Hi I am currently learning python scripting in maya. I am looking for a way to store models in code so I can access my unique models with the code. (I understand how to write a python amino acid sequence, just not how to store maya objects and access them with python in maya)
I have learned how to access the script editor and how to add specific shapes such as polySphere() and others. What I want to do is make a specific model, and then select the model and get the code for recreating all the selected items, which I can then run in a script to recreate that shape in another scene.
For example: I am currently making some amino acids, while it isn’t hard to model an amino acid, when I want to make a chain of them it would be very helpful to write a script that recreates those specific amino acid (3d models) in a sequence.
Thanks for your help!
This is a problem that many beginner to intermediate Maya users have. It stems form the fact that they don’t really grasp how Maya actually works. The trick here is that your actually looking it in the wrong way around. Before we go deeper into the answer its best if I define scripting so you dont get confused down the line. Scripting in Maya is the maya.cmds module, that is the scripting layer of Maya. Python also exposes Mayas programming layer in the maya.OpenMaya, more on that later.
Now Mayas scripting interface is somewhat weird at first, because its not the tool that does the job. The real programming environment of Maya are the nodes, the scripting interface just exposes a programmatic way for you to layout the nodes. So in way Mayas scripting interface is a metaprogramming interface of kinds. You wont figure this out by looking at the scripting reference tough, but rather the hypergraph or the Node Reference. This means its a bit unintuitive to do what you want at a first glance.
So your question mutates at this point(assuming you want to script as I defined above, and Maya manual defines it). What kinds of nodes can I use to build this amino acid chain?
Well basically your left with two options, using particles and particle instancing or using a snapshot node (snapshot node is the only factory node that can do replication and change the shape of the dg, during run time). Particle instancing works its super fast and intuitive once you get a hang of it, and it can almost certainly do hundreds of thousands of molecules this way. Using the snapshot node is a bit complex, and you cant really easily animate it. The node you use to bind all this is into something useful is a expression node, which is Mayas custom data handler (and no expressions are not MEL).
Now if you really want to do code, which I advice against, then you need to make a node using Mayas API, in combination to a script. Scripts build nodes remember so that building connections and user interface is a script and the API builds just the node internals. This is more straightforward coding, tough inefficient use of your time.
It is also possible to use events and rebuild the damn thing on demand. Problem with this is that you’ll have maya puking all over you and fighting you all the way making your life miserable.