Scripting#
Warning
The Maya Legacy Connector is no longer supported. All users should move to Maya Native.
USD Python Binding#
USD Python Bindings are available with the installation of the Maya Omniverse Connector.
Note
Known Limitation - Other USD plugins must be uninstalled for this to work.
Maya Plugin Script APIs#
Loading the Plugin#
Besides loading the Maya Omniverse plugin via the Plugin manager dialog, users can also load the plugin via this script.
loadPlugin "OmniverseMayaLoader.mll"
Connect to an Omniverse Server#
Check Connection Status#
int $nvConnect = `optionVar -q omniverse_connection_state`;
The omniverse_connection_state is a Maya option variable. You can remove it with the following command.
optionVar -remove omniverse_connection_state;
And you can modify it with this command
optionVar -iv omniverse_connection_state 1;
Note
Generally speaking, Users should use string or integer types for option variables as Maya does not use boolean variables.
OmniExtraCmd - clientLogLevel 0;
0 - Debug
1 - Verbose
2 - Inform
3 - Warning
4 - Error
Set User Name and Log in#
To make sure that you log in to right server you can call the following script command step by step.
Set up user name:
optionVar -sv "omniverse_user_name_var" dduka;
Set up available servers#
Creates a list of servers to connect to.
optionVar -sv omniverse_server_urls "localhost:3009;my-server:1234;my-other-server:4321"
Set Up Current Server#
Set’s up the server you wish to log-in to.
optionVar -sw omniverse_server_url "my-server:1234";
Inform C++ Plugin#
Script command to make the C++ plugin get the above information.
OmniConfigCmd;
Connect to Server#
Makes the connection to an Omniverse Nucleus Server.
OmniConnectionCmd true;
Update Status#
Make the relative UI showing correct status after log-in.
nvOmniUpdateConnectionMenu();
nvOmniUpdateConnectionUI();
Export USD#
Export a USD to Omniverse
OmniExportCmd -file "/Example/Users/aatest/tt.usd";
Note
there is a prefix “/Omniverse” with the URL.
Setting up Export Mode types#
Optional variables control how you export a scene. As an export can take form in various ways, you need turn on/off some variables before calling the export command.
Prop#
optionVar -iv omniverse_export_objecttype 1;
Skeletal Mesh#
optionVar -iv omniverse_export_objecttype 2;
optionVar -iv omniverse_export_skip_skelanimation 1
This option allows you to choose if 1 frame of animation is set to USD Skel on export. It is off by default.
Point Cache#
optionVar -iv omniverse_export_objecttype 3;
Set Export Collection Types
Export/Live-Sync All#
optionVar -iv omniverse_export_collectiontype 1;
Export/Live-Sync Selected#
optionVar -iv omniverse_export_collectiontype 2;
Export/Live-Sync Visible#
optionVar -iv omniverse_export_collectiontype 3;
Always Export GeomSubsets#
optionVar -iv omni_always_export_geosubset 0;
optionVar -iv omni_always_export_geosubset 1;
Other exporting options:#
Turn on “Use Animation”#
optionVar -iv omniverse_export_useanimation 1;
Set Animation Start-Frame#
optionVar -iv omniverse_export_ani_start 1;
Set Animation End-Frame#
optionVar -iv omniverse_export_ani_end 200;
Set Animation step#
optionVar -iv omniverse_export_ani_stride 1;
Normalize Animation range#
This option renumbers the exported frame range starting from a given base number. It will also adjust the timecode of the usd file to reflect the range.
NormalizeFrameRangeOnExport -onflag true -basenumber 0;
Normalize Skin Weights#
optionVar -iv omniverse_export_normalizeskinweights 1;
Bake Skin Bind position#
optionVar -iv omniverse_skin_use_finalmesh 0;
Include MDL#
optionVar -iv omniverse_export_includemdl 1;
Embedded MDL option#
optionVar -iv omniverse_embed_materials 1;
Include Cameras#
optionVar -iv omniverse_export_includecamera 1;
Include Lights#
optionVar -iv omniverse_export_includelight 1;
Live Sync Commands#
For Live Sync, it cannot work with USD Animation on. So, you need run two script commands to turn it on.
optionVar -iv omniverse_export_useanimation 0; // turn off Use Animation
optionVar -iv omniverse_export_livesync 1; // turn on Live Sync
nvOmniUpdateConnectionUI(); // this is optional. But if you want to see right Live Sync checkbox status, you need call it.
Import USD#
Imports a USD file on Omniverse
OmniImportCmd -file "/Omniverse/Users/aatest/tt.usd";
Note
there is a prefix “/Omniverse” to the URL.
List Command#
List Command can be used to list the files and sub-folders in an Omniverse folder. The return value of this command is a string array which has data grouped by 3.
string $ffs[] = `OmniListCmd -la "/Omniverse/Users/aatest/"`;
Note
the string should end with ‘/’ as well as starts with the prefix ‘/Omniverse
Show File/Folder Name#
Shows each folder/file full name
int $m = 0; for($m = 0; $m < 3; $m++) { int $idx = $m * 3; print ($ffs[$idx] + "\n");}
Show Folder/File Modify Date#
int $m = 0; for($m = 0; $m < 3; $m++) { int $idx = $m * 3 + 1; print ($ffs[$idx] + "\n");}
Cache#
Check Cache Status#
maya.cmds.optionVar(q='OmniAuth_enableCaching')
Enable Caching#
maya.mel.eval('OmniEnableCachingCmd -enable 1')
Plug-in Load Time#
maya.mel.eval('OmniExtaCmd -tl')
t = maya.cmds.OmniExtaCmd(tl=True)
print t
MDL Materials#
Python Scripts relating to MDLs
List MDL Materials#
Python Script to show all of MDL materials
import maya.cmds as cmds
mdls = cmds.mdlShaderCmd(q=True,listHyperShadeItems=True)
for module in mdls:
print module
Result
[u'adobe::annotations',
u'adobe::convert',
u'adobe::mtl',
......
u'Users::kkantiev::Hardskin_Test::t1OmniPbrTest',
u'Users::lileo::Maya::initialShadingGroup_lambert',
u'Users::lileo::Maya::lambert1']
Alternative List MDL#
mdls = cmds.mdlShaderCmd(q=True,listHyperShadeItems=True)
Result .. code-block:: python
[u’L/Library/MDL/Base/OmniGlass/OmniGlass’, u’L/Library/MDL/Base/OmniPBR/OmniPBR’, u’L/Library/MDL/Base/OmniPBR_Opacity/OmniPBR_Opacity’]
Upgrade MDL Materials#
Note
This feature will be deprecated in upcoming releases as it is not needed any longer. This tool specifically addresses a material change that was done from 2019.2 to 2019.3. The menu entry has been removed, however is still available as a MEL script command if needed.
nvOmniMenuUpgradeMaterials_command().
Record Time#
Record Time of Server Connect and Load#
maya.cmds.timer(s=True);
maya.mel.eval('optionVar -sv "omniverse_user_name_var" "my-user-name"')
maya.mel.eval('optionVar -sv "omniverse_server_url" "my-server:1234"')
maya.mel.eval('nvOmniMainConnectivity')
t = maya.cmds.timer(e=True);
print t
Record time to load templates#
maya.cmds.timer(s=True);
maya.mel.eval('optionVar -sv "Omniverse_Library_Materials_Templates_SearchPaths" "/Omniverse/Library/Materials/Templates;"')
maya.mel.eval('syncMDLSearchPath')
t = maya.cmds.timer(e=True);
print t
Record time to load Collection#
Collection Path is supported the same way as template path in plugin. So, there is should be no difference. But adding more path should cost more time.
maya.cmds.timer(s=True);
maya.mel.eval('optionVar -sv "Omniverse_Library_Materials_Collections_SearchPaths" "/Omniverse/Users/aatest/ani;"')
maya.mel.eval('syncMDLSearchPath')
t = maya.cmds.timer(e=True);
print t
Pick one file name#
User may want to pick and get a file name without exporting or importing a USD. Here the things to do. You need define a mel function nvOmniPickCallback in which you define what you do with the file name. Now you can call mel function nvOmniPickAFile() to start the file pick dialog. Once you pick a file and close the dialog, nvOmniPickCallback is called.
global proc nvOmniPickCallback(string $filename)
{
print("nvOmniPickCallback " + $filename + "\n");
}
nvOmniPickCallback is read only. You may want to export a new USD. Then you can call nvOmniAddAFile(). And you also need define a call back function, nvOmniAddAFileCallback, to handle the file name.
global proc nvOmniAddAFileCallback(string $filename)
{
print("nvOmniAddAFileCallback " + $filename + "\n");
OmniExportCmd -file $filename;
}
Loading the Plug-In#
Once the Maya Omniverse Plug-In is installed, navigate to the Plug-in Manager.
(Windows > Settings/Preferences > Plug-in Manager)
Look for OmniverseMayaLoader.mll and load/verify the plug-in is loaded/working. Select auto load if Maya should load this plug-in automatically.