Python API for Universal Material 'Metallic'

Maxon Cinema 4D (Export script developed by abstrax, Integrated Plugin developed by aoktar)

Moderators: ChrisHekman, aoktar

Post Reply
User avatar
blastframe
Licensed Customer
Posts: 178
Joined: Wed May 21, 2014 6:01 am
Location: Los Angeles, CA USA

Hi Ahmed,
I'm having a little trouble scripting the creation of a Universal Material and was hoping you could help me.

In Diffuse, Specular, Normal, Roughness, etc. I'm able to insert a bitmap shader because there is a slot for Texture. In the case of Metallic (Specular Map), there is a float next to a button labeled 'Tex.' I can call the button click with:

Code: Select all

c4d.CallButton(mat(), c4d.OCT_MAT_ADD_SPECULAR_MAP_BTN)

However, that gives me a contextual menu with the options (Float, Image, Rgb, Gaussian Spectrum). It does not print to Cinema 4D's Script Log, so I don't know the slot's ID/parameters I'd need to insert an ImageTexture.

With this code I can add a bitmap shader for the Specular Map, but it doesn't have an ImageTexture to connect as you can see in the Node Editor image.

Code: Select all

import c4d

ID_OCTANE_BITMAP = 1029508
ID_OCTANE_SPECULAR_MAP = 1029508

def addMetallicTexture(id,mat):
    imageTexture = c4d.BaseShader(ID_OCTANE_BITMAP)
    imageTexture[c4d.IMAGETEXTURE_FILE] = "Clear_Plastic_Mat_metallic.png"
    mat[id] = imageTexture
    doc.AddUndo(c4d.UNDOTYPE_CHANGE, mat)
    mat.InsertShader(imageTexture)
    mat.Message(c4d.MSG_UPDATE)
    c4d.EventAdd()

def main():
    doc = c4d.documents.GetActiveDocument()
    doc.StartUndo()
    mat = doc.GetActiveMaterial()
    addMetallicTexture(ID_OCTANE_SPECULAR_MAP,mat)
    doc.EndUndo()

if __name__=='__main__':
    main()
Metallic.png
Could you tell me how I can insert an ImageTexture node into the Universal Material's Metallic/Specular Map slot please? Thank you!
User avatar
aoktar
Octane Plugin Developer
Posts: 16065
Joined: Tue Mar 23, 2010 8:28 pm
Location: Türkiye
Contact:

You can see every IDs by dropping to script manager. See picture
Attachments
a2.jpg
Octane For Cinema 4D developer / 3d generalist

3930k / 16gb / 780ti + 1070/1080 / psu 1600w / numerous hw
User avatar
blastframe
Licensed Customer
Posts: 178
Joined: Wed May 21, 2014 6:01 am
Location: Los Angeles, CA USA

aoktar wrote:You can see every IDs by dropping to script manager. See picture
Hi Ahmed, thank you for the reply. I do know about this and how to get the ID for the ImageTexture node.

I found what I needed in the code for the C++ file: res\description\OctaneMaterial.res:

Code: Select all

 
GROUP ID_MATERIAL_SPECULAR_MAP_GROUP
    {
        COLUMNS 1;
        GROUP ID_MATERIAL_SPECULAR_MAP_FLOAT_GROUP
        {
            COLUMNS 2;
            REAL OCT_MAT_SPECULAR_MAP_FLOAT { SCALE_H; MIN 0.0; STEP 0.01; MAX 1.0; MAXSLIDER 1.0;  CUSTOMGUI OCTNSLIDER;; }
            BUTTON OCT_MAT_ADD_SPECULAR_MAP_BTN   { ANIM OFF; }
        }
        SHADERLINK OCT_MAT_SPECULAR_MAP_LINK { OPEN; INPORT;}
    }
I didn't know the Shader Link was there as it isn't visible. I was able to get it working by using OCT_MAT_SPECULAR_MAP_LINK:

Code: Select all

mat[c4d.OCT_MAT_SPECULAR_MAP_LINK ] = imageTexture
mat.InsertShader(imageTexture)
Thank you.
User avatar
aoktar
Octane Plugin Developer
Posts: 16065
Joined: Tue Mar 23, 2010 8:28 pm
Location: Türkiye
Contact:

Here's working code

Code: Select all

import c4d
from c4d import gui
#Welcome to the world of Python

ID_OCTANE_DIFFUSE_MATERIAL = 1029501
ID_OCTANE_IMAGE_TEXTURE = 1029508

def main():
    doc = c4d.documents.GetActiveDocument()

    mat = doc.GetActiveMaterial()
    doc.StartUndo()
    doc.AddUndo(c4d.UNDOTYPE_CHANGE, mat)
    
    shd = c4d.BaseShader(ID_OCTANE_IMAGE_TEXTURE)

    mat.InsertShader(shd)
    mat[c4d.OCT_MAT_SPECULAR_MAP_LINK] = shd
    shd[c4d.IMAGETEXTURE_FILE] = "texture.jpg"
    shd[c4d.IMAGETEXTURE_MODE] = 0
    shd[c4d.IMAGETEXTURE_GAMMA] = 2.2
    shd[c4d.IMAGETEX_BORDER_MODE] = 0
    doc.InsertMaterial(mat)
        
    doc.EndUndo()
    c4d.EventAdd()
    
if __name__=='__main__':
    main()
Octane For Cinema 4D developer / 3d generalist

3930k / 16gb / 780ti + 1070/1080 / psu 1600w / numerous hw
User avatar
blastframe
Licensed Customer
Posts: 178
Joined: Wed May 21, 2014 6:01 am
Location: Los Angeles, CA USA

aoktar wrote:Here's working code
Thank you very much, Ahmed!!!
Post Reply

Return to “Maxon Cinema 4D”