Python API for Universal Material 'Metallic'

Forums: Python API for Universal Material 'Metallic'
Maxon Cinema 4D (Export script developed by abstrax, Integrated Plugin developed by aoktar)

Moderator: aoktar

Python API for Universal Material 'Metallic'

Postby blastframe » Sun Sep 15, 2019 10:23 pm

blastframe Sun Sep 15, 2019 10:23 pm
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
blastframe
Licensed Customer
Licensed Customer
 
Posts: 178
Joined: Wed May 21, 2014 6:01 am
Location: Los Angeles, CA USA

Re: Python API for Universal Material 'Metallic'

Postby aoktar » Mon Sep 16, 2019 3:26 pm

aoktar Mon Sep 16, 2019 3:26 pm
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
aoktar
Octane Plugin Developer
Octane Plugin Developer
 
Posts: 15940
Joined: Tue Mar 23, 2010 8:28 pm
Location: Türkiye

Re: Python API for Universal Material 'Metallic'

Postby blastframe » Mon Sep 16, 2019 3:37 pm

blastframe Mon Sep 16, 2019 3:37 pm
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
blastframe
Licensed Customer
Licensed Customer
 
Posts: 178
Joined: Wed May 21, 2014 6:01 am
Location: Los Angeles, CA USA

Re: Python API for Universal Material 'Metallic'

Postby aoktar » Mon Sep 16, 2019 8:07 pm

aoktar Mon Sep 16, 2019 8:07 pm
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
aoktar
Octane Plugin Developer
Octane Plugin Developer
 
Posts: 15940
Joined: Tue Mar 23, 2010 8:28 pm
Location: Türkiye

Re: Python API for Universal Material 'Metallic'

Postby blastframe » Mon Sep 16, 2019 8:29 pm

blastframe Mon Sep 16, 2019 8:29 pm
aoktar wrote:Here's working code


Thank you very much, Ahmed!!!
User avatar
blastframe
Licensed Customer
Licensed Customer
 
Posts: 178
Joined: Wed May 21, 2014 6:01 am
Location: Los Angeles, CA USA

Return to Maxon Cinema 4D


Who is online

Users browsing this forum: No registered users and 6 guests

Fri Mar 29, 2024 1:53 am [ UTC ]