Forum Moderators: Staff
Poser Python Scripting F.A.Q (Last Updated: 2025 Feb 05 6:41 am)
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
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]
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]
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.
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]
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]
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]
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]
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]
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]
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]
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.
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/
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]
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]
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]
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]
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]
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
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 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