Forum Moderators: Staff
Poser Python Scripting F.A.Q (Last Updated: 2024 Sep 18 2:50 am)
What you see as the node title, isn't necessarily the InternalName.
The nodes generated by Poser often have the title (Name) altered to something more "friendly".
To be sure what internal name corresponds to a particular node, use a simple loop over the Nodes of a material to list the Names and InternalNames.
The node titled "Color_Texture" will almost certainly have the InternalName of "Image_Map".
Changing "Color_Texture" to "Image_Map" made it work for me, thanks. I realise that isn't the right way to do it, but it works for my use case which was all I was interested in at present. I have a prop with 275 materials and setting them up would be difficult without scripts.
In a more general case, I think I'm looking at it the wrong way. Instead of looking for a node with a particular name, I should be looking for one which has a particular connection (in this case it would be "the one that's plugged into Diffuse_Color").
Although I can get away with hacking together barely-working scripts for development purposes, it occurs to me that this prop (and another I have in mind) would benefit from being distributed with one or two scripts to help deal with all those materials. Expect more material room questions in the future. ;)
Thanks Mark.
Quote - That node may not be an image map node though.
That's fine - I'm just thinking ahead here. If the diffuse color input had something else plugged into it, a blender say, I imagine my first step would be to use the output of that for the bump too.
Talking of bumps, I couldn't get SetBumpStrength() to work. I added
mat.SetBumpStrength(0.2)
to the end of my script, but the bump strength remained at the default setting. I worked around that by using a macro in a text editor to change all the values, but it would be nice to know what went wrong. I'm usng Poser 7, if that makes a difference.
The other thing I did was write a colour randomising script which goes round all the materials and randomises their diffuse color values. That worked fine, but I could only ever see the difference by rendering. I had both
tree.UpdatePreview()
and
MyScene.DrawAll()
but the preview never seemed to get updated. The only way I could manage it through the user interface, even, was to select that material manually in the material room.
heres something like what you want
import poser
mats = poser.Scene().CurrentFigure().Materials()
for mat in mats:
tree = mat.ShaderTree().NodeByInternalName("PoserSurface")
nod = tree.NodeByInternalName("PoserSurface")
inp_Diffuse = nod.InputByInternalName("Diffuse_Color")
nod_diffuse = inp_Diffuse.InNode()
inp_bump = nod.InputByInternalName("Bump")
nod_Diffuse.ConnecttoInput(inp_bump)
tree.UpdatePreview()
poser.Scene().Drawall()
check my spelling and the actual bump input name
Quote - heres something like what you want
import poser
mats = poser.Scene().CurrentFigure().Materials()
for mat in mats:
tree = mat.ShaderTree().NodeByInternalName("PoserSurface")
nod = tree.NodeByInternalName("PoserSurface")
inp_Diffuse = nod.InputByInternalName("Diffuse_Color")
nod_diffuse = inp_Diffuse.InNode()
inp_bump = nod.InputByInternalName("Bump")
nod_Diffuse.ConnecttoInput(inp_bump)
tree.UpdatePreview()poser.Scene().Drawall()
Check my spelling and the actual bump input name.
Sorry to bump this up - it is indeed something that is going to help me a lot. Thanks heaps for that!! Writing a GUI and there's a lot to learn. be happy for examples for wxPython. This is gold, though!
Monterey/Mint21.x/Win10 - Blender3.x - PP11.3(cm) - Musescore3.6.2
Wir sind gewohnt, daß die Menschen verhöhnen was sie nicht verstehen
[it is clear that humans have contempt for that which they do not understand]
This site uses cookies to deliver the best experience. Our own cookies make user accounts and other features possible. Third-party cookies are used to display relevant ads and to analyze how Renderosity is used. By using our site, you acknowledge that you have read and understood our Terms of Service, including our Cookie Policy and our Privacy Policy.
I can find example code which connects a newly-created node to a given input, but I can't find how to connect an existing node to another input.
I want to go through all materials in a prop and connect the color texture image map, if there is one, to the bump input as well. Here's what I came up with (excuse the indenting, forum's fault):
import poser
MyScene = poser.Scene()
MyActor = MyScene.CurrentActor()
mats = MyActor.Materials()
for mat in mats:
tree = mat.ShaderTree()
surf = tree.NodeByInternalName("PoserSurface")
bump = surf.InputByInternalName("Bump")
ctex = tree.NodeByInternalName("Color_Texture") # this line is wrong...
if ctex:
ctex.ConnectToInput(bump)
MyScene.DrawAll()
As written, the script does nothing because "if ctex:" is never true.
If I comment out the if statement, then the ConnectToInput fails with the error
AttributeError: 'NoneType' object has no attribute 'ConnectToInput'
In other words, ctex has been created with no type. I'm not even sure what type it needs. I'd be grateful if someone could point me in the right direction.