Isotropix Forums

need some help with a script

Clarisse Scripting related topics

need some help with a script

Unread postby jeff_bartzis » Tue Aug 18, 2020 11:00 pm

Hey all,

im looking for a bit of assistance getting this script to work.
The idea is to, in one click, build a clarisse asset from a selection of alembic references - Including context structure, combiners, materials, groups, shading layers, rules, etc.
everything is working so far, but I get some buggy behavior when it comes time to actually move the referenced alembic into the newly created /geo context.
when the script is run over a selection of multiple alembic references, it skips every second one for some reason.
however, if it's any other kind of object, like a mesh , a combiner, or even groups or lights or anything else(even though it's not the intended purpose to use this script on those latter objects), the script behaves normally.

I might be missing something trivial here, as I am not very knowledgeable with python, but any insight would be very appreciated.

if you want to try it out, just copy the code below, and run it while you have a bunch of alembic references selected. If you get the same issue as me, only half of the items will work. Then try again on a selection of any other type of item, and it should produce the actual intended effect.

(i have assets in a context: "project://_1_ASSETS", so to avoid the script trying to take you to that location, just comment out the last line, or make a context called _1_ASSETS in the project root.

using 4.0 sp9
also tested in 4.0 sp8 and sp2

python code

# Create a Clarisse asset from a selection

# get items from current selection and process each item
for item in ix.selection:
#get name and path of current selection
selName = item.get_name() #DETAIL_01
path = item.get_full_name() #project://_1_ASSETS/DETAIL_01

#create root asset context for current iteration
astroot = ix.create_context(path + '_ASSET') #project://_1_ASSETS/DETAIL_01_ASSET
#set asset context color to green
ix.cmds.ColorTagItems([astroot], "green")

#set variables
geoctx = (path + '_ASSET' + "/geo") #project://_1_ASSETS/DETAIL_01_ASSET/geo
lookctx = (path + '_ASSET' + "/look") #project://_1_ASSETS/DETAIL_01_ASSET/look
mainmat = (lookctx + "/" + selName + "_layered_mat") #project://_1_ASSETS/DETAIL_01_ASSET/look/DETAIL_01_layered_mat

#create contexts
ix.create_context(mainmat + "/textures")

#move selection to geoctx
ix.cmds.MoveItemsTo([item], str(geoctx))

#create catch-all group in geo subcontext
geogrp = ix.create_object(selName + "_grp", "Group")
ix.cmds.SetValues([str(geogrp) + ".inclusion_rule[0]"], ["./*"])

#create combiner connected to geo catch-all group
ix.set_current_context(path + '_ASSET')
astcmb = ix.create_object(selName + "_CMPLT", "SceneObjectCombiner")
ix.cmds.ColorTagItems([astcmb], "yellow")
ix.cmds.AddValues([str(astcmb) + ".objects"], [str(geogrp)])

#create shader network
matlayered = ix.create_object(selName + "_layered_mat", "MaterialPhysicalLayered")
matbase = ix.create_object(selName + "_mat", "MaterialPhysical")
#connect matbase to base input of layered shader
ix.cmds.SetValues([str(matlayered) + ".base"], [matbase])

#create shading layer
ix.set_current_context(path + '_ASSET')
shdlr = ix.create_object(selName + "_SL", "ShadingLayer")
#connect shading layer to geometry
ix.cmds.AddShadingLayerRule(shdlr, 0, ["filter", "", "is_visible", "1"])
ix.cmds.SetShadingLayerRulesProperty(shdlr, [0], "filter", [str(geoctx + "/*")])
ix.cmds.SetShadingLayerRulesProperty(shdlr, [0], "material", [str(matlayered)])

#reset current context back to assets
Posts: 28
Joined: Fri May 12, 2017 6:41 pm
Location: Vancouver

Re: need some help with a script

Unread postby anemoff » Wed Aug 19, 2020 9:54 am


The problem is that the selection contents are updated when you move each reference context.
You need to gather all items beforehand in a separate array, then work on them.

Like this for example:

python code

# gather all items in a separate array and avoid iterating directly in selection items
# because selection will be updated automatically when moving the contexts
items = []
for item in ix.selection:

# get items from current selection and process each item
for item in items:
# do the work...

Anthony Nemoff
R&D Engineer
User avatar
Posts: 335
Joined: Wed Jan 13, 2016 10:10 am

Return to Scripting