Isotropix Forums

Default expressions

Clarisse Scripting related topics

Default expressions

Unread postby julian » Mon May 06, 2019 6:59 pm

Is it possible when writing a scripted class, to specify a default expression, so that when the user goes to Right-click->Reset Attribute the existing value/expression is replaced with the default expression?

Thanks!

julian
julian
 
Posts: 23
Joined: Tue Feb 05, 2019 2:51 pm

Re: Default expressions

Unread postby bvaldes » Tue May 07, 2019 3:03 pm

Hi,

To create a scripted class, you have to use CID. In the SDK documentation, you have a section dedicated to the CID: https://clarissewiki.com/4.0/sdk/cid_intro.html
At the Properties' section, you have an example with a custom value set. This is by using the value keyword that you are able to set the value you want. When inside of Clarisse you reset the attribute, you set back the default value written in the CID.

Take a look to the following example:

python code

# The brain of our system
class MyScriptedClassAction(ix.api.ModuleScriptedClassEngine):
def __init__(self):
ix.api.ModuleScriptedClassEngine.__init__(self)

def on_attribute_change(self, object, attr, dirtiness, dirtiness_flags):
"""
Each time that an attribute of this object change, this function will be called.
So if you mode a slider this funciton is called with the attribute edited as param
"""
if attr.get_name() == "slider_custom":
layer = attr.get_parent_object().get_attribute("layer_to_affect").get_object(0)
print layer
print "The attribute", attr.get_name(), "is changing"


my_cid = """
reference "layer_to_affect"{
filter "Layer"
}
double[1] "slider_custom" {
value 10.0
ui_range yes 0.0 50.0
doc "Set the."
}
"""
classe = ix.api.ModuleScriptedClass.register_scripted_class(ix.application, "my_scripted_class", MyScriptedClassAction(), my_cid)
ix.cmds.CreateObject("scriptedClass", "my_scripted_class", "Global", "project://scene")


You can see line 22 that I've set the value to 10.0, if you run this script and edit this value in the attribute editor and then reset the value: the value is back to 10.0 in the attribute editor.

I hope this is what you are looking for. Tell us if you need more information.

Best regards
Benoit VALDES
Isotropix
Clarisse QA
User avatar
bvaldes
 
Posts: 384
Joined: Mon Sep 26, 2016 10:44 am

Re: Default expressions

Unread postby julian » Tue May 07, 2019 6:40 pm

Hi Benoit,

Thank you for this. However, I don't think it solves my issue.

I would like to have an SeExpr expression controlling my attribute by default. For a simplistic example: $FPS * 0.5

The value would resolve to 12, or maybe 15. Now suppose the user deleted the expression. The behavior I would like, is for the Reset Attribute menu-item to set the SeExpr expression back to $FPS * 0.5

For that to happen, there would need to be some way to specify an expression as the default, not a value.

It's not very important, but it would make usability better for my class.

Many thanks.
julian
 
Posts: 23
Joined: Tue Feb 05, 2019 2:51 pm

Re: Default expressions

Unread postby bvaldes » Thu May 09, 2019 10:16 am

Hi,

Sorry I didn't understood what you really wanted. It's simple: replace the value keyword by the expression one.
Everything is set in the CID is considered as default. So if you set and expression in the CID this is be the default value.
You can take a look to the script I gave you but edited:

python code

# The brain of our system
class MyScriptedClassAction(ix.api.ModuleScriptedClassEngine):
def __init__(self):
ix.api.ModuleScriptedClassEngine.__init__(self)

def on_attribute_change(self, object, attr, dirtiness, dirtiness_flags):
"""
Each time that an attribute of this object change, this function will be called.
So if you mode a slider this funciton is called with the attribute edited as param
"""
if attr.get_name() == "slider_custom":
layer = attr.get_parent_object().get_attribute("layer_to_affect").get_object(0)
print layer
print "The attribute", attr.get_name(), "is changing"


my_cid = """
reference "layer_to_affect"{
filter "Layer"
}
double[1] "slider_custom" {
expression "$FPS*0.5"
ui_range yes 0.0 50.0
doc "Set the."
}
"""
classe = ix.api.ModuleScriptedClass.register_scripted_class(ix.application, "my_scripted_class", MyScriptedClassAction(), my_cid)
ix.cmds.CreateObject("scriptedClass", "my_scripted_class", "Global", "project://scene")


I hope this is what you asked this time.

Best regards
Benoit VALDES
Isotropix
Clarisse QA
User avatar
bvaldes
 
Posts: 384
Joined: Mon Sep 26, 2016 10:44 am

Re: Default expressions

Unread postby julian » Sat May 11, 2019 8:17 pm

Hi Benoit,
I'm not using CID, because I need more control over the order of buttons and attributes. However, I did the equivalent to your suggestion with set_expression() and it works perfectly.

Thanks very much for your help.
julian
 
Posts: 23
Joined: Tue Feb 05, 2019 2:51 pm


Return to Scripting
cron