Isotropix Forums

Python scripting within Clarisse?

Clarisse Scripting related topics

Python scripting within Clarisse?

Unread postby Arvid » Mon Oct 07, 2013 3:56 pm

Hey,

As a quick test, I assumed that if I type for example SetCurrentFrame(11) inside the script editor and hit "Run", that the time cursor would jump to frame 11. But Clarisse does not react to anything I type in the script editor. Am I missing something obvious, or is this not how scripting works in Clarisse?
Arvid
 
Posts: 191
Joined: Thu Jan 31, 2013 3:44 pm

Re: Python scripting within Clarisse?

Unread postby sam » Mon Oct 07, 2013 4:08 pm

Not really, currently the commands outputted in Clarisse are not in Python format. Moreover the current syntax for calling commands is deprecated. The new version will come soon

You can use the clarisse_helper (check scripting documentation)
Code: Select all
ix.set_current_frame(11)

Actually its a helper call (wrapper) the real call underneath is:
Code: Select all
ix.application.get_factory().get_time().set_current_frame(float(frame_number))


This call the API directly without spawning a command (no undo then)
The undoable version is in AppBuiltinCommands (which is deprecated)
Sam Assadian
Isotropix
CEO/Founder
User avatar
sam
 
Posts: 1281
Joined: Fri Jan 25, 2013 11:33 pm

Re: Python scripting within Clarisse?

Unread postby support_team » Mon Oct 07, 2013 4:25 pm

In fact I advise you to have a look on the clarisse_helper.py source in the python directory located in your clarisse binary folder
Isotropix
Support Team
User avatar
support_team
 
Posts: 1020
Joined: Thu Jan 31, 2013 11:10 am

Re: Python scripting within Clarisse?

Unread postby Arvid » Mon Oct 07, 2013 4:30 pm

I see. Maybe you can help me more specifically? I'd like to loop over a list of the selected objects and set incrementing values for each of them. Alembic time offset in this case.


Code: Select all
# psuedo code:
for i in range(0,len(list)):
    list[i].setValue("frame_offset", i);


Possible?

support_team wrote:In fact I advise you to have a look on the clarisse_helper.py source in the python directory located in your clarisse binary folder


Thanks, I'll do that!
Arvid
 
Posts: 191
Joined: Thu Jan 31, 2013 3:44 pm

Re: Python scripting within Clarisse?

Unread postby support_team » Mon Oct 07, 2013 5:21 pm

actually it's not that hard: assuming you selected the items.
Here is an example you might find useful (toggle selected item visibility)
Code: Select all
# name of the history command so you can undo it
ix.begin_command_batch("Toogle3DViewVisibility")
# iterates over the selection
for i in range(ix.selection.get_count()):
    item = ix.selection[i]
    # check if the item class is a scene item (otherwise it won't have that attribute)
    if item.is_kindof("SceneItem"):
        # toggle the value of the attribute
        item.attrs.display_visible[0] = not item.attrs.display_visible[0]
   

ix.end_command_batch()
Isotropix
Support Team
User avatar
support_team
 
Posts: 1020
Joined: Thu Jan 31, 2013 11:10 am

Re: Python scripting within Clarisse?

Unread postby Arvid » Tue Oct 08, 2013 10:10 am

Thanks, that makes sense. But how do I know how to access other parameters such as abc_xform.frame_offset? There's some syntax voodoo that I'm unable to figure out without some specific code examples to look at.
Arvid
 
Posts: 191
Joined: Thu Jan 31, 2013 3:44 pm

Re: Python scripting within Clarisse?

Unread postby support_team » Tue Oct 08, 2013 10:18 am

You access directly the attribute like this:
Code: Select all
item.attrs.attribute_name

so in your case
Code: Select all
item.attrs.frame_offset


One important thing, the name of the attributes is the technical name and not the one displayed by the Attribute Editor. You can find all that information per object class in the HTML documentation in the section Reference > Technical Reference. Then select the object class you are interested in: AbcXform, GeometryAbcMesh...
Isotropix
Support Team
User avatar
support_team
 
Posts: 1020
Joined: Thu Jan 31, 2013 11:10 am

Re: Python scripting within Clarisse?

Unread postby Arvid » Tue Oct 08, 2013 10:33 am

Ah, can't believe I didn't try that! I thought I had to go a step below, as in "items.attrs.abc_xform.frame_offset". I guess I misinterpreted the API ref. Thanks!
Arvid
 
Posts: 191
Joined: Thu Jan 31, 2013 3:44 pm

Re: Python scripting within Clarisse?

Unread postby Arvid » Tue Oct 08, 2013 10:35 am

Another question, just so I get it. How come you write display_visible[0] for that parameter? It's listed as bool, so why access it as a list? Is it a Python thing?
Arvid
 
Posts: 191
Joined: Thu Jan 31, 2013 3:44 pm

Re: Python scripting within Clarisse?

Unread postby support_team » Tue Oct 08, 2013 10:54 am

Yes, all attributes are potentially arrays. To set the value you're currently obliged to use the subscript operator. However if you wish to get it then you don't need to write
Code: Select all
item.attrs.my_attribute_name[0]
Isotropix
Support Team
User avatar
support_team
 
Posts: 1020
Joined: Thu Jan 31, 2013 11:10 am

Next

Return to Scripting
cron