==== Octane useful scripts ====

Sub forum for help and tutorials.

Moderators: aoktar, ChrisHekman

User avatar
aoktar
Octane Plugin Developer
Posts: 16063
Joined: Tue Mar 23, 2010 8:28 pm
Location: Türkiye
Contact:

Looks like "Remove duplicate material" command is internal, I will make it accesible
Octane For Cinema 4D developer / 3d generalist

3930k / 16gb / 780ti + 1070/1080 / psu 1600w / numerous hw
User avatar
aoktar
Octane Plugin Developer
Posts: 16063
Joined: Tue Mar 23, 2010 8:28 pm
Location: Türkiye
Contact:

Here is a new script, which does the work. It's a start point to make selections for Octane plugin materials

Code: Select all

import c4d
from c4d import gui

# Unique id numbers for each of the GUI elements
GROUP_OPTIONS = 20000
BTN_OK = 20001
BTN_CANCEL = 20002
COMBO1 = 1010
COMBO2 = 1011
COMBO3 = 1012

ID_OCTANE_DIFFUSE_MATERIAL = 1029501
ID_OCTANE_STANDARD_SURFACE = 1058763
ID_OCTANE_MIX_MATERIAL = 1029622
ID_OCTANE_PORTAL_MATERIAL = 1029623
ID_OCTANE_NULL_MATERIAL = 1061767
ID_OCTANE_CLIPPING_MATERIAL = 1056989
ID_OCTANE_SHADOWCATCHER_MAT = 1057003
ID_OCTANE_HAIR_MATERIAL = 1054119
ID_OCTANE_COMPOSITE_MATERIAL = 1040075
ID_OCTANE_LAYERED_MATERIAL = 1052933

OCT_MAT_TYPE_DIFFUSE = 2510
OCT_MAT_TYPE_GLOSSY = 2511
OCT_MAT_TYPE_SPECULAR = 2513
OCT_MAT_TYPE_METAL = 2514
OCT_MAT_TYPE_TOON = 2515
OCT_MAT_TYPE_UNIVERSAL = 2516

OCT_MAT_BRDF_OCTANE = 0
OCT_MAT_BRDF_BECKMANN = 1
OCT_MAT_BRDF_GGX = 2
OCT_MAT_BRDF_GGX_ENPRES = 6
OCT_MAT_BRDF_WARD = 3
OCT_MAT_BRDF_STD = 7


# Dialog for renaming objects
class OptionsDialog(gui.GeDialog):
  def CreateLayout(self):
    self.selMatType = ID_OCTANE_DIFFUSE_MATERIAL
    self.selSubMatType = OCT_MAT_TYPE_DIFFUSE

    self.SetTitle('Octane material selector')

    self.AddStaticText(0, c4d.BFH_LEFT, name='Material type:')
    self.AddComboBox(COMBO1, c4d.BFH_SCALEFIT, 80, 0, False)
    self.AddChild(COMBO1, ID_OCTANE_DIFFUSE_MATERIAL, 'Octane material')
    self.AddChild(COMBO1, ID_OCTANE_STANDARD_SURFACE, 'Standard surface')
    self.AddChild(COMBO1, ID_OCTANE_MIX_MATERIAL, 'Mix material')
    self.AddChild(COMBO1, ID_OCTANE_COMPOSITE_MATERIAL, 'Composite material')
    self.AddChild(COMBO1, ID_OCTANE_LAYERED_MATERIAL, 'Layered material')
    self.AddChild(COMBO1, ID_OCTANE_HAIR_MATERIAL, 'Hair material')
    self.SetInt32(COMBO1, self.selMatType)

    self.AddStaticText(0, c4d.BFH_LEFT, name='Sub material type:')
    self.AddComboBox(COMBO2, c4d.BFH_SCALEFIT, 80, 0, False)
    self.AddChild(COMBO2, 0, 'All types')
    self.AddChild(COMBO2, OCT_MAT_TYPE_DIFFUSE, 'Diffuse')
    self.AddChild(COMBO2, OCT_MAT_TYPE_GLOSSY, 'Glossy')
    self.AddChild(COMBO2, OCT_MAT_TYPE_SPECULAR, 'Specular')
    self.AddChild(COMBO2, OCT_MAT_TYPE_METAL, 'Metal')
    self.AddChild(COMBO2, OCT_MAT_TYPE_UNIVERSAL, 'Universal')
    self.AddChild(COMBO2, OCT_MAT_TYPE_TOON, 'Toon')
    self.SetInt32(COMBO2, self.selSubMatType)

    # Buttons - an Ok and Cancel button:
    self.GroupBegin(GROUP_OPTIONS, c4d.BFH_CENTER, 2, 1)
    self.AddButton(BTN_OK, c4d.BFH_SCALE, name='Select')
    self.AddButton(BTN_CANCEL, c4d.BFH_SCALE, name='Cancel')
    self.GroupEnd()
    self.ok = False

    return True

  # React to user's input:
  def Command(self, id, msg):
    if id==COMBO1:
        self.selMatType = self.GetInt32(COMBO1)
        print(self.selMatType)

    if id==COMBO2:
        self.selSubMatType = self.GetInt32(COMBO2)
        print(self.selSubMatType)


    if id==BTN_CANCEL:
      self.Close()
    elif id==BTN_OK:
      self.ok = True
      self.option_find_string = self.GetString(TXT_FIND)
      self.option_replace_string = self.GetString(TXT_REPLACE)
      self.Close()
    return True


