You can if you’re exporting to Alembic, it’s got a flag specifying which part you’d like to be root, but likely not other formats.
You could also unparent things prior to export, maybe with a context manager like this one.
import contextlib
from maya import cmds
@contextlib.contextmanager
def unparent(root):
"""Temporarily unparent `root`"""
parent = cmds.listRelatives(root, parent=True)
if parent:
cmds.parent(root, world=True)
yield
cmds.parent(root, parent)
You could use it like this.
with unparent(cmds.ls(sl=True)[0]):
cmds.file("c:/my/path.ma", exportSelected=True, type="mayaAscii")
And make it a meal-deal like this.
import contextlib
from maya import cmds
@contextlib.contextmanager
def unparent(root):
"""Temporarily unparent `root`"""
parent = cmds.listRelatives(root, parent=True)
if parent:
cmds.parent(root, world=True)
yield
cmds.parent(root, parent)
# Retrieve an output path
filters = "Maya Files (*.ma *.mb);;Maya ASCII (*.ma);;Maya Binary (*.mb)"
path = cmds.fileDialog2(fileFilter=filters,
dialogStyle=2, # Use Maya-style file dialog
fileMode=0) # Any file, whether it exists or not
# Perform export, without parenthood
if not path:
cmds.warning("Cancelled")
else:
selection = cmds.ls(sl=True)[0]
file_type = {"ma": "mayaAscii", "mb": "mayaBinary"}[path[0].rsplit(".")[-1]]
with unparent(selection):
cmds.file(path[0], exportSelected=True, type=file_type)
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/48a6f735-81a8-4b99-8eae-0c0d3ba5ba54%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.