Maya export selection issues

I’m having an issue scripting out exporting selected objects from Maya.

The first problem is, that it won’t export selected objects until I manually export selected first before running the script (If I don’t run this manually first it will export out the whole scene not just the selected).

Second issue is if I export out a lot of objects from one scene, I run into the memory issue that Maya is so well known for and it ends up crashing.

Do you know of any exporting selection thru the API? I’ve tried MEL, Python and Pymel but they all cause the same issues (because they are all wrappers around the MEL function).

#Here is some sample code I have if it helps
import pymel as pm

def exportTARGShapes(path, blendNode=“blendShape1”):
if not path:
path = pm.fileDialog(m=0, dm="*.ma")

if path:
    numTargets=len(pm.getAttr(blendNode+".w"))

    for iterator in range(numTargets):
        originalName=pm.aliasAttr("%s.w[%i]"%(blendNode,iterator), q=True)

        try:
            pm.setAttr(blendNode+"."+originalName, 1)
            dup = pm.duplicate("geoToExportGroup")
            dup = pm.rename(dup, originalName)
            pm.parent(dup, w=True)
            pm.select(dup)
            pm.exportSelected("C:/Documents and Settings/user/Desktop/exportFolder/%s.ma"%originalName,
                            constructionHistory=False,
                            constraints=False,
                            expressions=False,
                            shader=False)
            pm.delete(dup)
            pm.refresh()
            pm.setAttr(blendNode+"."+originalName, 0)
        except:
            pass

Thanks for any help.

[QUOTE=Floid Parkins;10511]
The first problem is, that it won’t export selected objects until I manually export selected first before running the script[/QUOTE]

You’re not actually selecting anything in the script, which is probably what’s going on there. Before you run this:


dup = pm.duplicate("geoToExportGroup")
dup = pm.rename(dup, originalName)

You need to grab a selection somewhere.

I am doing a selection a couple of lines down from what you posted.

dup = pm.duplicate(“geoToExportGroup”)
dup = pm.rename(dup, originalName)
pm.parent(dup, w=True)
pm.select(dup)

This script does work as intended but only after I export selected manually first.

Ok, so your script assumes the presence of a group called “geoToExportGroup”, didn’t catch that. That being the case, what does your scene look like? It’s kinda tricky to debug a script that’s so name/scene dependent without actually knowing what’s going on in the scene. Also, try except:pass isn’t doing you any favors. While you’re debugging, get rid of it or write a real exception handler.

Sorry for the long delay on responding. I was on paternity leave for the last 2 weeks.

So I found the fix to problem #1. The reason I couldn’t export out until I had done a manual export is because I wasn’t setting the type to “mayaAscii” :no:. The second problem with running out of memory when exporting out 60-100 files from a scene I still can’t figure out, but am chalking that up to a Maya bug.

#original code
pm.exportSelected("%s\%s.ma"%(path, originalName),
constructionHistory=False,
constraints=False,
expressions=False,
shader=False,
force=True)

#fixed code
pm.exportSelected("%s\%s.ma"%(path, originalName),
constructionHistory=False,
constraints=False,
expressions=False,
shader=False,
type=“mayaAscii”,
force=True)