Disabling a Protection Tag
-
Hello,
I'm trying to disable a Protection Tag's P, S, & R properties setting their dropdown menus to 'None.' The Script Log says it's as simple astag()[c4d.PROTECTION_P] = 0
but this does not work in practice.import c4d def disableProtection(doc): obj = doc.GetActiveObject() tags = obj.GetTags() for tag in tags: if tag.GetType() == 5629 and tag.GetTypeName() == "Protection": tag[c4d.PROTECTION_P] = 0 tag[c4d.PROTECTION_S] = 0 tag[c4d.PROTECTION_R] = 0 c4d.EventAdd() if __name__=='__main__': disableProtection(doc)
Can anyone explain what is going wrong? Thank you!
-
@blastframe Works fine for me actually.
Did you try to replace the numeric value by c4d.Tprotection? Is it necessary to check the type name as well? Did you try to just print the type value and name to the console to check? Does the loop find the tag but just doesn't set the values, or does it not find the tag at all?
-
@Cairyn said in Disabling a Protection Tag:
@blastframe Works fine for me actually.
Did you try to replace the numeric value by c4d.Tprotection? Is it necessary to check the type name as well? Did you try to just print the type value and name to the console to check? Does the loop find the tag but just doesn't set the values, or does it not find the tag at all?
@Cairyn Thank you for the reply. Accessing the tag with code is working (and checking the type name is unnecessary). I am able to set the tag's PSR properties and print their values but the tag's UI and behaviour do not change. Here is an image of my script on the left and the Protection tag attributes on the right after I run the script. As you can see the P, S, and R are all still set to "Lock" (1) while they should be "None" (0).
Oddly, I can change the dimension checkboxes successfully with:
tag[c4d.PROTECTION_P_X] = 0 tag[c4d.PROTECTION_P_Y] = 0 tag[c4d.PROTECTION_P_Z] = 0
Is this a bug? Are you on a Mac perhaps?
-
@blastframe Nope, I'm on a PC, R21 (newest fix). I copied your script from the post and it worked from the start, the attribute manager changes, the display of the axes in the viewport change, the behavior changes. It works as well with the constant and no name check - in the past, I had some weird issues with changing numeric "constants", that's why I asked about using the c4d.Tprotection one. But I cannot find any error whatsoever.
I would say you could notify the tag itself of a change, but then... it does work without that, so I have no explanation, sorry.
-
@Cairyn said in Disabling a Protection Tag:
I would say you could notify the tag itself of a change, but then... it does work without that, so I have no explanation, sorry.
Thanks for the reply. You were right about notifying the tag of the change! This fixed it:
import c4d def disableProtection(doc): obj = doc.GetActiveObject() tags = obj.GetTags() for tag in tags: if tag.GetType() == c4d.Tprotection: tag[c4d.PROTECTION_P] = 0 tag[c4d.PROTECTION_S] = 0 tag[c4d.PROTECTION_R] = 0 tag.Message(c4d.MSG_UPDATE) c4d.EventAdd() if __name__=='__main__': disableProtection(doc)
-
@blastframe good... although the question would be why it works for me without that. Then again it is entirely possible that some other plugin that I have installed has the side effect of updating all tags under certain circumstances...
-
@Cairyn Yes! I was thinking the same thing about my plugins. Maybe someone else out there wants to give the script a try to help determine if one of our setup's is causing the discrepancy.
Thanks again for your help.
-
Hello,
@blastframe said in Disabling a Protection Tag:
tag[c4d.PROTECTION_P_X] = 0
you should use the right type, this is a Boolean.
tag[c4d.PROTECTION_P_X] = False
you can use those symbols to define the function :
c4d.PROTECTION_NONE
c4d.PROTECTION_LOCK
c4d.PROTECTION_LIMIT
tag[c4d.PROTECTION_P] = c4d.PROTECTION_NONE
Last point, using
SetParameter
doesn't change the fact that you need to send a message to the tag.Cheers,
Manuel