Thank you once again I marked as solved
Posts made by EAZY5D
-
RE: Working with UserData Python
Humm thank you for the exception I just noticed I stopped my explanation at "GUI" Which totally was not my intention but also must have been frustrating for you. Again Thank you Really good support
-
RE: Working with UserData Python
@ferdinand I tried editing my post before, as I was able to get most of it working.
What I consider wrong is not the Indentations in the multi-line string, What I mean Is that I am trying to make this Whole Multiline String Gui
Using this code below Which I think is okay#it's Isolated now
LIne 13-28 and line 51 are all you really need to look atimport c4d from c4d import gui from random import randint # Welcome to the world of Python def randomColor(): r = randint(0,255) / 256.0 g = randint(0,255) / 256.0 b = randint(0,255) / 256.0 color = c4d.Vector(r,g,b) return color def CreateUserDataString(obj, name, parentGroup=None, shortname=None, text=None): if obj is None: return False if shortname is None: shortname = name bc = c4d.GetCustomDatatypeDefault(c4d.DTYPE_STRING) bc[c4d.DESC_NAME] = name bc[c4d.DESC_SHORT_NAME] = shortname bc[c4d.DESC_ANIMATE] = 0 bc[c4d.DESC_CUSTOMGUI] = c4d.CUSTOMGUI_STRINGMULTI if parentGroup is not None: bc[c4d.DESC_PARENTGROUP] = parentGroup if text is not None: bc[c4d.DESC_DEFAULT] = text element = obj.AddUserData(bc) return element # Main function def main(): CheckRun = doc.SearchObject("EaZyRetarget") if CheckRun == None: CreateER=c4d.BaseObject(c4d.Onull) CreateER[c4d.ID_BASELIST_NAME]="EaZyRetarget" CreateER()[c4d.ID_BASELIST_ICON_FILE] = "300000157" CreateER[c4d.ID_BASELIST_ICON_COLORIZE_MODE] = 1 CreateER()[c4d.ID_BASELIST_ICON_COLOR] = randomColor() doc.InsertObject(CreateER) msg = "WIP Disclamer:\n This could go Bad really Really Fast\n\n \ You want to make sure the Same Number of\n \ lines are avail on both include & exclude.\n\n\ If there is nothing to exclude just make that line\n\ a None in the exclude user data" QuickGuideVar = CreateUserDataString(CreateER,"Quick Guide for Custom",None,msg) message = "I have created a simple 'EaZyRetarget' object.\n\n\ All you need to do is drag the Parent of your Rig 'DOes not matter if it is a \ Null or your hipBone or the Rootbone' Inside the 'From' and 'To' link userdata\n\n\ and Rerun this Script We will work the work for you " gui.MessageDialog(message) else: print ("Don't Know don't care") if __name__=='__main__': main() c4d.EventAdd()
Here is what I get outputted the whole thing is not useable
An isolated code, Expected Behaviour, the Behaviour am getting.
-
Working with UserData Python
Really weird results.
Okay so I have these functions am using to create this user data's .
def CreateUserDataGroup(obj, name, parentGroup=None, columns=None, shortname=None, defaultopen=None, scale=None ): if obj is None: return False if shortname is None: shortname = name bc = c4d.GetCustomDatatypeDefault(c4d.DTYPE_GROUP) bc[c4d.DESC_NAME] = name bc[c4d.DESC_SHORT_NAME] = shortname bc[c4d.DESC_DEFAULT] = 0 bc[c4d.DESC_TITLEBAR] = 1 bc[c4d.DESC_GROUPSCALEV] = 0 if parentGroup is not None: bc[c4d.DESC_PARENTGROUP] = parentGroup if columns is not None: #DESC_COLUMNS VALUE IS WRONG IN 15.057 - SHOULD BE 22 bc[22] = columns if defaultopen != None: bc[c4d.DESC_DEFAULT] = 1 if scale != None: bc[c4d.DESC_GROUPSCALEV] = 1 return obj.AddUserData(bc) def CreateUserDataLink(obj, name, link, parentGroup=None, shortname=None): if obj is None: return False if shortname is None: shortname = name bc = c4d.GetCustomDatatypeDefault(c4d.DTYPE_BASELISTLINK) bc[c4d.DESC_NAME] = name bc[c4d.DESC_SHORT_NAME] = shortname if link is None: pass else: bc[c4d.DESC_DEFAULT] = link bc[c4d.DESC_ANIMATE] = c4d.DESC_ANIMATE_OFF bc[c4d.DESC_SHADERLINKFLAG] = True if parentGroup is not None: bc[c4d.DESC_PARENTGROUP] = parentGroup element = obj.AddUserData(bc) obj[element] = link return element def CreateUserDataInteger(obj, name, parentGroup=None, shortname=None, text=None): if obj is None: return False if shortname is None: shortname = name bc = c4d.GetCustomDatatypeDefault(c4d.DTYPE_LONG) bc[c4d.DESC_NAME] = name bc[c4d.DESC_SHORT_NAME] = shortname bc[c4d.DESC_ANIMATE] = 0 bc[c4d.DESC_CUSTOMGUI] = c4d.CUSTOMGUI_CYCLEBUTTON if parentGroup is not None: bc[c4d.DESC_PARENTGROUP] = parentGroup if text is not None: #Create a list of names and put them into a container names = c4d.BaseContainer() # for x in text.split(","): count = 0 for x in text: names.SetString(int(count), str(x)) count += 1 bc.SetContainer(c4d.DESC_CYCLE, names) bc[c4d.DESC_DEFAULT] = 0 element = obj.AddUserData(bc) return element def CreateUserDataString(obj, name, parentGroup=None, shortname=None, text=None): if obj is None: return False if shortname is None: shortname = name bc = c4d.GetCustomDatatypeDefault(c4d.DTYPE_STRING) bc[c4d.DESC_NAME] = name bc[c4d.DESC_SHORT_NAME] = shortname bc[c4d.DESC_ANIMATE] = 0 bc[c4d.DESC_CUSTOMGUI] = c4d.CUSTOMGUI_STRINGMULTI if parentGroup is not None: bc[c4d.DESC_PARENTGROUP] = parentGroup if text is not None: bc[c4d.DESC_DEFAULT] = text element = obj.AddUserData(bc) return element
but when I do Groups work fine so do links But all the others are glitched out.
Until I manually go into the user data and fix make a random edit then the integer works But as you can see in the gif Multiline string does not get fixed as shown in the image below
I still plan on adding "Scale V" to the string Userdata so help on that would be helpful
Below is the Simplified version of my code if you just want to copy and paste as see it for yourself
import c4d from c4d import gui from random import randint # Welcome to the world of Python def randomColor(): r = randint(0,255) / 256.0 g = randint(0,255) / 256.0 b = randint(0,255) / 256.0 color = c4d.Vector(r,g,b) return color def CreateUserDataGroup(obj, name, parentGroup=None, columns=None, shortname=None, defaultopen=None, scale=None ): if obj is None: return False if shortname is None: shortname = name bc = c4d.GetCustomDatatypeDefault(c4d.DTYPE_GROUP) bc[c4d.DESC_NAME] = name bc[c4d.DESC_SHORT_NAME] = shortname bc[c4d.DESC_DEFAULT] = 0 bc[c4d.DESC_TITLEBAR] = 1 bc[c4d.DESC_GROUPSCALEV] = 0 if parentGroup is not None: bc[c4d.DESC_PARENTGROUP] = parentGroup if columns is not None: #DESC_COLUMNS VALUE IS WRONG IN 15.057 - SHOULD BE 22 bc[22] = columns if defaultopen != None: bc[c4d.DESC_DEFAULT] = 1 if scale != None: bc[c4d.DESC_GROUPSCALEV] = 1 return obj.AddUserData(bc) def CreateUserDataLink(obj, name, link, parentGroup=None, shortname=None): if obj is None: return False if shortname is None: shortname = name bc = c4d.GetCustomDatatypeDefault(c4d.DTYPE_BASELISTLINK) bc[c4d.DESC_NAME] = name bc[c4d.DESC_SHORT_NAME] = shortname if link is None: pass else: bc[c4d.DESC_DEFAULT] = link bc[c4d.DESC_ANIMATE] = c4d.DESC_ANIMATE_OFF bc[c4d.DESC_SHADERLINKFLAG] = True if parentGroup is not None: bc[c4d.DESC_PARENTGROUP] = parentGroup element = obj.AddUserData(bc) obj[element] = link return element def CreateUserDataInteger(obj, name, parentGroup=None, shortname=None, text=None): if obj is None: return False if shortname is None: shortname = name bc = c4d.GetCustomDatatypeDefault(c4d.DTYPE_LONG) bc[c4d.DESC_NAME] = name bc[c4d.DESC_SHORT_NAME] = shortname bc[c4d.DESC_ANIMATE] = 0 bc[c4d.DESC_CUSTOMGUI] = c4d.CUSTOMGUI_CYCLEBUTTON if parentGroup is not None: bc[c4d.DESC_PARENTGROUP] = parentGroup if text is not None: #Create a list of names and put them into a container names = c4d.BaseContainer() # for x in text.split(","): count = 0 for x in text: names.SetString(int(count), str(x)) count += 1 bc.SetContainer(c4d.DESC_CYCLE, names) bc[c4d.DESC_DEFAULT] = 0 element = obj.AddUserData(bc) return element def CreateUserDataString(obj, name, parentGroup=None, shortname=None, text=None): if obj is None: return False if shortname is None: shortname = name bc = c4d.GetCustomDatatypeDefault(c4d.DTYPE_STRING) bc[c4d.DESC_NAME] = name bc[c4d.DESC_SHORT_NAME] = shortname bc[c4d.DESC_ANIMATE] = 0 bc[c4d.DESC_CUSTOMGUI] = c4d.CUSTOMGUI_STRINGMULTI if parentGroup is not None: bc[c4d.DESC_PARENTGROUP] = parentGroup if text is not None: bc[c4d.DESC_DEFAULT] = text element = obj.AddUserData(bc) return element def CreateUserDataPopUP(obj, name, parentGroup=None, shortname=None): if obj is None: return False if shortname is None: shortname = name bc = c4d.GetCustomDatatypeDefault(c4d.DTYPE_POPUP) def SmartCheckSelectedObjs(): objs = doc.GetActiveObjects(1) if objs is None: return None elif len(objs) == 2: print ("In here 222") fixedobjs = [] FoundAParent = False count = 0 for x in objs: GetParent = x if x.GetUp() != None: while GetParent != None: count = count + 1 if count == 100: print ("Count break: " + count) print ("Inside whileLOop") GetParent = GetParent.GetUp() print (GetParent) # count = count + 1 if GetParent == None: print ("Yesttt ") else: GetParentPrev = GetParent # print ("This should neva happen") FoundAParent =True if FoundAParent == True: fixedobjs.append(GetParentPrev) else: fixedobjs.append(x) else: fixedobjs.append(x) for elem in fixedobjs: if fixedobjs.count(elem) > 1: print ("Duplicate found") return None return fixedobjs elif len(objs) <= 2 or len(objs) > 15: return None else: print ("Fuck it all broken") def main(): CheckRun = doc.SearchObject("EaZyRetarget") if CheckRun == None: CreateER=c4d.BaseObject(c4d.Onull) CreateER[c4d.ID_BASELIST_NAME]="EaZyRetarget" CreateER()[c4d.ID_BASELIST_ICON_FILE] = "300000157" CreateER[c4d.ID_BASELIST_ICON_COLORIZE_MODE] = 1 CreateER()[c4d.ID_BASELIST_ICON_COLOR] = randomColor() doc.InsertObject(CreateER) layerGroup = CreateUserDataGroup(CreateER,"EaZyRetargetMain",c4d.DescID(0), "EaZyRetarget", defaultopen=True, scale=True) FsubGroup = CreateUserDataGroup(CreateER,"From",layerGroup,2,defaultopen=True) ListOfSupportedRigTypes = [ " EaZyRig_Game\n" "1; EaZYRig_Standard\n" "2; EaZYRig_Full\n" "-1; " "3; AccuRig\n" "4; Mixamo\n" "5; Rococo\n" "6; Cascadeur\n" "7; UE5\n" "8; Custom\n" ] fromCycleButton = CreateUserDataInteger(CreateER,"From",FsubGroup, None, ListOfSupportedRigTypes) try: print ("IN try") checkobjs = SmartCheckSelectedObjs()[0] print (checkobjs) print ("No try error") except: print ("Yeppp totally") checkobjs = SmartCheckSelectedObjs() # checkobjs = None fromCycleLink = CreateUserDataLink(CreateER,"From", checkobjs,FsubGroup, None) TsubGroup1 = CreateUserDataGroup(CreateER,"To",layerGroup,2, defaultopen=True) ToCyclebutton = CreateUserDataInteger(CreateER,"To",TsubGroup1, None, ListOfSupportedRigTypes) try: checkobjs = SmartCheckSelectedObjs()[1] print (checkobjs) except: checkobjs = SmartCheckSelectedObjs() # checkobjs = None ToCycleLink = CreateUserDataLink(CreateER,"To", checkobjs,TsubGroup1, None) QUickGuidesubGroup = CreateUserDataGroup(CreateER,"Quick Guide for Custom",layerGroup,2,defaultopen=False,scale=True) msg = "WIP Disclamer:\n This could go Bad really Really Fast\n\n \ You want to make sure the Same Number of\n \ lines are avail on both include & exclude.\n\n\ If there is nothing to exclude just make that line\n\ a None in the exclude userdata" QuickGuideVar = CreateUserDataString(CreateER,"Quick Guide for Custom",QUickGuidesubGroup,msg) CustomsubGroup1 = CreateUserDataGroup(CreateER,"Custom Rigs",layerGroup,2, defaultopen=False,scale=True) # bc = c4d.GetCustomDataTypeDefault(c4d.DTYPE_GROUP) # Create default container # bc[c4d.DESC_NAME] = "EaZyRetargetMain" # bc[c4d.DESC_SHORT_NAME] = "EaZyRetarget" # bc[c4d.DESC_VERSION] = 3 # bc[c4d.DESC_ANIMATE] = 0 # bc[c4d.DESC_COLUMNS] = 1 # bc[c4d.DESC_TITLEBAR] = True # bc[c4d.DESC_DEFAULT] = 1 # # pass empty DescID # bc[c4d.DESC_PARENTGROUP] = c4d.DescID() # element = CreateER.AddUserData(bc) # Add userdata container # bc1 = c4d.GetCustomDataTypeDefault(c4d.DTYPE_STRING) # Create default container # bc1[c4d.DESC_NAME] = "Name" # Rename the entry # bc1[c4d.DESC_ANIMATE] = 0 # bc1[c4d.DESC_PARENTGROUP] = element message = "I have created a simple 'EaZyRetarget' object.\n\n\ All you need to do is drag the Parent of your Rig 'DOes not matter if it is a \ Null or your hipBone or the Rootbone' Inside the 'From' and 'To' link userdata\n\n\ and Rerun this Script We will work the work for you " gui.MessageDialog(message) else: print("AAAAA") # for descId, bc in CheckRun.GetUserDataContainer(): # print ("*"*5,descId,"*"*5) # for key, val in bc: # for txt, i in c4d.__dict__.iteritems(): # if key == i and txt[:5]=="DESC_": # print (txt,"=",val) # break # else: # print (key,"=",val) # Execute main() if __name__=='__main__': main() c4d.EventAdd()
-
RE: Cinema4D GeDialog Not Updating.
Thanks for your prompt Reply, I was able to debug the whole thing yesterday, I don't know what to do with this post now though.
-
Cinema4D GeDialog Not Updating.
Dear Developers,
So I have this Class for a dynamic settings and help interface which works fine see code below. Here are the list of what is not included
Emm Code works for all versions from R21 - S25 Tested
- I have a .ini file which I read from with a fuction called loadSettings()
- A replace() fuction which I use to save setting's back to the .ini file
- a Fuction Called SMsg() which contain' s the message I pass to the replace() for any new message
See how it works in the gif below
it does just that it all works see the code below, After code contains the problem pls scroll down
# ID's # 1. Main Group That Holds ALl The Other Grooups ID_MAINGROUP2 = 19000 ID_SUBMAIN = 19500 # 2.LeftBox Group and CheckBox LB_GROUP = 3000 LB_USE_CUSTOM_COLOR = 3001 LB_TOGGLE_GLOW = 3002 # 3.RighBox Group and COMBObox COMBO_GROUP = 4000 COMBO_BOXID = 4003 COMBO_USE_ASV = 4004 COMBO_USE_ARV = 4005 # 4. Info INFO_GROUP = 5000 INFO_TEXTF = 5001 # Ok/Cancle BTN_GROUP = 7000 BTN_OK = 7001 BTN_CANCEL = 7002 # End of ID's class Settings_Gem(gui.GeDialog): """docstring for Settings""" def __init__(self): super(Settings_Gem, self).__init__() self.res = c4d.BaseContainer() def InitValues(self): print ("Refreshing GUI") defaultMSG, Msg1, Msg2, Msg3, Msg4 = SMsg() self.AppendGuiHelp(defaultMSG) return True def AppendGuiHelp(self, msg): replace(1, msg) # Flush the content of the group that holds all ours SubDialogs self.LayoutFlushGroup(INFO_GROUP) self.AddMultiLineEditText(INFO_TEXTF, c4d.BFH_SCALEFIT, inith=50, initw=500, style=c4d.DR_MULTILINE_READONLY | c4d.DR_MULTILINE_WORDWRAP) self.GroupEnd() # GUISettings,Camera,Comp,Focal,Toggle = loadSettings() GUISettings = loadSettings() txt = str(GUISettings["setINFO"]) txtfix = (txt.format("\n")) self.SetString(INFO_TEXTF, txtfix) # Notifies the content of the MainGroup has changed self.LayoutChanged(INFO_GROUP) return True def CreateLayout(self): bc = c4d.BaseContainer() # Initialize a base container self.SetTitle("Settings For SetCamS") # Set dialog title # ---------------------------------------------------------------------------------------- self.GroupBegin(ID_MAINGROUP2, c4d.BFH_LEFT, 1, 2) self.GroupBorderSpace(5, 5, 5, 5) # ---------------------------------------------------------------------------------------- self.GroupBegin(ID_SUBMAIN, c4d.BFH_FIT | c4d.BFH_LEFT, 4, 1) # self.GroupBorderSpace(5, 5, 5, 5) # self.GroupBorderNoTitle(c4d.BORDER_ACTIVE_3) # Check Box On Left self.GroupBegin(LB_GROUP, c4d.BFH_LEFT, 1, 1, "") self.GroupBorderNoTitle(c4d.BORDER_ACTIVE_4) self.GroupBorderSpace(5, 5, 5, 5) self.AddCheckbox(LB_USE_CUSTOM_COLOR, c4d.BFH_LEFT, 0, 13, "Use Custom Color") self.AddCheckbox(LB_TOGGLE_GLOW, c4d.BFH_LEFT, 0, 13, "Last Used Show Glow") self.GroupEnd() # Check Box On Right self.GroupBegin(COMBO_GROUP, c4d.BFH_RIGHT, 2, 1, "Cam Mode") self.GroupBorder(c4d.BORDER_ACTIVE_4) self.GroupBorderSpace(25,13, 25, 13) self.AddComboBox(COMBO_BOXID, c4d.BFH_RIGHT, 140, 13) self.AddChild(COMBO_BOXID, COMBO_USE_ASV, "Use ASV") self.AddChild(COMBO_BOXID, COMBO_USE_ARV, "Use ARV") self.GroupEnd() # End 'Alt' group self.GroupEnd() # Creates a group that will contain all the group representing each tab # self.GroupBegin(ID_MAINGROUP, c4d.BFH_SCALEFIT | c4d.BFV_SCALEFIT, 0, 0, '', 0) # self.GroupEnd() self.GroupBegin(INFO_GROUP, c4d.BFH_RIGHT, 2, 1, "INFO") self.GroupBorder(c4d.BORDER_ACTIVE_4) self.GroupBorderSpace(5, 3, 5, 3) self.AddMultiLineEditText(INFO_TEXTF, c4d.BFH_SCALEFIT, inith=50, initw=500, style=c4d.DR_MULTILINE_READONLY | c4d.DR_MULTILINE_WORDWRAP) # self.SetString(INFO_TEXTF, # "Pls Read!!! \nThis Shows You What Each Setting you Clicked On is Used For." # "\nDon't Ask Why! :| I Am Real Bad At Naming Sh*&" # "\n\nHold CTRL and Run the Script to Ignore All Selected Camera Obj(s), This will Apply any SetCam Script Settings to you C4D Default Camera\n" # "The Default Camera Selected is Based on the ASV/ARV in the Settings GUI.") self.GroupEnd() self.GroupBegin(BTN_GROUP, c4d.BFH_CENTER, 0, 0, "OK to SaVe Settings") # Begin 'Buttons' group self.GroupBorder(2) self.AddDlgGroup(c4d.DLG_OK | c4d.DLG_CANCEL) self.GroupEnd() # Set Defaults GUISettings = loadSettings() # GUISettings,Camera,Comp,Focal,Toggle = loadSettings() txt = str(GUISettings["setINFO"]) txtfix = (txt.format("\n")) self.SetString(INFO_TEXTF, txtfix) self.SetInt32(LB_USE_CUSTOM_COLOR, int(GUISettings['setC_Color'])) self.SetInt32(LB_TOGGLE_GLOW, int(GUISettings['setT_Glow'])) self.SetInt32(COMBO_BOXID, int(GUISettings['setCOMBO'])) return True def Command(self, id, msg): bc = c4d.BaseContainer() # Initialize a base container defaultMSG, Msg1, Msg2, Msg3, Msg4 = SMsg() ##################### # Save, Cancle, Esc # ##################### C_Color = int(self.GetInt32(LB_USE_CUSTOM_COLOR)) # Get color T_Glow = int(self.GetInt32(LB_TOGGLE_GLOW)) # Get glow Combo = int(self.GetInt32(COMBO_BOXID)) # Get Camera COMBO c4d.gui.GetInputState(c4d.BFM_INPUT_KEYBOARD, c4d.KEY_ESC, bc) if bc[c4d.BFM_INPUT_VALUE]: print("User Click on ESC") self.Close() return True # User click on Ok button if id == c4d.DLG_OK: print("User Click on Ok") saveSettings(C_Color, T_Glow, Combo) self.Close() return True # User click on Cancel button elif id == c4d.DLG_CANCEL: print("User Click on Cancel") # Close the Dialog self.Close() return True # print (id) ############################ # Staring To Write to File # ############################ if id == LB_USE_CUSTOM_COLOR: print ("Settings CustomCOlor") self.AppendGuiHelp(Msg1) return True if id == LB_TOGGLE_GLOW: print ("Settings ToggleGlow") self.AppendGuiHelp(Msg2) return True if id == COMBO_BOXID: if Combo == COMBO_USE_ASV: print ("Settings ASV") self.AppendGuiHelp(Msg3) return True elif Combo == COMBO_USE_ARV: print ("Settings ARV") self.AppendGuiHelp(Msg4) return True else: print ("WHF") self.AppendGuiHelp("Hahaha open a Fucking") return True diag = Settings_Gem() diag.Open(c4d.DLG_TYPE_MODAL_RESIZEABLE, 0, -2, -2, 200, 45) # Open dialog
Problem, Now I made a simple popUp dialog and copy pasted the Settings class just as it is and called it
if result == Settings_id: diag = Settings_Gem() diag.Open(c4d.DLG_TYPE_MODAL_RESIZEABLE, 0, -2, -2, 200, 45) # Open dialog
And It's a disaster sometimes I get a
SystemError: error return without exception set "Which is Fustrating"
or worse See gifThe whole thing just Falls Apart I would have pasted the whole code but it's like 2k line plus since it a completion of multiple Things all in one.
Ohh and the .ini File does update only the Gui in cinema4D does not