Select object to import

102 views
Skip to first unread message

illunara

unread,
Apr 1, 2014, 10:21:17 PM4/1/14
to python_in...@googlegroups.com
Hi everybody
I wonder if we can select objects from maya scene to import, instead of import the whole scene?
Thanks

Justin Israel

unread,
Apr 2, 2014, 3:29:34 AM4/2/14
to python_in...@googlegroups.com
I think your only option is to import the scene file, move out the things you want to keep, and then delete the rest.


--
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/9605de3a-7730-4a68-9812-cfdc4e58be9c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Tuan Nguyen

unread,
Apr 2, 2014, 3:41:07 AM4/2/14
to python_in...@googlegroups.com
Hi Justin
The only thing i worry about, that is not only objects, but materials, shading, or many unnecessary things, will get imported along as well.
But we can select object to import from reference file, maybe i will give it a try, or maybe open that scene implicit and export what we need to another scene.

Ricardo Viana

unread,
Apr 2, 2014, 4:02:59 AM4/2/14
to python_in...@googlegroups.com
I would suggest open the scene ,select only the objects you want, and export selected as new scene. Same applies for materials.
--
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.

For more options, visit https://groups.google.com/d/optout.


--
Sent from Mobile

Tuan Nguyen

unread,
Apr 2, 2014, 4:15:14 AM4/2/14
to python_in...@googlegroups.com
Hi Ricardo
That's would be the best, however, too much files will get hard to maintain. Our artists said to keep it as simple as i can, so i decide not to export them all over the place :D



--
You received this message because you are subscribed to a topic in the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/python_inside_maya/99ENXsZJXEI/unsubscribe.
To unsubscribe from this group and all its topics, 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/CAK%2Bp0%3DYVLzTzrVL688o-9eOVmVSSKVCw-T5cvYhu-uS3x9xE0w%40mail.gmail.com.

Ricardo Viana

unread,
Apr 2, 2014, 4:36:44 AM4/2/14
to python_in...@googlegroups.com
In that case you can import as Justin mentioned, select all you dont want and delete it.
After that, run the file scene optimize that cleans up unnecessary nodes. Not sure if it cleans up everything.

For more options, visit https://groups.google.com/d/optout.


--
Sent from Mobile

Marcus Ottosson

unread,
Apr 2, 2014, 5:23:51 AM4/2/14
to python_in...@googlegroups.com
If you're looking for a programmable way of separating scenes, you can utilise the fact that Maya .ma files are plain-text.

# Step 1
You need some way of distinguishing between the nodes you want to separate from the rest. If what you're looking to extract is simply "all polygon meshes" or "all lights" then you can distinguish them via their node-type. 

## 1a
If your needs are more custom, then there are a few alternatives you can try. One might be to assign a common attribute per set of objects; for instance, all left arms of multiple characters get the attribute "leftArm". Then you can separate them by cmds.ls('*.leftArm'). 

## 1b
Another way to do it might be to collect all nodes in a objectSet, then you can reference them either via cmds.set() or traversing connections.

# Step 2
Locate the nodes you distinguished from above in your saved Ascii file and generate a new one with only those nodes, and their related attribute changes. You won't be able to use cmds.ls or cmds.set here, but if they can find it, so can you via some straightforward string-manipulation.

You'll keep the header of the original Maya file, with Maya version and such, and simply copy the lines only relevant to your criteria.



For more options, visit https://groups.google.com/d/optout.



--
Marcus Ottosson
konstr...@gmail.com

Tuan Nguyen

unread,
Apr 2, 2014, 6:30:33 AM4/2/14
to python_in...@googlegroups.com
Oh wow
Thank Marcus, you gave me some great ideas.Almost forgot about Ascii file  and i never used objectSet before, but i will give it a try too :D

Marcus Ottosson

unread,
Apr 2, 2014, 7:26:25 AM4/2/14
to python_in...@googlegroups.com
You're welcome. :) If you can, I'd love to see what you come up with.


On 2 April 2014 11:30, Tuan Nguyen <cb.il...@gmail.com> wrote:
Oh wow
Thank Marcus, you gave me some great ideas.Almost forgot about Ascii file  and i never used objectSet before, but i will give it a try too :D

--
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.

For more options, visit https://groups.google.com/d/optout.



--
Marcus Ottosson
konstr...@gmail.com

Fredrik Averpil

unread,
Apr 2, 2014, 10:12:55 AM4/2/14
to python_in...@googlegroups.com
Marcus,

Would it not be possible to write a method which parses through an .ma and collects all nodes and their attributes, perhaps in one or two dictionaries.

Then you would need a method to create a node from the dictionary and populate its attributes accordingly. When this is setup you could write a third method which would let you select which nodes to create from a list. 

