Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    LinkBox in .res not work

    Scheduled Pinned Locked Moved PYTHON Development
    19 Posts 0 Posters 1.9k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H Offline
      Helper
      last edited by

      On 01/01/2013 at 09:27, xxxxxxxx wrote:

      Originally posted by xxxxxxxx

      ehm, wild guess, your linkbox id isn't 10006 ? have you double checked it in the .h file ?

      Hi littledevil, happy new year 🙂

      the .h file is ok:

      CASELLAPERSONALE = 10005,
      VAIPERSONALE = 10006,

      10006 is the button.
      when i click the 10006 button, the linkBox in .res is not considered Confused 
      But if I use a linkbox integrated in the .pyp source, the  button, 10006 work...

      1 Reply Last reply Reply Quote 0
      • H Offline
        Helper
        last edited by

        On 01/01/2013 at 10:33, xxxxxxxx wrote:

        hm,

        never have used interface elements that provide methods, but on the seocond look this :

        print self.linkBox.GetLink()
        

        looks funny to me. how is c4d supposed to know what linkBox is ? shoudln't you read
        the respective ID (10005) first ? in the manual layout example it works, because you 
        asign your linkbox to that field of your class.

        1 Reply Last reply Reply Quote 0
        • H Offline
          Helper
          last edited by

          On 01/01/2013 at 10:52, xxxxxxxx wrote:

          littledevil I did not understand much, and google translate doesn't help me understand ....

          1 Reply Last reply Reply Quote 0
          • H Offline
            Helper
            last edited by

            On 01/01/2013 at 16:11, xxxxxxxx wrote:

            you din't asign the linkbox gui to a variable. you just used a variable with the name linkBox.

            def CreateLayout(self) :
            	self.LoadDialogResource(IDD_RISORSA)
            	# Here you don't
            	................
              
              
            def Command(self, id, msg) :
            	if id == 10006:
               # but here you use self.linkBox as if a LinkBoxGui has been asigend to it.
               # This line should actually raise a runtime error.
               print self.linkBox.GetLink()
              
            -----------------------------------------------------------------------------------------------------------------
              
            def CreateLayout(self) :
            	self.LoadDialogResource(IDD_RISORSA)
            	# Here you asign it to variable
            	self.linkBox = self.AddCustomGui(MY_LINKBOX, c4d.CUSTOMGUI_LINKBOX, "", c4d.BFH_SCALEFIT|c4d.BFV_SCALEFIT, 0, 0)
              
              
            def Command(self, id, msg) :
            	if id == 10006:
               # which you use here to access the LinkBoxClass
               print self.linkBox.GetLink()
            
            1 Reply Last reply Reply Quote 0
            • H Offline
              Helper
              last edited by

              On 02/01/2013 at 05:24, xxxxxxxx wrote:

              Originally posted by xxxxxxxx

              you din't asign the linkbox gui to a variable. you just used a variable with the name linkBox.

              def CreateLayout(self) :
              self.LoadDialogResource(IDD_RISORSA)
              # Here you don't
              ................
               
               
              def Command(self, id, msg) :
              if id == 10006:
                 # but here you use self.linkBox as if a LinkBoxGui has been asigend to it.
                 # This line should actually raise a runtime error.
                 print self.linkBox.GetLink()
               
              -----------------------------------------------------------------------------------------------------------------
               
              def CreateLayout(self) :
              self.LoadDialogResource(IDD_RISORSA)
              # Here you asign it to variable
              self.linkBox = self.AddCustomGui(MY_LINKBOX, c4d.CUSTOMGUI_LINKBOX, "", c4d.BFH_SCALEFIT|c4d.BFV_SCALEFIT, 0, 0)
               
               
              def Command(self, id, msg) :
              if id == 10006:
                 # which you use here to access the LinkBoxClass
                 print self.linkBox.GetLink()
              

              littledevil Thank you so much for your help I know that this is how it works.

              but I was wondering how to make it work with a c4d.CUSTOMGUI_LINKBOX in . res file 
              sorry if I can't express myself well 🙂

              and thanks for the patience that you have shown 🙂

              1 Reply Last reply Reply Quote 0
              • H Offline
                Helper
                last edited by

                On 02/01/2013 at 06:50, xxxxxxxx wrote:

                well, my example was aimed at a res file solution. you have to always think of how c4d works.
                almost everything has to be broken down into a BaseContainer. so if you have a gui which holds
                a textbox and a checkbox c4d creates somewhere a BaseContainer which looks something like 
                this pseudocode :

                myDialogBc = c4d.BaseContainer()
                myDialogBc[myTextBoxID] = 'TextBoxText'
                myDialogBc[myCheckBoxID] = checkBoxCheckValue
                

                when you call in your dialog :

                self.setString(myTextBoxID, 'new fancy string')
                

                c4d writes this internally into the bc of your dialog. which would be for our pseudo code
                example :

                myDialogBc[myTextBoxID] = 'new fancy string'
                

                but a BaseContainer can only contain certain data types. There are the basic data types like
                string, long and so on and there are CustomDataTypes. those are plugins which tell c4d how to
                store a specific class (which can hold any data) in a BaseContainer(). CustomGuis are a form
                of these CustomDataTypes.

                so when you have a LinkBoxGui in your dialog you have to get the LinkBoxGui class from the
                BaseContainer first and then you can use the methods provided by the class to change/read
                the data.

                # imagine this linkbox has been added in a resfile
                self.AddCustomGui(MY_LINKBOX, c4d.CUSTOMGUI_LINKBOX, "", c4d.BFH_SCALEFIT|c4d.BFV_SCALEFIT, 0, 0)
                # we use FindCustomGui to get the class stored in the BaseContainer at our ID
                myLinkBox = self.FindCustomGui(MY_LINKBOX, c4d.CUSTOMGUI_LINKBOX)
                #do something with the linkbox class
                print myLinkBox.GetLink()
                
                1 Reply Last reply Reply Quote 0
                • H Offline
                  Helper
                  last edited by

                  On 02/01/2013 at 12:32, xxxxxxxx wrote:

                  ^Using the code method you provided will create a LinkBox gizmo in the dialog. But when you try to grab the object in it the result is always None.

                  Here's a complete plugin example.
                  When LoadDialogResource() is used. The return from it is always None.
                  When LoadDialogResource() is commented out. The Linkbox works and returns what's inside of it properly.

                  https://sites.google.com/site/scottayersmedia/res Based Linkbox.zip

                  Also note in the .res file the comment I wrote that the accept flag for the linkbox throws an error too! 😠

                  This is why I avoid using .res files for dialogs at all costs. And only use them for making dialog based spline GUI's.
                  It's either buggy, broken, or just plain not documented properly by Maxon.

                  -ScottA

                  1 Reply Last reply Reply Quote 0
                  • H Offline
                    Helper
                    last edited by

                    On 02/01/2013 at 13:58, xxxxxxxx wrote:

                    Originally posted by xxxxxxxx

                    It's either buggy, broken, or just plain not documented properly by Maxon.

                    -ScottA

                    Yes ScottA, I'm the same I your opinion 🙂
                    Thank you ScottA and Thanks even littledevil !Thumbs Up[URL-REMOVED]


                    [URL-REMOVED] @maxon: This section contained a non-resolving link which has been removed.

                    1 Reply Last reply Reply Quote 0
                    • H Offline
                      Helper
                      last edited by

                      On 02/01/2013 at 16:36, xxxxxxxx wrote:

                      Originally posted by xxxxxxxx

                      ^Using the code method you provided will create a LinkBox gizmo in the dialog. But when you try to grab the object in it the result is always None.

                      Here's a complete plugin example.
                      When LoadDialogResource() is used. The return from it is always None.
                      When LoadDialogResource() is commented out. The Linkbox works and returns what's inside of it properly.

                      https://sites.google.com/site/scottayersmedia/.res Based Linkbox.zip

                      Also note in the .res file the comment I wrote that the accept flag for the linkbox throws an error too! 😠

                      This is why I avoid using .res files for dialogs at all costs. And only use them for making dialog based spline GUI's.
                      It's either buggy, broken, or just plain not documented properly by Maxon.

                      -ScottA

                      that is simply not true. i haven't red your whole example code, but i saw a comment saying 
                      c4d crashes when you set the refuse and and accept flags. this is kind of obvious because 
                      both these flags are description flags and dialog ressources  are not descriptions. you have 
                      also be careful about the lifettime of the linkbox class.

                      however here is little example plugin showing the two LinkBox methods which are exposed to
                      python in action (GetLink, SetLink). the plugin loads a dialog from a ressource file , creates on 
                      init a cube and inserts the cube into the document, then asigns it to the linkbox and as the last 
                      action it prints the linkbox content to the console.

                      if this really doesn't work for you (which i cannot really believe) this has to be an OS problem.

                      http://www.file-upload.net/download-7003752/LinkBoxGui.zip.html

                      import os, sys, string
                        
                      import c4d
                      from c4d import bitmaps, documents, gui, plugins
                        
                      PID = 1000001
                        
                      class fhLinkBoxDialog(gui.GeDialog) :
                          def __init__(self) :
                              self.LinkBox = None
                        
                          def CreateLayout(self) :
                              geRessource = plugins.GeResource()
                              geRessource.Init(os.path.dirname(__file__))
                              result = self.LoadDialogResource(10001, geRessource, 0)
                      	if (result) :
                              	linkBox = self.FindCustomGui(10002, c4d.CUSTOMGUI_LINKBOX)
                        
                              	cube = c4d.BaseObject(c4d.Ocube)
                              	doc = c4d.documents.GetActiveDocument()
                              	doc.InsertObject(cube)
                        
                              	linkBox.SetLink(cube)
                              	print linkBox.GetLink(doc, c4d.Ocube)
                              return result   
                        
                      class fhLinkBoxExample(plugins.CommandData) :
                          def __init__(self) :
                              self.ManagerDialog = fhLinkBoxDialog()
                        
                          def Execute(self, doc) :
                              screen = gui.GeGetScreenDimensions(0, 0, True)
                              result = self.ManagerDialog.Open(dlgtype  = c4d.DLG_TYPE_ASYNC,
                                                                                    pluginid = PID,
                                                          			      xpos     = int(screen['sx2'] / 2) - 300,
                                                         			      ypos     = int(screen['sy2'] / 2) - 300)
                              return result
                        
                      if __name__ == "__main__":
                          dir, f = os.path.split(__file__)
                          c4d.plugins.RegisterCommandPlugin (id   = PID,
                                                             str  = "fhLinkBox",
                                                             help = "",
                                                             info = 0,
                                                             dat  = fhLinkBoxExample(),
                                                             icon = None)
                      
                      1 Reply Last reply Reply Quote 0
                      • H Offline
                        Helper
                        last edited by

                        On 02/01/2013 at 17:35, xxxxxxxx wrote:

                        Doh!
                        Thanks for posting that code ferdinand.
                        I was returning True in my CreateLayout() method instead of returning the resource variable.
                        No wonder I was getting None type errors. 😊

                        @Caleidos4d,
                        I updated my example file because it works properly now.
                        Just drop any object into the linkbox gizmo and click the "execute" button. And it will get the name of the object in the linkbox.

                        The other gizmos don't do anything they're just there as filler. So ignore them.
                        Let me know when you've got the file. Because I'm going to delete it.

                        -ScottA

                        1 Reply Last reply Reply Quote 0
                        • H Offline
                          Helper
                          last edited by

                          On 12/01/2013 at 11:45, xxxxxxxx wrote:

                          Originally posted by xxxxxxxx

                          @Caleidos4d,
                          I updated my example file because it works properly now.
                          Just drop any object into the linkbox gizmo and click the "execute" button. And it will get the name of the object in the linkbox.

                          The other gizmos don't do anything they're just there as filler. So ignore them.
                          Let me know when you've got the file. Because I'm going to delete it.

                          -ScottA

                          Hi ScottA!
                          I realized just now that you've updated the post, I haven't had time to download the updated version of the file, thanks anyway 🙂

                          1 Reply Last reply Reply Quote 0
                          • H Offline
                            Helper
                            last edited by

                            On 12/01/2013 at 12:25, xxxxxxxx wrote:

                            I wondered what happened to you. 🙂

                            It has a bunch of notes and gizmo code in it for my own reference purposes that might be confusing to people. That's why I deleted it.
                            If you still want it just send me your e-mail address in a private message and I'll send it to you.

                            -ScottA

                            1 Reply Last reply Reply Quote 0
                            • H Offline
                              Helper
                              last edited by

                              On 12/01/2013 at 12:47, xxxxxxxx wrote:

                              i have sended my email address in private messagge, Thank ScottA!!

                              1 Reply Last reply Reply Quote 0
                              • H Offline
                                Helper
                                last edited by

                                On 12/01/2013 at 16:21, xxxxxxxx wrote:

                                Originally posted by xxxxxxxx

                                I was returning True in my CreateLayout() method
                                instead of returning the resource variable.

                                c4d.gui.GeDialog.LoadDialogResource() returns a boolean value, just like ~.CreateLayout() expects
                                as return type.

                                Best,
                                -Niklas

                                1 Reply Last reply Reply Quote 0
                                • H Offline
                                  Helper
                                  last edited by

                                  On 12/01/2013 at 17:09, xxxxxxxx wrote:

                                  When returning True in the CreateLayout() method. I only get proper results from locally created gizmos using the ADD() type coding method.
                                  Returning True while using a .res file in the CreateLayout() method results in zero values from my gizmos.

                                  In order to use a .res file and get proper results from my gizmos.
                                  This is an example of what I have to use in CreateLayout() :

                                    
                                  res = self.LoadDialogResource(ResBasedMenu)  
                                  self.mylink = self.FindCustomGui(MY_LINK, c4d.CUSTOMGUI_LINKBOX)  
                                  return res
                                  

                                  Same thing goes for C++ plugins.
                                  Everything is working fine for me now.

                                  -ScottA

                                  1 Reply Last reply Reply Quote 0
                                  • H Offline
                                    Helper
                                    last edited by

                                    On 13/01/2013 at 03:27, xxxxxxxx wrote:

                                    Hi Scott,
                                    What Cinema 4D release are you working with? I'm using R14 and do not hit this problem, but
                                    I remember there have been issues in an old R13 version with FindCustomGui(). However, the
                                    following code works in R13.051+ (maybe even older versions) including R14 of course.

                                    class MyDialog(c4d.gui.GeDialog) :  
                                    def CreateLayout(self) :  
                                    result = self.LoadDialogResource(res.DLG_TEST)  
                                    self.link = self.FindCustomGui(res.EDT_LINK, c4d.CUSTOMGUI_LINKBOX)  
                                    print "Return value of self.LoadDialogResource() :", result  
                                    # No difference in returning True or `result` here (for me).  
                                    return True  
                                    def InitValues(self) :  
                                    self.SetReal(res.EDT_WIDTH, 100, 0)  
                                    self.SetReal(res.EDT_HEIGHT, 100, 0)  
                                    return True  
                                    def Command(self, id, msg) :  
                                    if id == res.BTN_OK:  
                                    op = self.link.GetLink()  
                                    print "Link in linkbox:", op  
                                    elif id == res.BTN_CANCEL:  
                                    self.Close()  
                                      return True
                                    

                                    You can find my complete set-up here, but it requires c4dtools installed.
                                    Best,
                                    Niklas

                                    1 Reply Last reply Reply Quote 0
                                    • H Offline
                                      Helper
                                      last edited by

                                      On 13/01/2013 at 09:22, xxxxxxxx wrote:

                                      I think I was using R12 at the time.
                                      If I get a chance I'll try testing in R13.

                                      -ScottA

                                      1 Reply Last reply Reply Quote 0
                                      • First post
                                        Last post