Sun, Dec 29, 12:10 PM 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 Dec 02 3:16 pm)

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: How to change texture of a node from Shader tree?


maur_2005 ( ) posted Thu, 09 January 2020 at 10:31 AM · edited Sat, 28 December 2024 at 8:21 PM

Hi folks,I'm trying to change the texture of a node in the Shader Tree but I'm having trouble, maybe someone can help me This is my code:

NewPathString = ""
NewTextureString = ""

scene = Poser.Scene()
actor = poser.Scene().CurrentActor()

for mat in actor.Materials():
     Tree = mat.ShaderTree()
    
    for node in tree.Nodes:
          if targetNodeName = node.Name()
               node.Material(mat.Name()).SetTextureMapFileName(NewTextureString)


adp001 ( ) posted Thu, 09 January 2020 at 11:11 AM · edited Thu, 09 January 2020 at 11:17 AM

You can set a Texturemap with SetTextureMapFileName to a material as base-texture. But not to a Node.

All Nodes follow the same rules. They have Inputs and Outputs where something can connect to (even values or textures). Inputs and outputs are arranged as lists. See "PoserPython Methods Manual" in your Poser directory.

Normally you have to search or determine the index of an input/output. But fortunately "Image_Source" is the first entry in the node "Image_Map".

< Node >.Inputs()[0].InNode().SetString(< Path >)

Manual says to "SetString": ** SetString** Explanation Set the string value. In this version of Poser, this is the path of a texture or movie file. Arguments Enter the path name for the desired texture or movie file.




maur_2005 ( ) posted Thu, 09 January 2020 at 12:48 PM

Thanks adp001, I will try to do that...

The problem is that I don't know exactly which node the texture is in, sometimes that node is called "Image_Map_1" other times "Image_Map_2" or something like that

shaderTree.jpg


adp001 ( ) posted Thu, 09 January 2020 at 3:16 PM · edited Thu, 09 January 2020 at 3:20 PM

Sure, you need to know something about the image you want to change. A path or filename will do if it is unique.

Here is a sample-search:

try:
    # I need to do this to make my editor happy
    import poser
except ImportError:
    poser = None

import re

def find_image(node, name="Image_Source", value="myImage.*"):
    if node is None:
        return None

    if node.Type() == poser.kNodeTypeCodeIMAGEMAP:
        test = re.compile(value)

        for inp in node.Inputs():
            v = inp.Value()
            if isinstance(v, basestring) and test.search(v):
                return node
            result = find_image(inp.InNode())
            if result is not None:
                return result
    return None


sc = poser.Scene()
        
for mat in sc.CurrentFigure().Materials():
    for shadernode in mat.ShaderTree().Nodes():
        # change value to what should be part of the 
        # path you search for
        node = find_image(shadernode, value="Mask")
        if node is not None:
            print node.Name()
            print node.InputByInternalName("Image_Source").Value()


This should give you an idea how to solve your problem.




maur_2005 ( ) posted Wed, 05 February 2020 at 8:15 AM

Thank you adp001, that was very useful


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.