Isotropix Forums

converts DisneyPrincipled to AStandardSurface and more

Clarisse Scripting related topics

converts DisneyPrincipled to AStandardSurface and more

Unread postby zheying » Sat Nov 06, 2021 2:49 am

Hi,
I'm trying to 'converts DisneyPrincipled to AStandardSurface' Upgrade code for Clarisse 5.0
But the new code is wrong.Could you please let me know what am I missing..

legacy code
Code: Select all
materials = ix.api.OfObjectVector()
filter = "*"
type = ["MaterialPhysicalStandard"]
for i in type:
    ix.application.get_matching_objects(materials, filter, i)

def delockAttrs(item):
    count = item.get_attribute_count()
    for i in range(count):
        item.get_attribute(i).set_read_only(False)

for mat in materials:

    diff = mat.attrs.diffuse
   
    ix.selection.select(ix.get_item(str(mat)))
    ix.application.select_next_outputs()
    sel = ix.application.get_selection()

    connected = sel.get_item(0).is_kindof("Geometry")



    context = mat.get_context()
    dpbr = ix.cmds.CreateObject(str(mat).split("/")[-1] + "_dpbr", "MaterialPhysicalDisneyPrincipled", "Global", str(context))
    delockAttrs(dpbr)

    if diff.attr.is_textured() :
        map = diff.attr.get_texture()
        dpbr.attrs.diffuse_front_color.attr.set_texture(map)
    else :
        dpbr.attrs.diffuse_front_color[0] = diff[0]
        dpbr.attrs.diffuse_front_color[1] = diff[1]
        dpbr.attrs.diffuse_front_color[2] = diff[2]



    if connected:
        ix.selection.select(ix.get_item(str(mat)))
        ix.application.select_next_outputs()
        sel = ix.selection
        for i in range(sel.get_count()):
            shadingG = sel[i].get_module().get_geometry().get_shading_group_names()
            count = shadingG.get_count()
            for j in range(count):
                shaders = sel[i].attrs.materials[j]
                if shaders == mat:
                    ix.cmds.SetValues([sel[i].get_full_name() + ".materials" + str([j])], [str(dpbr)])

### Delete the old legacy material
    ix.cmds.DeleteItems([str(mat)])
### Set the exact same name as the old legacy material (for shading layers rules)
    ix.cmds.RenameItem(dpbr, str(dpbr).split("/")[-1][:-4])


New code
Code: Select all
materials = ix.api.OfObjectFactory()
filter = "*"
type = ["MaterialPhysicalDisneyPrincipled"]
for i in type:
    ix.application.get_matching_objects(materials, filter, i)

def OfAttr(item):
    count = item.get_attribute_count()
    for i in range(count):
        item.get_attribute(i).set_read_only(False)

for mat in materials:

    base_color  = mat.attrs.base_color



    ix.selection.select(ix.get_item(str(mat)))
    ix.application.select_next_outputs()
    sel = ix.application.get_selection()

    connected = sel.get_item(0).is_kindof("Geometry")



    context = mat.get_context()
    dpbr = ix.cmds.CreateObject(str(mat).split("/")[-1] + "_dpbr", "MaterialPhysicalAutodeskStandardSurface", "Global", str(context))
    OfAttr(dpbr)

    if base_color.attr.is_textured() :
        map = base_color.attr.get_texture()
        dpbr.attrs.base_color.attr.set_texture(map)
    else :
        dpbr.attrs.base_color[0] = base_color[0]
        dpbr.attrs.base_color[1] = base_color[1]
        dpbr.attrs.base_color[2] = base_color[2]



    if connected:
        ix.selection.select(ix.get_item(str(mat)))
        ix.application.select_next_outputs()
        sel = ix.selection
        for i in range(sel.get_count()):
            shadingG = sel[i].get_module().get_geometry().get_shading_group_names()
            count = shadingG.get_count()
            for j in range(count):
                shaders = sel[i].attrs.materials[j]
                if shaders == mat:
                    ix.cmds.SetValues([sel[i].get_full_name() + ".materials" + str([j])], [str(dpbr)])

### Delete the old legacy material
    ix.cmds.DeleteItems([str(mat)])
### Set the exact same name as the old legacy material (for shading layers rules)
    ix.cmds.RenameItem(dpbr, str(dpbr).split("/")[-1][:-4])


Thank you
zheying
 
Posts: 1
Joined: Sun Aug 05, 2018 5:03 am

Return to Scripting