==== Octane useful scripts ====

Sub forum for help and tutorials.

Moderators: aoktar, ChrisHekman

ShivaMist
Licensed Customer
Posts: 80
Joined: Thu Oct 11, 2018 5:07 pm
Location: Paris

SSmolak wrote:Is there way to change compression only for textures that have "diffuse" in their name for example ? Unfortunately change compression globally for selected textures in Octane Texture Manager is not possible for many of them selected - it ask for every texture.

Code: Select all

import c4d
ID_OCTANE_IMAGE_TEXTURE = 1029508

def collect(shdList, n):
    if n is None:
        return
    if n.GetType() == ID_OCTANE_IMAGE_TEXTURE:
        ix =- 1
        try:
            ix = shdList.index(n)
        except:
            ix = -1

        if ix == -1:
            shdList.append(n)

    if n.GetDown():
        collect(shdList, n.GetDown())
    if n.GetNext():
        collect(shdList, n.GetNext())


def main():
    doc = c4d.documents.GetActiveDocument()
    matList = doc.GetMaterials()
    for mat in matList:
        shaders = []
        collect(shaders, mat.GetFirstShader())
        for shader in shaders:
            if 'diffuse' in shader[c4d.IMAGETEXTURE_FILE].lower():
                shader[c4d.IMAGETEX_COMPR_FORMAT] = 0

if __name__ == '__main__':
    main()
Here you go!

This line is where you choose the parameter, you can use trial and error :)

Code: Select all

shader[c4d.IMAGETEX_COMPR_FORMAT] = 0
User avatar
SSmolak
Licensed Customer
Posts: 1157
Joined: Sat Feb 07, 2015 5:41 pm
Location: Poland
Contact:

ShivaMist wrote:
Here you go!
Thank you very much. That's fantasitc !
Architectural Visualizations http://www.archviz-4d.studio
User avatar
Hurricane046
Licensed Customer
Posts: 98
Joined: Wed Jul 25, 2018 6:57 am

EDIT: Nevermind, solved!

Code: Select all

# -------------------------------------------------------------
# SET SPECULAR VALUES

def main():
    materials = doc.GetMaterials()
    for material in materials:
        red = 0.0
        green = 0.0
        blue = 0.0
        material[c4d.OCT_MATERIAL_DIFFUSE_FLOAT]=1
        material[c4d.OCT_MATERIAL_SPECULAR_FLOAT]=0.3
        material[c4d.OCT_MATERIAL_SPECULAR_COLOR]=c4d.Vector(red, green, blue)
    c4d.EventAdd()

main()
Is there a Python way to:

• set the HSV values to 0,0,0
• set the Float value to 0.5

We've already written extensive script which handles a lot of Octane related stuff for us but accessing these properties is proving to be troublesome. Thank you!

Image

It doesn't turn orange so I assume there is more tricky way of accessing this property. The OCT_MATERIAL_DIFFUSE_FLOAT works.

Image
User avatar
Hurricane046
Licensed Customer
Posts: 98
Joined: Wed Jul 25, 2018 6:57 am

I'm looking for script which will force reload of ALL Octane Material thumbnails in the current project.

I'm using Aoktar's script for reloading individually selecteded material thumbnail but I'm having trouble to automate this process for all materials since the script needs to take around 1 second break between each material so the preview is able to properly render. As far as I know this isn't possible without asyncio?

This is what I'm using now:

Code: Select all

import c4d
from c4d import gui

ID_OCTANE_IMAGE_TEXTURE = 1029508

def collect(shdList, n):
    if n.GetType()==ID_OCTANE_IMAGE_TEXTURE: 
        ix=-1
        try:
            ix = shdList.index(n)
        except:
            ix=-1

        if ix==-1:  shdList.append(n)

    if n.GetDown(): collect(shdList, n.GetDown())
    if n.GetNext(): collect(shdList, n.GetNext())
       
def main():
    mat = doc.GetActiveMaterial()
    shaders=[]

    collect(shaders, mat.GetFirstShader())
   
    for n in shaders:
        n[c4d.IMAGETEXTURE_FORCE_RELOAD]=1
        n.SetDirty(c4d.DIRTYFLAGS_ALL)
   
    c4d.EventAdd()   

if __name__=='__main__':
    main()
User avatar
Hurricane046
Licensed Customer
Posts: 98
Joined: Wed Jul 25, 2018 6:57 am

Hello, I can't intercept CallCommand for "Remove duplicate material". It intercepts the one for "Convert Materials" but not for the removal.

Any chance anyone here knows what the ID on this CallCommand is? Thank you!

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

[quote="Hurricane046"]Hello, I can't intercept CallCommand for "Remove duplicate material". It intercepts the one for "Convert Materials" but not for the removal.

Any chance anyone here knows what the ID on this CallCommand is? Thank you!

You can look for commands in Commander(shift+C)
ID_REMOVE_UNUSED_MATERIALS=1035351
ID_REMOVE_DUPLICATED_MATERIALS=1036468
Attachments
a1.jpg
a1.jpg (20.6 KiB) Viewed 26779 times
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

Thanks for the answer! Unfortunately it seems that Remove duplicate material isn't your average Python c4d.CallCommand().

Remove Unused Materials
c4d.CallCommand(1035351) does work.

Remove duplicate material
c4d.CallCommand(1036468) doesn't work.

I cannot even find the "Remove duplicate material" Octane function in the shift+C list. It only shows these two where one is the Remove Unused Materials function and the other is my Python script.

Image

Is there any way this function can be called via Python script? Out of 30 various functions we've already implemented, this one is throwing a wrench in the whole thing. :?
User avatar
SSmolak
Licensed Customer
Posts: 1157
Joined: Sat Feb 07, 2015 5:41 pm
Location: Poland
Contact:

Hurricane046 wrote:
I cannot even find the "Remove duplicate material"
Shift+F12 type "unused" "duplicated" and you will have all commands listed here
Architectural Visualizations http://www.archviz-4d.studio
User avatar
Hurricane046
Licensed Customer
Posts: 98
Joined: Wed Jul 25, 2018 6:57 am

I did that but this window also doesn't show the Octane function "Remove duplicate material". It shows the native C4D one "Delete Duplicate Materials" but I need the Octane one. To be completely frank the C4D one never worked for me in 15 years of using C4D.

Image

This is the one I need triggered via Python.

Image
User avatar
SSmolak
Licensed Customer
Posts: 1157
Joined: Sat Feb 07, 2015 5:41 pm
Location: Poland
Contact:

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 :)
Architectural Visualizations http://www.archviz-4d.studio
Post Reply

Return to “Help / Tutorials”