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 contextlibfrom maya import cmds
@contextlib.contextmanagerdef 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 contextlibfrom maya import cmds
@contextlib.contextmanagerdef 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 parenthoodif 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)

​

On 19 October 2015 at 11:13, Macbeth R. <[email protected]> wrote:

> Is there a way to export selected nodes only without a top parent group
> above them??
>
> For example if I have one top group/transform named ALL, then inside some
> other groups/transforms named FW and BG, and I only want to export BG and
> FG with all their children without getting the top group ALL in the
> resulting scene.
>
> Greetings.
>
> --
> 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 [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/python_inside_maya/48a6f735-81a8-4b99-8eae-0c0d3ba5ba54%40googlegroups.com
> <https://groups.google.com/d/msgid/python_inside_maya/48a6f735-81a8-4b99-8eae-0c0d3ba5ba54%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
*Marcus Ottosson*
[email protected]

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOA1w0nicQdwJE4Ku4jneq70vYsaACnh%3D4cKrkn0UFCeOA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to