Isotropix Forums

Setting dynamic rule using attribute value

Clarisse Scripting related topics

Setting dynamic rule using attribute value

Unread postby jboissinot » Fri Sep 06, 2019 7:50 pm

Hi,

Is it possible to set a dynamic inclusion/exclusion rule with using the value of an attribute?

Let's say I have an object - a group for instance - on which I created a string attribute, and I want to set the inclusion rule with using the value of this attribute so that it will filter some specific objects based on the attribute value.

I tried something like this:

Code: Select all
*/path/to/context/*/get_string("attribute_name")/*


But this doesn't seem to be working, so I was wondering if this is possible or actually supported, or maybe the syntax is just not correct to make it work.

Thanks,
Jeremy
jboissinot
 
Posts: 48
Joined: Tue Jan 29, 2019 10:36 pm

Re: Setting dynamic rule using attribute value

Unread postby anemoff » Mon Sep 09, 2019 11:02 am

Hi,

You want to use expressions, right?

First, click on the Sigma button to enable the expression, and then, type the expression.

Assuming the custom attribute "attr_name" belongs to the Group item, the expression simply needs the attribute name (no need to specify the full attribute path):
Code: Select all
get_string('attr_name')


However, if the attribute belongs to a another item, the expressions needs the full or relative path:
Code: Select all
get_string('relative/path/to/other/item/attr_name')

or
Code: Select all
get_string('project:/full/path/to/other/item/attr_name')


Cheers,
Anthony Nemoff
Isotropix
R&D Engineer
User avatar
anemoff
 
Posts: 174
Joined: Wed Jan 13, 2016 10:10 am

Re: Setting dynamic rule using attribute value

Unread postby jboissinot » Tue Sep 10, 2019 2:32 pm

Hi,

Yes I want to use expressions indeed. I'm a bit familiar with expressions as I already did some that worked well, and even in scripting.

What I was trying to achieve is to set an expression with mixing strings and attribute values.

I tried this which didn't work as the expression could not solve the result I was expecting to get:

Code: Select all
*/path/to/context/*/get_string("attribute_name")/*


But after doing further tests, I finally came up with this syntax which works fine:

Code: Select all
"*/path/to/context/*/" + get_string("attribute_name") + "/*"
jboissinot
 
Posts: 48
Joined: Tue Jan 29, 2019 10:36 pm

Re: Setting dynamic rule using attribute value

Unread postby anemoff » Tue Sep 10, 2019 3:52 pm

Oh I see, sorry I didn't fully understand the first time.
You are correct, you have to use the + operator between strings:
Code: Select all
"project://context/*" + get_string("custom_attr_name") + "*"

Then add '*' where needed to fit your needs, for example.

Here is an example project containing a Group that has a custom attribute "custom_filter", and looks for objects at a given path + filter.

Cheers,
Attachments
group_with_custom_attr_sexpr.project
(34.31 KiB) Downloaded 1 time
Anthony Nemoff
Isotropix
R&D Engineer
User avatar
anemoff
 
Posts: 174
Joined: Wed Jan 13, 2016 10:10 am

Re: Setting dynamic rule using attribute value

Unread postby jboissinot » Tue Sep 10, 2019 8:24 pm

No worries Anthony, I did find out what I was looking for, so all good! In fact, the expression works well and the group does filter the proper objects based on the given attribute values.
jboissinot
 
Posts: 48
Joined: Tue Jan 29, 2019 10:36 pm


Return to Scripting