Python API

 
 
 

Overview

XGen provides a Python API that gives access to internal XGen data from the Python shell. This can be used within or outside of Maya. The API is extended within Maya to allow for operations that apply within Maya (for example, accepting the “name” of a guide to get its patch), but that don’t apply elsewhere. All interaction with XGen should be done through this API, or the UI. Any access via MPxCommands or MEL functions that might exist within XGen are not guaranteed.

The methods are listed below in a pseudo syntax to indicate the return type and expected parameter types. Calling the methods is done as you would normally do in Python. You can pass the parameters in order, or use the names and reorder them as you please.

Importing API

The API is divided into two parts: Base and Maya. There is a separate UI component, but the API is essentially made up of the underlying C++ code, a Python layer that constitutes the Base API, and then another Python layer that brings in necessary Maya additions as well as extra API functions that constitutes the Maya API. It is important to bring in the correct API for the task, or you may obtain unexpected results. The best approach is to let XGen handle the decision for you:

import xgen as xg

This brings in the xgen module which detects Maya and optionally brings in the Maya layer of the API. If your script is going to run inside and outside of Maya and you are calling methods from the Maya only portion of the API, you should put those within a conditional block. A safe way to handle this is to use XGen's Maya detection:

import xgen.xgGlobal as xgg

if xgg.Maya
    # Do something maya specific like using XGen's Maya API

This brings in the XGen global module, which has the ability to detect Maya. Once that is in place, you can use its xgg.Maya variable to determine that you are in Maya and protect your Maya code within these conditionals.

Base API

The following methods are available whether you are inside or outside of Maya. They operate directly on the underlying XGen data. Many are also available through the libXgAPI.so library as a C++ API if you need an even faster link into XGen.

Creation and Deletion

Object Access

Attribute Access

FX Modules

Culling

Binding Info

File IO

Event Callbacks

Messages

General

Maya Extension API

All of the Base API methods are available through Maya, but the following methods extend the API further. These are not provided as part of the base API as they, in general, do not make sense in that context. For example, a method that accepts a “guide name” and returns a “patch name” in Maya doesn’t apply to standard XGen, as guides do not have names and patches are simply named after their geometry. That said, several of the Base API methods are overridden in Maya, and therefore you should always reference the API through the Maya API if you are in Maya so that the correct layer is referenced.

Maya MPx API

The following are MPxCommands that are part of the XGen API and only available through Maya.

Creative Commons License Except where otherwise noted, this work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License