---
title: "Maya Python API 2.0 - MGlobal"
author: "schi"
date: "2012-08-31T18:07:16Z"
tags: ["Maya Python API 2.0", "Python", "maya"]
categories: ["编程语言"]
slug: "maya-python-api-2-0-mglobal"
draft: false
lastmod: "2012-08-31T18:07:16Z"
id: 1669101
url: "https://schi.iteye.com/blog/1669101"
---

MGlobal是一个静态类,提供通用的API涵数.
包括获取maya的版本,API版本,执行mel,python命令等等.
但2.0的MGlobal只实现了很少的涵数.

getActiveSelectionList获取当前的的选取列表,返回MSelectionList

```python

import maya.OpenMaya as om  # API 1.0  
import maya.api.OpenMaya as newom  # API 2.0  

# API 1.0  
selList = om.MSelectionList()  
om.MGlobal.getActiveSelectionList(selList)  
  
# API 2.0  
mySel = newom.MGlobal.getActiveSelectionList() 

```


displayError显示错误信息

```python

# API 1.0  
om.MGlobal.displayError("error message")  
  
# API 2.0  
newom.MGlobal.displayError("error message") 

```


displayInfo是显示信息,用法跟displayError一样,类似print
displayWarning是显示警告信息,以前有些版本里的cmds模块并没有cmds.warning(),可以使用这个涵数来代替.

getSelectionListByName是通过给予的物体名字来返回一个MSelectionList

```python

# API 1.0  
selList = om.MSelectionList()  
om.MGlobal.getSelectionListByName("pCube1", selList)  
  
# API 2.0  
mySel = newom.MGlobal.getSelectionListByName("pCube1") 

```