Tue, Nov 19, 9:37 AM CST

Renderosity Forums / Poser Python Scripting



Welcome to the Poser Python Scripting Forum

Forum Moderators: Staff

Poser Python Scripting F.A.Q (Last Updated: 2024 Sep 18 2:50 am)

We now have a ProPack Section in the Poser FreeStuff.
Check out the new Poser Python Wish List thread. If you have an idea for a script, jot it down and maybe someone can write it. If you're looking to write a script, check out this thread for useful suggestions.

Also, check out the official Python site for interpreters, sample code, applications, cool links and debuggers. This is THE central site for Python.

You can now attach text files to your posts to pass around scripts. Just attach the script as a txt file like you would a jpg or gif. Since the forum will use a random name for the file in the link, you should give instructions on what the file name should be and where to install it. Its a good idea to usually put that info right in the script file as well.

Checkout the Renderosity MarketPlace - Your source for digital art content!



Subject: Connecting the output of an existing node


EnglishBob ( ) posted Thu, 13 October 2011 at 5:17 PM · edited Tue, 19 November 2024 at 9:17 AM

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. 


nruddock ( ) posted Thu, 13 October 2011 at 6:31 PM

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


EnglishBob ( ) posted Fri, 14 October 2011 at 3:29 AM

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


markschum ( ) posted Sat, 15 October 2011 at 12:35 AM

you want InNode() for that , using the input for diffuse color you get the node thats plugged into it.  That node may not be an image map node though.

 


EnglishBob ( ) posted Sat, 15 October 2011 at 2:32 PM

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. 


nruddock ( ) posted Sat, 15 October 2011 at 4:51 PM

Don't bother making changes with the old P4 compatible material settings methods.

You'll need to find the appropriate node and input in the shader tree to change.


markschum ( ) posted Mon, 17 October 2011 at 1:03 PM

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

   


EnglishBob ( ) posted Mon, 17 October 2011 at 5:01 PM

Thanks guys. As usual I have too many things on the go at once, and I'll be unable to do much while I'm away for a few days. I'll get back to this shortly. Might even release something. :D


RobynsVeil ( ) posted Sat, 03 December 2011 at 2:19 AM

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] 

Metaphor of Chooks


Privacy Notice

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.