How to dynamically hide parameters
-
Hi,
I am trying to control which parameters of ObjectPlugin are shown/hidden depending on the values of another parameter.
For example, the Cloner object switches which parameters it displays depending on its "mode" parameter.
From the other threads I see that overriding GetDDescription() is the key to achieving this, but I just can't get it to work.
Any help would be appreciated.
-
Hello @kng_ito,
Thank you for reaching out to us. Modifying the description of a node via
NodeData.GetDDescription
should only be done when NodeData.GetDEnabling is not sufficient. To hide a parameter, the field c4d.DESC_HIDE must be set toTrue
. Find a simple example below.Cheers,
FerdinandResult:
File: pc14487.zip
Code:
// The description defintion of the tag Texample. CONTAINER Texample { NAME Texample; INCLUDE Texpression; // The main "Tag" tab of the tag. GROUP ID_TAGPROPERTIES { // The element which is being hidden (or not). REAL ID_HIDDEN_ELEMENT { MIN 0.0; MAX 100.0; UNIT METER; STEP 0.001; CUSTOMGUI REALSLIDER; } // The parameter based on which the hidden element is shown or not. BOOL ID_HIDE_CONDITION {} } }
"""Implements a tag which dynamically hides and shows a parameter. """ import c4d import typing class ExampleTagData(c4d.plugins.TagData): """Implements a tag which dynamically hides and shows a parameter. """ # The plugin ID for the hook. ID_PLUGIN: int = 1060794 @classmethod def Register(cls) -> None: """Registers the plugin hook. """ if not c4d.plugins.RegisterTagPlugin( id=cls.ID_PLUGIN, str="Example Tag", info=c4d.TAG_EXPRESSION | c4d.TAG_VISIBLE, g=cls, description="texample", icon=c4d.bitmaps.InitResourceBitmap(c4d.Tdisplay)): print(f"Warning: Failed to register '{cls}' tag plugin.") def Init(self, node: c4d.GeListNode) -> bool: """Called to initialize a tag instance. Args: node: The BaseTag instance representing this plugin object. """ self.InitAttr(node, float, c4d.ID_HIDDEN_ELEMENT) self.InitAttr(node, bool, c4d.ID_HIDE_CONDITION) node[c4d.ID_HIDDEN_ELEMENT] = 50.0 node[c4d.ID_HIDE_CONDITION] = False return True def Execute(self, tag: c4d.BaseTag, doc: c4d.documents.BaseDocument, op: c4d.BaseObject, bt: c4d.threading.BaseThread, priority: int, flags: int) -> int: """Called when expressions are evaluated to let a tag modify a scene. Not used in this case. """ return c4d.EXECUTIONRESULT_OK def GetDDescription(self, node: c4d.GeListNode, description: c4d.Description, flags: int) -> typing.Union[bool, tuple[bool, int]]: """Called by Cinema 4D when the description of a node is being evaluated to let the node dynamically modify its own description. """ # Bail when the description cannot be not fully loaded. if not description.LoadDescription(node.GetType()): return False, flags # Define the ID of the parameter we want to modify and get the ID of the parameter which is # currently to be evaluated. paramId: c4d.DescID = c4d.DescID(c4d.DescLevel(c4d.ID_HIDDEN_ELEMENT, c4d.DTYPE_REAL, 0)) evalId: c4d.DescID = description.GetSingleDescID() # Bail when there is a to be evaluated parameter and our parameter is not part of or equal # to the evaluated parameter. if (evalId and not paramId.IsPartOf(evalId)): return True, flags # Get the description data container instance (GetParameter>I<) for the parameter we want to # modify. All changes made to the container will be directly reflected on the node. paramData: c4d.BaseContainer = description.GetParameterI(paramId) if paramData is None: return True, flags # Set the hidden state of the parameter ID_HIDDEN_ELEMENT based on the value of the # parameter ID_HIDE_CONDITION. paramData[c4d.DESC_HIDE] = node[c4d.ID_HIDE_CONDITION] return True, flags | c4d.DESCFLAGS_DESC_LOADED if __name__ == "__main__": ExampleTagData.Register()