Wed, Sep 18, 1:26 PM CDT

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: Need help, can this be done?


MaskimXul ( ) posted Sat, 26 February 2011 at 3:44 PM · edited Thu, 12 September 2024 at 11:27 PM

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


markschum ( ) posted Sat, 26 February 2011 at 4:12 PM

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()

 


semidieu ( ) posted Sat, 26 February 2011 at 4:16 PM · edited Sat, 26 February 2011 at 4:23 PM

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


MaskimXul ( ) posted Sat, 26 February 2011 at 4:28 PM

 

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


MaskimXul ( ) posted Sat, 26 February 2011 at 4:30 PM

Quote - Concerning the textures, it depends what you want to do exactly. If it's changing on texture filename to another, then it's easy.

Yes, exactly- to change the texture filename to another (for all the materials)

Thanks!


MaskimXul ( ) posted Sat, 26 February 2011 at 4:48 PM · edited Sat, 26 February 2011 at 4:49 PM

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

spec colors

 

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()

 


markschum ( ) posted Sat, 26 February 2011 at 4:54 PM

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()


MaskimXul ( ) posted Sat, 26 February 2011 at 5:11 PM

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()


markschum ( ) posted Sat, 26 February 2011 at 6:09 PM

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.

 


semidieu ( ) posted Sun, 27 February 2011 at 6:05 AM

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.


MaskimXul ( ) posted Sun, 27 February 2011 at 6:12 AM

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!


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.