Isotropix Forums

Scripting Snippets Cheatsheet

Clarisse Scripting related topics

Scripting Snippets Cheatsheet

Unread postby fran3d » Wed Jan 23, 2019 2:32 pm

Hello Community!

I was wondering, if there already is, or if not if we could consolidate known Snippets or ixcmds in a cheatsheet, so that anyone who is not exactly a programming guru can get the most out of Clarisse and begin scripting.

Sometimes the listener/log doesn`t show the right commands.

for i.e.

how can i query the number of polyobjects in a given context and apply a random object color to each one independently?
how can I get the position of an object?

What do you think about?
Does anyone like to fill the list up?

Many thanks.

Posts: 10
Joined: Thu Nov 23, 2017 3:46 pm

Re: Scripting Snippets Cheatsheet

Unread postby bvaldes » Wed Jan 23, 2019 4:04 pm


You can access to the SDK documentation to find almost all the functions that you can use inside of Clarisse. This link point on all function ix.cmds.something
You also have in your install folder lot's of python scripts that make Clarisse work: instal_folder/python. I think that all of this can be a good start to learn python for Clarisse.

As you may know, the way that Clarisse works is object oriented. That mean that some functions are specific to some objects. For exemple if you want to get the items of a context you have to use the following snippet:

python code

context = ix.get_item("project://context") #Get teh context object (a thing of type OfContext)

# The context object have a function get_all_objects() that fill a list of type OfObjectArray
# So you have to create an OfObjectArray() and set it as argument to the get_all_objects() function

objects = ix.api.OfObjectArray()

# Now the objects variable contain all the objects of the context
# you can get them individually by using a for loop
# as it's not a python list, you have to go through a list of index
# objects.get_count() gives you the number of item in the objects list
for i in range(objects.get_count()):
print objects[i]

To affect an item by hand in Clarisse, you edit their attributes in the attribute editor. In python it's the same but by code:

python code

item = ix.get_item("project://box") # get an item of Clarisse

# We want to change the Matte Color attribute of a geometry
# Let's first check if it's a geometry
if item.is_kindof("Geometry"): # Check if the item is kind of Geometry
# To activate the matte color we first have to set matte object to true
# To edit an attribute we have to use the ix.cmds.SetValue() function
# The function takes 2 arguments: the path of the attr to affect and the value to set
# The first argument is a string and the second is a list
attr = item.get_attribute("matte_object") #gives you the argument object
# We have to convert it to string to be used in the function
ix.cmds.SetValue(str(attr), ["1"])
# Now the matte object is ON so we can edit the matte color
attr = item.get_attribute("matte_color") # we get theattribute object
ix.cmds.SetValue(str(attr), ["1", "0", "0"]) # you just setted the value to a red

To get a value to an attribute, you have, like above, to get the attribute an use a get_something() function. Something is the type of attribute. For example:

python code

item = ix.get_item("project://box") # get an item of Clarisse

translate_attr = item.get_attribute("translate")

# The type of the attribute is double (because it's a float number)
# to find the the type of an attribute you can use get_type()
# that will return a number and to get the name of this type number
# you can use get_tye_name(number)
# these functions are partor the OfAttr type. Your argument has this type.
type_nbr = translate_attr.get_type()
type_name = translate_attr.get_type_name(type_nbr)
# Because it's a type double you will use get_double()
# if it was a type string you will use get_string() ...
# The get_something() functions have one argument, the value number you want
# Translate has 3 values so you will have to call get_double 3 times
x = translate_attr.get_double(0)
y = translate_attr.get_double(1)
z = translate_attr.get_double(2)

If you can't figure out how to do something in script feel free to ask on the forum.

best regards
Clarisse QA
User avatar
Posts: 384
Joined: Mon Sep 26, 2016 10:44 am

Return to Scripting