Poser Python and Material Nodes
Quick question: Is there a way to distinguish selected nodes in Python? If not, it's not the end of the world, but it would be really convenient if I could identify which nodes were selected and just work with those.
anomalaus last edited by
@kobaltkween it doesn't appear so. The material method "Selected()" relates to which selections of materials the User has made in a SaveSelectedMaterials dialog, and not on which material is currently visible in the Material Room, let alone which node is currently selected.
The only other relevant method relates to which output of a multi-output node is selected to determine which preview should be displayed in Compound Nodes and any other node type (usually Cycles) which has multiple outputs.
anomalaus last edited by
@kobaltkween on second thought, if you were prepared to move your selected nodes into a compound node and then extract them later, they would become nodes within the ShaderTree of the compound node itself, and thus immediately distinguishable from those nodes not previously selected.
There doesn't seem to be a Python method to collapse selected nodes from within a script, but if you had the script record the positions of all the nodes in all the materials of the current actor, you could subsequently restore them if the collapse and expand manual processes had not done so. All very kludgey, as are so many things related to Poser's Python API. [Still thankful for what we already have, though]
How do you access the shader tree of a compound node, anyway? How do you handle them in general? I notice that the documentation says that CompoundData() returns an object that gives you access to specific methods, but then doesn't seem to list those methods anywhere.
eclark1849 last edited by
@kobaltkween Chapter 16 of the reference manual . Page 465. Expanding compound nodes.
@eclark1849 Sorry, I wasn't clear. I know how to do it in the interface. I specifically meant through the Python API. You see, there's no ShaderTree() method for nodes. So my guess would be that you do it through one of the methods described in the explanation of the CompoundData() node method (Page 181 of the Poser Python Manual):
"Get a data object providing access to compound-node-specific methods. If this is not a compound node, the return value will be None."
The problem is that I can find absolutely no record of those "compound-node-specific methods." I can get the object, but without knowing how to access it's methods, I'd have to write some sort of script to just get the object to explain/describe its interface to me. Which is a PITA I'd like to avoid if I can.
Just in case someone else searches for this, these are the methods I'm finding so far:
I'm still not sure how one would use these methods to duplicate a compound node, but it seems I'm going to have to work on it.
Some more undocumented methods, for the NodeOutput object
@kobaltkween I know this is resurrection, but did you ever tie all this down so you could create a compound node from code?
bantha last edited by
I have created compound nodes with a script, it is possible. I don't have the script here right now, but I will search for it and post it here in a couple of days.
@bantha Did you manage to find anything?
I have not only created compound nodes before, but also dynamically created all the internal nodes by type, and then dynamically created all the connections between them, so I know it can be done. Each node has an ID that identifies them by type. The manual has a list of all the IDs.
I also remember the manual being really vague and useless about this, so I had to ask around for the details. Nobody new about this specifically, so I went trial and error until it worked. This was a year ago, so I don't remember the details, but I do remember nodes are identified by IDs, and we loop across all nodes until we find the ID. We can also assign names for the nodes, which help identifying them across others of the same type. This is the name that shows on the title bar of each node. With a combination of ID + name, we can uniquely locate and identify a specific node in that jungle.
However, if you want to locate a specific node created in other people's shaders, with random node names, that can be difficult.
@ken1171 Hi, yes I know it can be done, and I have also done this with materials that don't have compound nodes, both on my own and using EZSkin3, it is the total lack of documentation around compound nodes that stopped me. Yes I'm sure I can figure it out I was just wondering if anyone had a snippet that showed the basics it would be easier :)
bantha last edited by
It works like this:
scn = poser.Scene()
mat = scn.CurrentMaterial()
tree = mat.ShaderTree()
nodelist = tree.Nodes()
t1 = tree.Node(0)
#Now create a sample node inside "root":.
n = self.createNode(root,'image_map','Image_Map_9',655,282)
# Next node
#Connect multiple nodes like this:
#Create inputs like this:
Is this example enough?
Hi @bantha yep that gives me what I need, thank you