Forum Moderators: Staff
Poser Python Scripting F.A.Q (Last Updated: 2024 Sep 18 2:50 am)
So you want a different image map for the diffuse and change specular color to a new RGB value ?
Thats not too difficult. I should have one somewhere in my zips .
Here is one offhand that you can copy and paste to set specular color
import poser
scn = poser.Scene()
fig = scn.CurrentFigure()
mats = fig.Materials()
if mats:
print fig.Name()
for mat in mats:
tree=mat.ShaderTree()
n = tree.NodeByInternalName("PoserSurface")
if n:
i = n.InputByInternalName("Specular_Value")
if i:
i.SetColor(0.5,0.5,0.5) # replace with rgb values
tree.UpdatePreview()
scn.DrawAll()
It's easy for the specular color.
Concerning the textures, it depends what you want to do exactly. If it's changing on texture filename to another, then it's easy.
To detect any texture connected to, say, the Diffuse Color channel and change them to another one is a little bit more complicated, but not too much :)
This code will change the specular color from all materials from the selected figure to the value r=128, g=245, b = 135
import poser
r = 128
g = 245
b = 135
f = poser.Scene().CurrentFigure()
for m in f.Materials():
______m.ShaderTree().Node(0).InputByInternalName('Highlight_Color').SetColor(float(r)/255.0, float(g)/255.0, float(b)/255.0)
______m.ShaderTree().UpdatePreview() ------------------------------------------
I'm missing something... can't add space at the beginning !?!?!?!
And I see there is already an answer... too slow. Notice the the internal value from the specular color is not specular color, but Highlight_Color
Quote - import poser
r = 128
g = 245
b = 135
f = poser.Scene().CurrentFigure()
for m in f.Materials():
______m.ShaderTree().Node(0).InputByInternalName('Highlight_Color').SetColor(float(r)/255.0, float(g)/255.0, float(b)/255.0)
got an error
File "C:Program FilesSmith MicroPoser ProRuntimePythonposerScriptsWacrosUserDefinedSpecularColor.py", line 8
______m.ShaderTree().Node(0).InputByInternalName('Highlight_Color').SetColor(float(r)/255.0, float(g)/255.0, float(b)/255.0)
^
IndentationError: expected an indented block
This by markschum worked, but had to change Specular_Value to Highlight_Color
Now, the problem, I may be changing the spec color for 40+ intances, so,
any way to make the color picker pop up to choose the color?
I have a mat that I apply to the preview that has the colors I need and I choose from there
Quote - So you want a different image map for the diffuse and change specular color to a new RGB value ?
Thats not too difficult. I should have one somewhere in my zips .
Here is one offhand that you can copy and paste to set specular color
import poser
scn = poser.Scene()
fig = scn.CurrentFigure()
mats = fig.Materials()
if mats:
print fig.Name()
for mat in mats:
tree=mat.ShaderTree()
n = tree.NodeByInternalName("PoserSurface")
if n:
i = n.InputByInternalName("Specular_Value")
if i:
i.SetColor(0.5,0.5,0.5) # replace with rgb values
tree.UpdatePreview()
scn.DrawAll()
here is one that looks for an image map name and replaces it , might not be quite what you want.
sorry for the name error , O am not at my poser machine so I am working from memory.
import poser
myimgname = "c:/program files/e frontier/poser7/runtime/textures/oldimgname.jpg"
newimgname = "c:/program files/e frontier/poser7/runtime/textures/newimgname.jpg"
scn = poser.Scene()
fig = scn.CurrentFigure()
mats = fig.Materials()
for mat in mats:
print mat.Name()
tree = mat.ShaderTree()
nods = tree.Nodes()
for nod in nods:
if nod.Type() == poser.kNodeTypeCodeIMAGEMAP:
img = nod.Input(0).Value()
print img
if img == myimgnam:
nod.input(0).SetString(newimgname)
tree.UpdatePreview
scn.DrawAll()
solved the error changed
if img == myimgnam:
to
if img == myimgname:
but it pretty much just listed the texture file locations
Quote - here is one that looks for an image map name and replaces it , might not be quite what you want.
sorry for the name error , O am not at my poser machine so I am working from memory.
searches tree for all materials in figure and replaces named file with new file name
save as material collection to save running script again
import poser
file name used
myimgname = "c:/program files/e frontier/poser7/runtime/textures/oldimgname.jpg"
new file name to be used
newimgname = "c:/program files/e frontier/poser7/runtime/textures/newimgname.jpg"
scn = poser.Scene()
fig = scn.CurrentFigure()
mats = fig.Materials()
for mat in mats:
print mat.Name()
tree = mat.ShaderTree()
nods = tree.Nodes()
for nod in nods:
if nod.Type() == poser.kNodeTypeCodeIMAGEMAP:
img = nod.Input(0).Value()
print img
if img == myimgnam:
nod.input(0).SetString(newimgname)
tree.UpdatePreview
scn.DrawAll()
the image name listed is for debugging. when I used this script the file name retrieved was a fully ualified name. You might get a different result.
you need to change the lines myimgname = and newimgname = to the actual file names you want to change. If the oldfilenames are different in each material then it needs a different approach.
To change the color (using a color picker), it's a little bit more complicated... You're working in PoserPro 7 (NOT PoserPro 2010) - right ?
The problem you had (with my little code) is that you must replace the '_____' by spaces (or a tabulation). I'll make a little later today a color picker, if it's still needed.
Quote - To change the color (using a color picker), it's a little bit more complicated... You're working in PoserPro 7 (NOT PoserPro 2010) - right ?
Correct, PoserPro7
Quote - The problem you had (with my little code) is that you must replace the '_____' by spaces (or a tabulation). I'll make a little later today a color picker, if it's still needed.
Wonderful, that would help me so much! Thank you!
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.
To change the texture only on current/selected figure on all the materials without messing up the current shader.
and
To change the specular color only on current/selected figure on all the materials without messing up the current shader.
Seperate would be ok, together would be even better, would drastically improve my workflow.
How hard would this be to write? I have no clue how to start writing a script, have edited them a little but that's about it.
Oh, I'm working in P7Pro