def main():
    doc = c4d.documents.GetActiveDocument()
    mat = doc.GetActiveMaterial()
    matList = doc.GetMaterials()


# Open the options dialogue to let users choose their options.
    dlg = OptionsDialog()
    dlg.Open(c4d.DLG_TYPE_MODAL, defaultw=300, defaulth=50)
    if not dlg.ok:
        return

    selMatType = dlg.selMatType
    selSubMatType = dlg.selSubMatType

    mt = 0
    cnt=0

    for mat in matList:
        t = mat.GetType()
        sel=False

        if t==selMatType:

            mt = mat[c4d.OCT_MATERIAL_TYPE]
            if t==ID_OCTANE_DIFFUSE_MATERIAL:
                if mt==selSubMatType: sel=True
                if selSubMatType==0: sel=True
            else: sel=True

            if sel==True:
                print(mat.GetName(), mt)
                if cnt==0:
                    doc.SetActiveMaterial(mat)
                    doc.SetSelection(mat,mode=c4d.SELECTION_NEW)
                else:
                    doc.SetSelection(mat,mode=c4d.SELECTION_ADD)
                cnt=cnt+1


    c4d.EventAdd()

if __name__ == '__main__':
    main()
Octane For Cinema 4D developer / 3d generalist

3930k / 16gb / 780ti + 1070/1080 / psu 1600w / numerous hw
User avatar
Hurricane046
Licensed Customer
Posts: 98
Joined: Wed Jul 25, 2018 6:57 am

SSmolak wrote:
Hurricane046 wrote:To be completely frank the C4D one never worked for me in 15 years of using C4D.
hmm yes it doesn't work. I never used it. Why you didn't reported this before to Maxon :)
I've been using the Octane feature for this. It works really great. This whole problem stems only from me trying to access this feature via Python. The feature itself is great and completely negates the need for the native C4D one.
aoktar wrote:Looks like "Remove duplicate material" command is internal, I will make it accesible
Thanks, you're awesome!
User avatar
eyeonestudio
Licensed Customer
Posts: 328
Joined: Fri Oct 18, 2013 5:49 pm
Location: Seoul, South Korea
Contact:

Can I set Live Viewer's Render Region and Film Region using Python? (Button and Region)
You can use Picture Viewer by modifying the render settings.
However, there is no way the live viewer.
RR.png
CINEMA 4D R2025
Win11 / AMD 7995WX, 3995WX, 3990X, Intel 10980XE / 256Gb RAM / RTX4090, RTX3090 / 100GbE, 40GbE, 10GbE
User avatar
aoktar
Octane Plugin Developer
Posts: 16063
Joined: Tue Mar 23, 2010 8:28 pm
Location: Türkiye
Contact:

