Forum: Poser Python Scripting


Subject: Changing Alternate_Diffuse value

papillon68 opened this issue on Nov 19, 2010 · 24 posts


papillon68 posted Fri, 19 November 2010 at 12:16 PM

I have the following code (taken and adapted from PhilC's Python for Poser book), that work fine when I try to change the Diffuse Color of a Material:

 

    actor = (scene.Actor("hutRoofLP_19"))       
    mat = actor.Materials()[0]
    # find the material's shader tree and its root
    tree = mat.ShaderTree()
    root = tree.Node(0)
    # find the Diffuse_Color node.
    diffCol = root.InputByInternalName("Diffuse_Color") # <<< OK
    diffCol = root.InputByInternalName("Alternate_Diffuse") # <<< ERROR
    diffCol.SetColor(1,0,0)

However, I need to change the Alternate_Diffuse value, and that gives the following error:

AttributeError: 'NoneType' object has no attribute 'SetColor'

Anybody knows how to correctly address the Alternate Diffuse ? Thanks

 

visit my blog:  www.alessandromastronardi.com

My Rendo Store


papillon68 posted Fri, 19 November 2010 at 12:19 PM

Well, I managed to solve it like this:

    actor = (scene.Actor("hutRoofLP_19"))       
    mat = actor.Materials()[0]
    # find the material's shader tree and its root
    tree = mat.ShaderTree()
    root = tree.Node(0)
    diffCol = root.Input(18) # <<< this is the Alternate_Diffuse
    diffCol.SetColor(1,0,0)

visit my blog:  www.alessandromastronardi.com

My Rendo Store


PhilC posted Fri, 19 November 2010 at 12:25 PM

You need to use the node's internal name, "AlternateDiffuse" rather than the external (visible) name of "Alternate_Diffuse".

 


papillon68 posted Fri, 19 November 2010 at 3:07 PM

Thaks for the clarification Phil !

visit my blog:  www.alessandromastronardi.com

My Rendo Store


RobynsVeil posted Fri, 13 January 2012 at 9:39 PM

I'm looking at a script by a very clever person for setting Diffuse_Value on all nodes to .8.

When I try to run this script:

import poser
scn = poser.Scene()
figs = scn.Figures()
acts = scn.Actors()
for fig in figs:
  print fig.Name()    
  mats = fig.Materials()
  if mats:
    for mat in mats:
      tree = mat.ShaderTree()
      n = tree.NodeByInternalName("PoserSurface")
      i = n.InputByInternalName("Diffuse_Value")
      i.SetFloat(0.8)
      tree.UpdatePreview()

in a scene with multiple "characters" (figures) - i.e., a church and a V4 figure - in PP2012 from the Scripts -> Utility menu I get the following error:

Traceback (most recent call last):
  File "C:Program FilesSmith MicroPoser Pro 2012RuntimePythonposerScriptsScriptsMenuUtilitySetDiffuseValueZeroPointEight.py", line 15, in
    i = n.InputByInternalName("Diffuse_Value")
AttributeError: 'NoneType' object has no attribute 'InputByInternalName'

...which looks similar to the error already mentioned. I made certain that "PoserSurface" is indeed the internal name for... um... PoserSurface and that the input name (internal) is indeed "Diffuse_Value".

Any ideas why this happens?

ETA: I've only included code from the script to a bit past the "offending" line...

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


RobynsVeil posted Fri, 13 January 2012 at 10:00 PM

Quote - I'm looking at a script by a very clever person for setting Diffuse_Value on all nodes to .8.

BTW, meant to say: on all PoserSurface nodes... clearly... :glare:

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


markschum posted Fri, 13 January 2012 at 10:23 PM

its saying there was no PoserSurface node found in that material.

The script is going to try looking at all materials in all figures in that scene. Before the tracebacks you should get printed to the screen the figure name its currently examining.

Check that figure manually to make sure it actually has materials.

 

n = tree.NodeByInternalName("PoserSurface")

if n:
      i = n.InputByInternalName("Diffuse_Value")
      i.SetFloat(0.8)
      tree.UpdatePreview()

 

 

make this change should get you past the problem as a quick fix.


RobynsVeil posted Fri, 13 January 2012 at 10:42 PM

I so wish I had your mind, Mark! Thank YOU!!

if n:

sort-of means: if n is not null or empty or false, right?

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


RobynsVeil posted Fri, 13 January 2012 at 10:52 PM

Yay! getting somewhere. I did this:

import poser
scn = poser.Scene()
figs = scn.Figures()
acts = scn.Actors()
for fig in figs:
  print fig.Name()    
  mats = fig.Materials()
  if mats:
    for mat in mats:
      tree = mat.ShaderTree()
      node = tree.NodeByInternalName("PoserSurface")
      if node:
        print node
        i = node.InputByInternalName("Diffuse_Value")
        i.SetFloat(0.8)
      tree.UpdatePreview()

With apologies to the originator of this fine script, I've changed a variable name and put in a print statement, which was quite revelatory:

Charlotte
<ShaderNode object at 0x00000000384D06A8>
<ShaderNode object at 0x00000000384D0690>
<ShaderNode object at 0x00000000384D06D8>
CitySwan_Hair_V4
<ShaderNode object at 0x00000000384D06C0>
<ShaderNode object at 0x00000000384D0678>
<ShaderNode object at 0x00000000384D0690>
<ShaderNode object at 0x00000000384D06D8>
ChurchNull
<ShaderNode object at 0x00000000384D06C0>
GROUND
Traceback (most recent call last):
  File "C:Program FilesSmith MicroPoser Pro 2012RuntimePythonposerScriptsScriptsMenuUtilitySetDiffuseValueZeroPointEight.py", line 28, in
    i = n.InputByInternalName("Diffuse_Value")
AttributeError: 'NoneType' object has no attribute 'InputByInternalName'

Now I know on which object/figure/whatever things appear to be hiccuping on: the GROUND prop. I think. Or was it ChurchNull? I'm guessing ChurchNull is a sort-of null object that acts as a "figure container" for the rest of the church bits. Something to parent to. It only has a preview mat zone.

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


RobynsVeil posted Fri, 13 January 2012 at 10:53 PM

Top of MY wishlist for Poser: a Python IDE... even a skimpy one where you can set breaks and watchs... oh, and a pony. Gotta have the pony. :blink:

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


RobynsVeil posted Fri, 13 January 2012 at 10:54 PM

BTW, can't remember, there's no authorship statement in this script: it wouldn't happen to be yours, Mark? I just want to thank you for it if so! I'm learning so much from it!

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


RobynsVeil posted Fri, 13 January 2012 at 11:35 PM

Quote - Yay! getting somewhere. I did this:

import poser
scn = poser.Scene()
figs = scn.Figures()
acts = scn.Actors()
for fig in figs:
  print fig.Name()    
  mats = fig.Materials()
  if mats:
    for mat in mats:
      tree = mat.ShaderTree()
      node = tree.NodeByInternalName("PoserSurface")
      if node:
        print node
        i = node.InputByInternalName("Diffuse_Value")
        i.SetFloat(0.8)
      tree.UpdatePreview()

With apologies to the originator of this fine script, I've changed a variable name and put in a print statement, which was quite revelatory:

Charlotte
<ShaderNode object at 0x00000000384D06A8>
<ShaderNode object at 0x00000000384D0690>
<ShaderNode object at 0x00000000384D06D8>
CitySwan_Hair_V4
<ShaderNode object at 0x00000000384D06C0>
<ShaderNode object at 0x00000000384D0678>
<ShaderNode object at 0x00000000384D0690>
<ShaderNode object at 0x00000000384D06D8>
ChurchNull
<ShaderNode object at 0x00000000384D06C0>
GROUND
Traceback (most recent call last):
  File "C:Program FilesSmith MicroPoser Pro 2012RuntimePythonposerScriptsScriptsMenuUtilitySetDiffuseValueZeroPointEight.py", line 28, in
    i = n.InputByInternalName("Diffuse_Value")
AttributeError: 'NoneType' object has no attribute 'InputByInternalName'

Now I know on which object/figure/whatever things appear to be hiccuping on: the GROUND prop. I think. Or was it ChurchNull? I'm guessing ChurchNull is a sort-of null object that acts as a "figure container" for the rest of the church bits. Something to parent to. It only has a preview mat zone.

ETA: never mind: think I've sorted it... 😄

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


RobynsVeil posted Fri, 13 January 2012 at 11:37 PM

Oh, it WORKED!!!! WooHOOOOO!!!! :m_coolsmirk:

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


RobynsVeil posted Fri, 13 January 2012 at 11:44 PM

I can't publish this, can I? Don't even know whose code it is - but it sure would be cool to have in one's Script arsenal, I think.

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


markschum posted Sat, 14 January 2012 at 12:33 PM

It looks a lot like one of mine, strange abbreviations, lack of error trapping and all ;-)

