Isotropix Forums

How to unlock an attribute that is disabled

Clarisse Scripting related topics

How to unlock an attribute that is disabled

Unread postby bvz » Mon Apr 12, 2021 9:15 am

Hi,

I have a script that modifies attributes on different nodes based on some criteria.

But the script dies if the attribute cannot be modified because another attribute has disabled the attribute in question.


Here is a sample of the script (this is just one portion, it does more than just unlock attributes):

Code: Select all
                # Check the locked status of the attribute and unlock if needed
                locked = False
                if attr.is_locked():
                    locked = True
                    ix.cmds.LockAttributes([item.get_full_name() + "." + attr.get_name()], False)

                value_count = attr.get_value_count()
                for i in range(value_count):
                    if expressions[i] != "":
                        ix.cmds.SetExpression([item.get_full_name() + "." + attr.get_name() + "[" + str(i) + "]"], [new_expression])



But when it runs it can easily fail if the attribute in question is not enabled because another attribute is set to 0. In this case, I get this error:

Code: Select all
Attribute 'project://asset_veg_bamboo_ac/shading/leaf/support/material_leaf.transmission_color' cannot be  unlocked.
Attribute 'project://asset_veg_bamboo_ac/shading/leaf/support/material_leaf.transmission_color[0]' is not editable.


In the example above I have a MaterialPhysicalStandard and I want to modify the Transmission Color. Unfortunately this script fails if the Transmission Strength is set to 0.

I could do a test for the Transmission Strength and see if it is 0, but that poses a number of problems:

1) The Transmission Strength is being driven by an expression, so I cannot easily set it to something other than 0 temporarily just to modify the values in the transmission color.

2) This script needs to be generic, and I don't really want to code exceptions for every attribute on every node type that might be disabled because some other attribute is set to 0.


Is there a better way to modify attributes that might be disabled?

Thanks

(We are still on sp5b because the later service packs process scatters differently and our scatters do not line up with previous renders from last year. If this is something that is not an issue in newer service packs, I can make sure we only run this script when in a newer version of Clarisse).
bvz
 
Posts: 97
Joined: Tue Dec 03, 2013 9:55 am

Re: How to unlock an attribute that is disabled

Unread postby anemoff » Wed Apr 14, 2021 1:11 pm

Hi,

First, note that "locked" and "read-only" are 2 different states. Even if both result in disabling the UI they don't have the same meaning. We generally use the "read-only" state for attribute dependencies like transmission_color and transmission_strength: when strength is 0, color is set read-only, otherwise read-write.
So you'll want to use the method "OfAttr.set_read_only" or the command "ix.cmds.DisableAttributes".

There's no easy solution for this problem because currently there's no way of knowing what are the dependencies between attributes.
So you have to handle each corner case by hand. Also, I'm not certain that all these dependencies are publicly documented.

In any case, you'll want to edit the dependency first (e.g. transmission_strength), then the dependent (e.g. transmission_color). The problem is knowing such dependencies...

This issue is not addressed in newer service packs, so updating the version won't help.
Anthony Nemoff
Isotropix
R&D Engineer
User avatar
anemoff
 
Posts: 376
Joined: Wed Jan 13, 2016 10:10 am

Re: How to unlock an attribute that is disabled

Unread postby bvz » Thu Apr 15, 2021 4:32 am

Thank you for the update. Good to know about the distinction between locked and read-only.

Unfortunately I cannot easily modify the dependency because it is not a value but rather an expression itself. I would have to copy the expression, set the value to something other than zero (or checked or something), modify the desired expression, and then reset the expression on the dependency.

I am not sure from your description whether I can manually (via code) set a parameter to not be read_only via the OfAttr.set_read_only method, so I will try that. If that does not work thenI will have to think about this problem a bit more and see if there is another way of handling it. It isn't a critical piece of code so perhaps I just think about abandoning this line of thinking and try something else.

Thanks
bvz
 
Posts: 97
Joined: Tue Dec 03, 2013 9:55 am

Re: How to unlock an attribute that is disabled

Unread postby anemoff » Thu Apr 15, 2021 1:19 pm

Actually, even if the attribute is read-only (which is mostly a UI thing), you can change its values by script.
But do this at your own risk (it should be safe though).

You can try the following in 4.0 to confirm:

python code

material = ix.cmds.CreateObject("standard", "MaterialPhysicalStandard", "Global", "project://scene")
tcolor = material.get_attribute('transmission_color')
tcolor.set_vec3d(ix.api.GMathVec3d(1, 0, 0))


So in this specific case, you don't need to change "transmission_strength" in order to change "transmission_color".

However, I can't guarantee that this will be true for other attributes with dependencies, because these dependencies are handled on a case-by-base basis in the modules. For example, some modules might validate or refuse the change if the dependency is read-only.
Anthony Nemoff
Isotropix
R&D Engineer
User avatar
anemoff
 
Posts: 376
Joined: Wed Jan 13, 2016 10:10 am

Re: How to unlock an attribute that is disabled

Unread postby bvz » Thu Apr 15, 2021 6:45 pm

Got it.

Thanks. I will give it a try.
bvz
 
Posts: 97
Joined: Tue Dec 03, 2013 9:55 am


Return to Scripting