eyeonestudio wrote:Can I set Live Viewer's Render Region and Film Region using Python? (Button and Region)
You can use Picture Viewer by modifying the render settings.
However, there is no way the live viewer.
RR.png
There are not any way to change this via script. They are internal and temporal parameters, we don't have no any storage to reveal it. Sorry!
Octane For Cinema 4D developer / 3d generalist

3930k / 16gb / 780ti + 1070/1080 / psu 1600w / numerous hw
User avatar
eyeonestudio
Licensed Customer
Posts: 328
Joined: Fri Oct 18, 2013 5:49 pm
Location: Seoul, South Korea
Contact:

aoktar wrote:
eyeonestudio wrote:Can I set Live Viewer's Render Region and Film Region using Python? (Button and Region)
You can use Picture Viewer by modifying the render settings.
However, there is no way the live viewer.
RR.png
There are not any way to change this via script. They are internal and temporal parameters, we don't have no any storage to reveal it. Sorry!
Oh, I see. Thank you for answer
CINEMA 4D R2025
Win11 / AMD 7995WX, 3995WX, 3990X, Intel 10980XE / 256Gb RAM / RTX4090, RTX3090 / 100GbE, 40GbE, 10GbE
HSchoenberger
Licensed Customer
Posts: 6
Joined: Tue Jan 23, 2024 10:16 am

Hi

I have a scripting question for C4D.
I have seen your script to get the Ocane version from the C4D document.

Code: Select all

doc = c4d.documents.GetActiveDocument()
bc = doc[ID_OCTANE_LIVEPLUGIN] 
print ("Octane version=",bc[c4d.SET_OCTANE_VERSION])
But the issue is that the document might not show the current version used, it might be a version that was used for the scene before.
Example:
End Customer has C4D 2023+Octane 12 and C4D 2024+Octane 13 installed.
They work with 2023 for their current project.
An artist accidentally opened the scene in Cinema 2024 and saved it.
But then he continues with 2023.

If I request the information from the C4D document in 2023, then it states Octane 13.
Which is wrong.

Is there any way to get an information from the loaded plugin itself?
User avatar
aoktar
Octane Plugin Developer
Posts: 16063
Joined: Tue Mar 23, 2010 8:28 pm
Location: Türkiye
Contact:

HSchoenberger wrote:Hi

I have a scripting question for C4D.
I have seen your script to get the Ocane version from the C4D document.

Code: Select all

doc = c4d.documents.GetActiveDocument()
bc = doc[ID_OCTANE_LIVEPLUGIN] 
print ("Octane version=",bc[c4d.SET_OCTANE_VERSION])
But the issue is that the document might not show the current version used, it might be a version that was used for the scene before.
Example:
End Customer has C4D 2023+Octane 12 and C4D 2024+Octane 13 installed.
They work with 2023 for their current project.
An artist accidentally opened the scene in Cinema 2024 and saved it.
But then he continues with 2023.

If I request the information from the C4D document in 2023, then it states Octane 13.
Which is wrong.

Is there any way to get an information from the loaded plugin itself?
It's already posted information this forum, see
viewtopic.php?f=87&t=56039&start=30#p422511
Octane For Cinema 4D developer / 3d generalist

3930k / 16gb / 780ti + 1070/1080 / psu 1600w / numerous hw
HSchoenberger
Licensed Customer
Posts: 6
Joined: Tue Jan 23, 2024 10:16 am

aoktar wrote: It's already posted information this forum, see
viewtopic.php?f=87&t=56039&start=30#p422511
I stated that I have already tried that script
and it does not work.

Please read my message.
Thanks.
User avatar
aoktar
Octane Plugin Developer
Posts: 16063
Joined: Tue Mar 23, 2010 8:28 pm
Location: Türkiye
Contact:

HSchoenberger wrote:
aoktar wrote: It's already posted information this forum, see
viewtopic.php?f=87&t=56039&start=30#p422511
I stated that I have already tried that script
and it does not work.

Please read my message.
Thanks.
I don't understand your request. You have two different point to read numbers, current plugin version or saved version number in to scene. What do you want to get exactly if scene version number overwritten?
Octane For Cinema 4D developer / 3d generalist

3930k / 16gb / 780ti + 1070/1080 / psu 1600w / numerous hw
Post Reply

Return to “Help / Tutorials”