You cant really copyright python because the code to do a specific task is going to look much the same no matter who writes it.  Thats why commercial products use a compiled script pyc.

I dont think any of the people who do freebie scripts would object to your using and modifying anything.  Certainly you can use anything of mine.

I normally put a comment line at the start when I remember. 

 

Its usually in the actors loop that my scripts come apart.  poser.Scene().Actors()  contains a lot of stuff that does not always have materials. I usually toss in code to filter lights, magnets and such out of the list.  

If you modify your print node to print mat.Name()  you will get the material name printed if there is a PoserSurface node. 


Snarlygribbly posted Sat, 14 January 2012 at 3:26 PM

node = tree.NodeByInternalName("PoserSurface")

It's better to use:

node = tree.Node(0)

The reason is because the internal name of the PoserSurface node isn't always 'PoserSurface'!

By way of example, check out BB's EnvDome - it uses the internal name 'Surface' instead, which wouldn't be picked up by your script.

Free stuff @ https://poser.cobrablade.net/


RobynsVeil posted Sun, 15 January 2012 at 1:11 AM

Good point, SG... is there some way of figuring out what a node number (like Node(0) for PoserSurface) is? Documentation is a bit sketchy...

 

So, for those who want it, here's how it looks so far:

#====================================================================
#      Set Diffuse_Value of PoserSurface to .8
#      Poser script by MarkSchum
#      sets diffuse_value in all materials for figures or props
#      to 0.8
#====================================================================

