Page 1 of 1

[SOLVED] Bitmap to ImageTexture conversion through python?

Posted: Thu Jun 01, 2023 12:12 pm
by Hurricane046
Hello fellow Octane users!

What is a c4d python octane command to convert c4d native Bitmap into Octane ImageTexture? Or what way we can do instead creating Bitmap shader containing texture and injecting it into material, create ImageTexture node if material is OctaneMaterial and connect it into correct link inside Octane Node Editor?

C4D default python example that creates Bitmap link:

Code: Select all

# Create a new bitmap shader and set its filename to the texture path
                            shader = c4d.BaseList2D(c4d.Xbitmap)
                            shader[c4d.BITMAPSHADER_FILENAME] = texture_path
                            
                            # Insert the shader into the document
                            doc.InsertShader(shader)
                            
                            # Set the shader as the link for c4d.OCT_MATERIAL_DIFFUSE_LINK
                            mat[c4d.OCT_MATERIAL_DIFFUSE_LINK] = shader
                            
                            # Print the name of the selected texture
                            print(f"Selected diffuse texture: {file_name}")

Re: Bitmap to ImageTexture conversion through python?

Posted: Thu Jun 01, 2023 5:26 pm
by aoktar
There are not a simple command to convert one node to another one. Nodes are complicated with their data structures and has own parameters types. You can do it a python script by creating new node and transfer/convert the parameters and links. See example scripts under C4D section.

Re: Bitmap to ImageTexture conversion through python?

Posted: Fri Jun 02, 2023 9:08 am
by Hurricane046
Thanks for quick response. It worked! We skip the bitmap node and go straight for the imagetexture one!

Code: Select all

 for file_name in os.listdir(folder_path):
                    for texture_type in texture_types:
                        if texture_type in file_name.lower():
                            texture_path = os.path.join(folder_path, file_name)
                            print(f"Found {texture_types[texture_type][1]} texture: {texture_path}")

                            # Create a new Octane Image Texture and set its filename to the texture path
                            shader = c4d.BaseShader(ID_OCTANE_IMAGE_TEXTURE)
                            shader[c4d.IMAGETEXTURE_FILE] = texture_path

                            # Insert the shader into the document
                            doc.InsertShader(shader)

                            # Set the shader as the link for c4d.OCT_MATERIAL_DIFFUSE_LINK
                            mat[texture_types[texture_type][0]] = shader

                            # Print the name of the selected texture
                            print(f"Selected {texture_types[texture_type][1]} texture: {file_name}")

                            break

Re: [SOLVED] Bitmap to ImageTexture conversion through python?

Posted: Fri Jun 02, 2023 11:27 am
by aoktar
You'll need to insert the created ImageTextures to materials. They have to be owned by the material