I am not with a computer right now and I haven't checked on which form/syntax the .ma is written in. Any idea if this is covered in the docs or somewhere else?

-- to the OP:
If you know which parts you want imported on beforehand but need to automate this, you can run Maya in standalone mode and have it execute a script. This way Maya opens up in a prompt and can open the scene and then select and export the parts you are interested in into a scene which upon import will only import the stuff you wanted. 

Maya standalone is incredibly powerful when you need to automate stuff and without actually launching the regular GUI version of Maya. 

I've built a python app which analyses not the .ma but the scene "seen through" Maya this way.

Look up "Maya standalone" in the docs.  

// Fredrik

Marcus Ottosson

unread,
Apr 2, 2014, 10:19:36 AM4/2/14
to python_in...@googlegroups.com
It would indeed. :) Sounds like a healthy approach too. The syntax is plain MEL, no mystery involved.

Maya standalone is certainly another option, especially if your files are binary and you are stuck with it. You could potentially "select" in Maya standalone too and make your export from there.


--
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.

For more options, visit https://groups.google.com/d/optout.



--
Marcus Ottosson
konstr...@gmail.com

Tuan Nguyen

unread,
Apr 2, 2014, 11:15:50 AM4/2/14
to python_in...@googlegroups.com
To Fredrik
Yeah, i'm working on mayapy too, much easier, and safe than re-creating node. However, it tooks 2-3 seconds to load maya.standalone, and 1-2 more seconds to load a maya file, I will try to fix it.

Looking into Maya API too, but no luck.

Justin Israel

unread,
Apr 2, 2014, 2:39:04 PM4/2/14
to python_in...@googlegroups.com

+1 to Fredrik's suggestion of loading it in a headless Maya standalone to export what you want. That way your process doesn't have to rely on parsing the scene file format and making assumptions.

--
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.

Marcus Ottosson

unread,
Apr 2, 2014, 3:29:49 PM4/2/14
to python_in...@googlegroups.com
I think the question was about importing rather than exporting select items from a Maya scene, and I got the impression it was on the heavy side as well.

Modifying the Maya ascii files is indeed conventionally considered a black-magic approach, but they do follow a strict, easy to understand and consistent layout. I've had much luck modifying and generating it in the past, mainly for managing references, and would recommend getting your head around it.

For reference, the ascii format is laid out into four steps.

1. Header, with versioning and references
2. Creating nodes
3. Connecting nodes
4. Setting attributes

Any and all of these can be modified without heading into Maya. It's a convenience not many programs share, can only think of Nuke at the moment, and one that provides great power.



For more options, visit https://groups.google.com/d/optout.



--
Marcus Ottosson
konstr...@gmail.com

Justin Israel

unread,
Apr 2, 2014, 4:15:10 PM4/2/14
to python_in...@googlegroups.com
But the process limits you to dealing only with .ma files as opposed to being agnostic. And nuke doesn't have a binary project file format. They just have one .nk format. 

I didn't see where the other suggestions were focused on exporting. 


Marcus Ottosson

unread,
Apr 2, 2014, 4:44:28 PM4/2/14
to python_in...@googlegroups.com
But the process limits you to dealing only with .ma files as opposed to being agnostic.

This is true, it comes down to whether or not the limitation outweigh the benefit.

And nuke doesn't have a binary project file format. They just have one .nk format. 

Sorry, I should have been more clear. I meant that Nuke shared the convenience of Maya's .ma files in that they are also easily manipulated as strings of text.



For more options, visit https://groups.google.com/d/optout.



--
Marcus Ottosson
konstr...@gmail.com

Tuan Nguyen

unread,
Apr 3, 2014, 4:27:02 AM4/3/14
to python_in...@googlegroups.com
I have a few questions about mayapy
It took long times to import and run maya.standalone package, can i keep the mayapy running in background, and control it through python or mel? I only use it to run a batch of code, using cmd mayapy script.py


You received this message because you are subscribed to a topic in the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/python_inside_maya/99ENXsZJXEI/unsubscribe.
To unsubscribe from this group and all its topics, 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/CAFRtmOAPzvyRh1nO6hS-QqYOmLoDcXFAtMb43msLO08i-V1MRg%40mail.gmail.com.

Justin Israel

unread,
Apr 3, 2014, 4:49:43 AM4/3/14
to python_in...@googlegroups.com

Maya standalone does take a second to startup. But ya you could open a socket or use a commandPort to keep pushing the long running process.

Tuan Nguyen

unread,
Apr 3, 2014, 5:06:53 AM4/3/14
to python_in...@googlegroups.com
Can you go for more detail, or give me a sample please? I'm not good with network stuff :(


Reply all
Reply to author
Forward
0 new messages