Hide DescElements R18
-
On 26/11/2016 at 13:37, xxxxxxxx wrote:
Hello guys,
there are new methods like
NodeData.GetDDescription
(),NodeData.GetDParameter
( ),NodeData.SetDParameter
( ) and new members of descriptions, but I´m absolutly not able to get an idea what they are good for. As the title of this topic says I´d like to hide description elements of a NodeData. Is it possible now?Greetings and thx
rownn -
On 28/11/2016 at 07:12, xxxxxxxx wrote:
Hi,
in the examples o the Python SDK there's the Py-DynamicParametersObject demonstrating at least parts of what you can do with these functions.
Also the C++ SDK documentation contains manuals (not to be confused with the API reference pages) on these functions, which explain some background and might be valuable to Python developers as well: GetDDescription Manual, SetDParameter Manual, GetDParameter Manual
In short:
GetDDescription() lets you intercept the moment, when C4D requests the parameter description of your NodeData. Providing you with means to create and/or modify the description to your liking.
With GetDParameter() and SetDParameter() on the other hand you can get into the process of getting and setting a parameter of your NodeData. For example you can decide to store a parameter only in a member variable instead of the NodeData's BaseContainer (not recommended, just an example).
Now, to your actual question:
Yes, that's absolutely possible.One way would be to set the DESC_HIDE of the parameter description in GetDDescription().
Another way, if the description is dynamically created in GetDDescription(), is to create the parameter in question only if a certain condition is met.A final note, as we are nearing Christmas. Something to look forward to, there'll be an updated C++ SDK documentation soon, containing manuals all around GUI programming.
-
On 28/11/2016 at 07:40, xxxxxxxx wrote:
Hey Andreas,
thx alot
Your reply makes me antsy and I hope I can finish my current job soon to take a look into that stuff.Ill be back ... soon
rownn -
On 28/11/2016 at 11:51, xxxxxxxx wrote:
Ok, I don´t get it.
import os import math import sys import c4d from c4d import plugins, utils, bitmaps, gui PLUGIN_ID = 123446789 class GUItest(plugins.ObjectData) : def InitA(self, op, type, id, value) : self.InitAttr(op, type, [id]) op[id] = value def Init(self, op) : self.InitA(op, bool, c4d.GT_HIDE01, False) self.InitA(op, float, c4d.GT_REAL, 12) return True def GetDDescription(self, node, description, flags) : if not description.LoadDescription(node.GetType()) : return False singleID = description.GetSingleDescID() groupID = c4d.DescID(c4d.DescLevel(c4d.GT_GROUP1, c4d.DTYPE_GROUP, node.GetType())) if singleID: if singleID[0].id == c4d.GT_REAL: bc = c4d.GetCustomDataTypeDefault(c4d.DTYPE_REAL) if c4d.GT_HIDE01: bc.SetBool(c4d.DESC_HIDE, True) else: bc.SetBool(c4d.DESC_HIDE, False) description.SetParameter(singleID, bc, groupID) return (True, flags | c4d.DESCFLAGS_DESC_LOADED) def GetVirtualObjects(self, op, hierarchyhelp) : return None if __name__ == "__main__": dir, file = os.path.split(__file__) icon = bitmaps.BaseBitmap() icon.InitWith(os.path.join(dir, "res", "Icon_Default.png")) plugins.RegisterObjectPlugin(id=PLUGIN_ID, str="GUItest", g=GUItest, description="GUItest", icon=icon, info=c4d.OBJECT_GENERATOR)
-
On 29/11/2016 at 08:40, xxxxxxxx wrote:
Here's an example:
#This is an example how to hide node based descriptions using the GetDDescription() method added in R18 #The GetDEnabling() method added in R15 is used here to grey out the descriptions if desired import c4d from c4d import bitmaps, documents, plugins PLUGIN_ID = 100000 #Be sure to use a unique ID obtained from www.plugincafe.com class MyObject(plugins.ObjectData) : def Init(self, node) : data = node.GetDataInstance() data.SetBool(1111, False); data.SetString(2222, "default"); return True def GetDDescription(self, node, description, flags) : data = node.GetDataInstance() #load the parameters from the description resource if not description.LoadDescription(node.GetType()) : return False singleID = description.GetSingleDescID() ### Use this code block to hide/unhide the gizmo depending on the state of the checkbox gizmo ### #groupID = c4d.DescID(c4d.DescLevel(c4d.ID_OBJECTPROPERTIES, c4d.DTYPE_GROUP, node.GetType())) #The default group groupID = c4d.DescID(c4d.DescLevel(1000, c4d.DTYPE_GROUP, node.GetType())) paramID = c4d.DescID(c4d.DescLevel(2222)) if singleID is None or paramID.IsPartOf(singleID)[0]: bc = c4d.GetCustomDataTypeDefault(c4d.DTYPE_STRING) bc.SetString(c4d.DESC_NAME, "My String") if data.GetBool(1111) == True: bc.SetBool(c4d.DESC_HIDE, True) if data.GetBool(1111) == False: bc.SetBool(c4d.DESC_HIDE, False) if not description.SetParameter(paramID, bc, groupID) : return False #Shorter version using GetParameterI() if preferred #bc = description.GetParameterI(paramID, None) #if data.GetBool(1111) == True: bc.SetBool(c4d.DESC_HIDE, True) #if data.GetBool(1111) == False: bc.SetBool(c4d.DESC_HIDE, False) #Use this to change the text in the string gizmo depending on the state of the checkbox gizmo if data.GetBool(1111) == True: data.SetString(2222, "") else: data.SetString(2222, "Not default") return (True, flags | c4d.DESCFLAGS_DESC_LOADED) #Use this to grey out the string type gizmo if the checkbox is enabled """def GetDEnabling(self, node, id, t_data, flags, itemdesc) : data = node.GetDataInstance() paramID = id[0].id if data.GetBool(1111) == True: if paramID == 2222: return False else: if paramID == 2222: return True return True""" def GetBubbleHelp(self, node) : return "Plugin Bubble Help" if __name__ == "__main__": plugins.RegisterObjectPlugin(id=PLUGIN_ID, str="Hide/disable Description", g=MyObject, description="myobject", icon=bitmaps.InitResourceBitmap(c4d.Onull), info=c4d.OBJECT_GENERATOR) ### .res file ### CONTAINER myobject { NAME myobject; INCLUDE Obase; //Use this for the default group //GROUP ID_OBJECTPROPERTIES //{ // BOOL MY_CHECKBOX { } // STRING MY_STRING { } //} GROUP MY_GROUP { DEFAULT 1; //Makes is open by default BOOL MY_CHECKBOX { } STRING MY_STRING { } } } ### .h file ### #ifndef _myobject_H_ #define _myobject_H_ enum { MY_GROUP = 1000, MY_CHECKBOX = 1111, MY_STRING = 2222, }; #endif ### .str file ### STRINGTABLE myobject { myobject "Hide/disable Attributes"; MY_GROUP "My Group Tab"; MY_CHECKBOX "Toggle Me"; MY_STRING "My String"; }
-ScottA
-
On 29/11/2016 at 13:23, xxxxxxxx wrote:
HeyScott
thank you! Now it works and I´m able to do alot of funny stuff.
def GetDDescription(self, node, description, flags) : data = node.GetDataInstance() if not description.LoadDescription(node.GetType()) : return False singleID = description.GetSingleDescID() groupID = c4d.DescID(c4d.DescLevel(c4d.GT_GROUP1, c4d.DTYPE_GROUP, node.GetType())) paramID = c4d.DescID(c4d.DescLevel(c4d.GT_REAL)) if singleID is None or paramID.IsPartOf(singleID)[0]: bc = c4d.GetCustomDataTypeDefault(c4d.DTYPE_REAL) if data.GetBool(c4d.GT_HIDE01) == True: bc.SetBool(c4d.DESC_HIDE, True) elif data.GetBool(c4d.GT_HIDE01) == False: bc.SetString(c4d.DESC_NAME, "Real") bc.SetLong(c4d.DESC_UNIT, c4d.DESC_UNIT_METER) bc.SetBool(c4d.DESC_HIDE, False) if not description.SetParameter(paramID, bc, groupID) : return False return (True, flags | c4d.DESCFLAGS_DESC_LOADED)
But one of many questions and one note.
Question:
If I useif c4d.GT_HIDE01: ...
instead of
if data.GetBool(c4d.GT_HIDE01) == True: ...
nothing happens. Why?
Note:
If I print paramID.IsPartOf(singleID) cinema crashs.Thanks Andreas and Scott and greetings
rownn -
On 29/11/2016 at 14:00, xxxxxxxx wrote:
The code "if c4d.GT_HIDE01:" asks the question: if this integer.
But C4D doesn't know what that means without some context.
So you need to tell C4D to look in the node's container for that integer ( node.GetDataInstance() ).
That's what the "data" variable is used for in my example.It might have been clearer if I named it "bc" or maybe something like "nodeBC".
I tend to use "data" by habit.-ScottA
-
On 30/11/2016 at 05:38, xxxxxxxx wrote:
Damn! I used c4d.GT_HIDE01 instead of node[c4d.GT_HIDE01]. That´s embarrassing!!
-
On 30/11/2016 at 10:22, xxxxxxxx wrote:
Hi guys,
glad you seem to have solved the issue already.
I just want to add, that there's a slight difference between creating a new parameter description and changing an existing one in GetDDescription().
In the posted snippets it looks like you are creating a new description parameter. At least you are always overwriting the existing description parameter. It's a bit hard to tell, without seeing the resource files. In Scott's example this is definitely the case, if I'm not mistaken.
You can do so, but in such a case, where you have defined a description parameter in a resource file and just want to hide it, the approach would be slightly different. Instead of creating a new BaseContainer (and then having to care to set up everything the way you want, while you already did so before in the resource file) with GetCustomDataTypeDefault(), you'd rather use Description.GetParameterI() to get the existing BaseContainer of the parameter description and simply modify the needed value (e.g. in this case DESC_HIDE). -
On 30/11/2016 at 13:35, xxxxxxxx wrote:
Hey Andreas,
thx for that point. It would be nice to hide an element without the need to reset everything else, but
Description.GetParameterI
( id , ar ) crashs cinema, too.def GetDDescription(self, node, description, flags) : data = node.GetDataInstance() if not description.LoadDescription(node.GetType()) : return False singleID = description.GetSingleDescID() groupID = c4d.DescID(c4d.DescLevel(c4d.GT_GROUP1, c4d.DTYPE_GROUP, node.GetType())) paramID = c4d.DescID(c4d.DescLevel(c4d.GT_REAL)) if singleID is None or paramID.IsPartOf(singleID)[0]: bc = description.GetParameterI(paramID, []) #c4d.GetCustomDataTypeDefault(c4d.DTYPE_REAL) if node[c4d.GT_HIDE01]: bc[c4d.DESC_HIDE] = True elif not node[c4d.GT_HIDE01]: bc[c4d.DESC_HIDE] = False if not description.SetParameter(paramID, bc, groupID) : return False return (True, flags | c4d.DESCFLAGS_DESC_LOADED)
-
On 30/11/2016 at 15:07, xxxxxxxx wrote:
Try using None instead of "[]" in your GetParameterI() function.
I added the GetParameterI() version to my example.
-ScottA
-
On 01/12/2016 at 02:34, xxxxxxxx wrote:
Hey,
Ive already tried using None, but with None cinema freezes.
-
On 01/12/2016 at 07:25, xxxxxxxx wrote:
Since bc is assigned to GetParameterI() in your code. It will probably crash when it's used in the SetParameter() function.
Try it without using SetParameter() at the end. It doesn't seem to be needed when using the GetParameterI() function to change a description.Like this:
bc = description.GetParameterI(paramID, None) if data.GetBool(1111) == True: bc.SetBool(c4d.DESC_HIDE, True) if data.GetBool(1111) == False: bc.SetBool(c4d.DESC_HIDE, False)
-ScottA
-
On 01/12/2016 at 09:04, xxxxxxxx wrote:
Yep, Scott is right. Sorry, I forgot to tell yesterday.
But still, it shouldn't crash C4D. We are investigating. -
On 02/12/2016 at 04:40, xxxxxxxx wrote:
Thank you guys,
I though I had tried to uncomment that line, because it makes totally sense. Hmm...
Finally the code looks clean and works. I like such a finish.def GetDDescription(self, node, description, flags) : if not description.LoadDescription(node.GetType()) : return False singleID = description.GetSingleDescID() paramID = c4d.DescID(c4d.DescLevel(c4d.GT_REAL)) if singleID is None or paramID.IsPartOf(singleID)[0]: bc = description.GetParameterI(paramID, None) if node[c4d.GT_HIDE01]: bc[c4d.DESC_HIDE] = True else: bc[c4d.DESC_HIDE] = False return (True, flags | c4d.DESCFLAGS_DESC_LOADED)
thx again
rownnPS: Thanks 1M times all the guys who implemented that great possibility.