import poser
psrScene = poser.Scene()
figs = psrScene.Figures()
acts = psrScene.Actors()
for fig in figs:
  print fig.Name()    
  mats = fig.Materials()
  if mats:
    for mat in mats:
      tree = mat.ShaderTree()
      node = tree.Node(0)
      if node:
        print node
        i = node.InputByInternalName("Diffuse_Value")
        i.SetFloat(0.8)
      tree.UpdatePreview()
for act in acts:
  print act.Name()
  if act.IsProp() or act.IsHairProp():
    mats = act.Materials()
    if mats:
      for mat in mats:
        tree = mat.ShaderTree()
        node = tree.Node(0)
        if node:
          i = node.InputByInternalName("Diffuse_Value")
          i.SetFloat(0.8)
        tree.UpdatePreview()

psrScene.DrawAll()

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


markschum posted Sun, 15 January 2012 at 11:17 AM

if you add the line  print tree.Node(0).InternalName()  in place of the print node line you will be able to see what internal name is being used. 

 

Poser Python methods is your friend !   except where its wrong ;)

 


RobynsVeil posted Sun, 15 January 2012 at 4:42 PM

I am having a fair bit of fun with this, Mark - someday, I'll even learn to make some of my little thingies into GUIs... heheheh

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


RobynsVeil posted Sat, 28 January 2012 at 6:40 PM

Further to the above idea, would you have any objection if I took the core of this script and turned it into a wxPython-based GUI? I'm learning wx atm, and would like to make something useful, which your script so is!

Full credit to the original author would be given, of course!

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


markschum posted Sat, 28 January 2012 at 6:59 PM

go for it. I have Poser 7 so I dont have wxpython to play with ;)

dont worry about credits if you are doing Freestuff.


RobynsVeil posted Sat, 28 January 2012 at 7:07 PM

Quote - go for it. I have Poser 7 so I dont have wxpython to play with ;)

dont worry about credits if you are doing Freestuff.

Oh, it's an honour thing: the brilliant idea came from someone else: I'm just adding a pretty face.

Thank you, Mark! 😄

BTW, PP2010 is $65 at Purplus.net. Just sayin'... 😄

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


RobynsVeil posted Sat, 28 January 2012 at 11:05 PM

Oh and, this is definitely going to be FreeStuff. Not into selling. I'm into creating. Which is why HeRaZa and I aren't working together anymore. hated the vendor grind... bloody awful!

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


MistyLaraCarrara posted Thu, 23 February 2012 at 9:49 AM

Quote - > Quote - Yay! getting somewhere. I did this:

import poser
scn = poser.Scene()
figs = scn.Figures()
acts = scn.Actors()
for fig in figs:
  print fig.Name()    
  mats = fig.Materials()
  if mats:
    for mat in mats:
      tree = mat.ShaderTree()
      node = tree.NodeByInternalName("PoserSurface")
      if node:
        print node
        i = node.InputByInternalName("Diffuse_Value")
        i.SetFloat(0.8)
      tree.UpdatePreview()

With apologies to the originator of this fine script, I've changed a variable name and put in a print statement, which was quite revelatory:

Charlotte
<ShaderNode object at 0x00000000384D06A8>
<ShaderNode object at 0x00000000384D0690>
<ShaderNode object at 0x00000000384D06D8>
CitySwan_Hair_V4
<ShaderNode object at 0x00000000384D06C0>
<ShaderNode object at 0x00000000384D0678>
<ShaderNode object at 0x00000000384D0690>
<ShaderNode object at 0x00000000384D06D8>
ChurchNull
<ShaderNode object at 0x00000000384D06C0>
GROUND
Traceback (most recent call last):
  File "C:Program FilesSmith MicroPoser Pro 2012RuntimePythonposerScriptsScriptsMenuUtilitySetDiffuseValueZeroPointEight.py", line 28, in
    i = n.InputByInternalName("Diffuse_Value")
AttributeError: 'NoneType' object has no attribute 'InputByInternalName'

Now I know on which object/figure/whatever things appear to be hiccuping on: the GROUND prop. I think. Or was it ChurchNull? I'm guessing ChurchNull is a sort-of null object that acts as a "figure container" for the rest of the church bits. Something to parent to. It only has a preview mat zone.

ETA: never mind: think I've sorted it... 😄

 

revaltory python  😄



♥ My Gallery Albums    ♥   My YT   ♥   Party in the CarrarArtists Forum  ♪♪ 10 years of Carrara forum ♥ My FreeStuff