WENIE RAHARDJA
Effects + CGI
  • work
  • Reel

Alembic Cache Script Via Python

8/22/2016

 
Recently I found that there is no equivalent python command for alembic export import. I can't find the documentation on it either.
To read on the documentation, you have to call it in script editor using AbcExport -h and it only comes in mel.

So after further research, I found a way to do it the python way. Basically, you have to wrap the mel version in a string and use it on the jobArg (j) flag. 

For the alembic export

import maya.cmds as cmd

start = 0
end = 120
root = "-root pSphere1 -root pCube1"
save_name = "c:\documents\maya\project\default\cache\alembicTest.abc"

command = "-frameRange " + start + " " + end +" -uvWrite -worldSpace " + root + " -file " + save_name
cmd.AbcExport ( j = command )


 If you do print command you'll get the following result

-frameRange 0 120 -uvWrite -worldSpace -root pSphere1 -root pCube1 -file c:\documents\maya\project\default\cache\alembicTest.abc



The alembic import command doesn't have the jobArg flag so I figured that I can import maya.mel to my python script and use the eval command.

import maya.cmds as cmd
import maya.mel as mel
 command = "AbcImport -mode import -fitTimeRange -connect " + '"' + root + '"' + " " + '"' + save_name + '"' 

 mel.eval(command)

Notice that you need to include the double quote encasing the root and save_name  in the string. ' " '
 If you do print command you'll get the following result

AbcImport -mode import -fitTimeRange -connect "pSphere1 -root pCube1"  "c:\documents\maya\project\default\cache\alembicTest.abc"

Reference:
About alembic export, click  here

About wrapping melscript inside python, click here

Comments are closed.

    Categories

    All
    Hair / Fur
    Scripting