Object Plugin GUI with locked elements.



  • On 03/12/2017 at 07:04, xxxxxxxx wrote:

    Hello plugincafe!
    I'm trying to create UI for my plugin that will look like Spline object UI.


    As you can see in this screenshot, some settings of spline object are 'locked'. I copied the code from one of the spline objects from description folder but as you can see, my settings look completely different.

    This is how my code looks like

    INCLUDE ospline ; generates this ui but no settings are locked.
    I wonder how this can be done in my python object plugin.

    Download plugin: http://www.dropbox.com/s/rigs3rbmxeyuzps/Test Plugin 0.1.rar?dl=0



  • On 03/12/2017 at 10:25, xxxxxxxx wrote:

    Didn't test, since I don't have a lot of time right now but should have more tomorrow.

    According Python GetDEnabling is look like to be te part to override. Moreover you can find in the C++ manual of GetDEnabling an exemple about how to use it.

    Hope it's help.



  • On 03/12/2017 at 11:05, xxxxxxxx wrote:

    wow. thank you very much for the quick answer and also thanks for these links. I'll try to find answers there :)

    I have another GUI related question.
    I've never created plugins before, so I still can't understand how to link GUI elements and python code.
    Here is a simple plugin that creates a cube object and allows moving it on a Y-axis.
    I'm getting this error when adding this plugin object to my scene and this error keeps generating unless I change any parameter in the object tab.

    Traceback (most recent call last) :
    **  File "'test plugin.pyp'", line 26, in GetVirtualObjects**
    TypeError: a float is required

    Python code:

    Res/Description

    thank you again! :)

    plugin:
    https://www.dropbox.com/s/ph7lv6r6iilnfox/Test Plugin 0.rar?dl=0



  • On 03/12/2017 at 12:39, xxxxxxxx wrote:

    You have to initialize value the first time for that simply do

        def Init(self, node) :
            self.InitAttr(node, float, [c4d.TESTPLUGIN_VALUE])
      
            # 1 method
            data = node.GetDataInstance()
            data.SetFloat(c4d.TESTPLUGIN_VALUE, 200.0)
      
            #2 method
            node[c4d.TESTPLUGIN_VALUE] = 210.0
      
            return True
    

    You can find relevant informations and example about object creation inside ObjectData page.

    Btw there is a small error in the python example of NodeData.InitAttr where op should be remplaced with node.



  • On 03/12/2017 at 13:04, xxxxxxxx wrote:

    OMG! Thanks, buddy. U saved me again. I appreciate.
    Have a nice day!
    Cheers! 🍺



  • On 03/12/2017 at 16:46, xxxxxxxx wrote:

    The problem with float and int values is solved but I'm getting the same problem when trying to initialize bool data type.

    TypeError: __setitem__ expected int or bool, not None

    after manually enabling bool checkbox, this error disappears but then I'm getting this new error:
    AttributeError: 'module' object has no attribute 'TESTPLUGIN_BOOL'

    1. import c4d
    2. from c4d import plugins
    3. import os
    4. TESTPLUGIN_ID = 1000001  #Temporary ID
    5. TESTPLUGIN_VALUE = 10000 #Real Slider
    6. TESTPLUGIN_BOOL = 10001 #On/Off Checkbox
    7. class Testplugin(c4d.plugins.ObjectData) :
    8. def Init(self, node) :
    9. self.InitAttr(node, float, [c4d.TESTPLUGIN_VALUE])
    10. node[c4d.TESTPLUGIN_VALUE] = 0.0
    11. self.InitAttr(node, bool, [c4d.TESTPLUGIN_BOOL])
    12. node[c4d.TESTPLUGIN_BOOL] = True
    13. return True
    14. def GetVirtualObjects(self, op, hh) :
    15. obj = c4d.BaseObject(c4d.Ocube)
    16. obj.SetAbsPos(c4d.Vector(0,op[c4d.TESTPLUGIN_VALUE],0))
    17. obj[c4d.ID_BASEOBJECT_GENERATOR_FLAG] = op[TESTPLUGIN_BOOL]
    18. return obj
    19. if __name__ == "__main__":
    20. bmp = c4d.bitmaps.BaseBitmap()
    21. dir, file = os.path.split(__file__)
    22. fn = os.path.join(dir, "res", "icon.tif")
    23. bmp.InitWith(fn)
    24. result = plugins.RegisterObjectPlugin(id = TESTPLUGIN_ID,
    25. str = "Test Plugin",
    26. g = Testplugin,
    27. description = "Otestplugin",
    28. info = c4d.OBJECT_GENERATOR | c4d.OBJECT_POLYGONOBJECT,
    29. icon = bmp)

    Am I doing something wrong? :D
    And I still can't figure out this GetDEnabling example from C++



  • On 04/12/2017 at 01:19, xxxxxxxx wrote:

    I just notice you are using c4d constant and not directly your ID.
    Then if you want to still use c4d.TESTPLUGIN_VALUE instead of TESTPLUGIN_VALUE (which is define in your script), you have to move all your constant from "res\description\Otestplugin.h" to "res\.c4d_symbols.h"

    Or you can simply adapt your code

        def Init(self, node) :
            self.InitAttr(node, float, [TESTPLUGIN_VALUE])
            self.InitAttr(node, bool, [TESTPLUGIN_BOOL])
      
            node[TESTPLUGIN_VALUE] = 0.0
            node[TESTPLUGIN_BOOL] = True
      
            return True
    

    About GetDEnabling you fail it probably for the same reason

        def GetDEnabling(self, node, id, t_data, flags, itemdesc) :
            if id[0].id == TESTPLUGIN_VALUE:
              return False
      
            return True
    

    Hope it's help ! :)



  • On 04/12/2017 at 04:58, xxxxxxxx wrote:

    Hi,

    gr4ph0s already pointed one important issue out.

    A few additions from our side:

    If gr4ph0s post doesn't solve the issue completely, you may have run into another issue. Cinema 4D builds a cache of symbols (basically names for IDs, flags,...), which is stored in Cinema 4D's prefs folder (open C4D, open Preferences and click the "Open Preferences Folder..." button on the bottom left, in the appearing folder enter the prefs folder). Somettimes, when changing resource files, C4D fails to keep track of these changes. The simply delete the symbolcache file in the above described folder and restart Cinema.

    If you still have any issues with GetDEnabling(), maybe you want to check out the Py-DoubleCircle example in our GitHub repository (well, of course also included in the Python SDK archive).

    A final recommendation: When you post error messages and code, it can be a good idea to post the line number, where the error happened. You can get this information from the Console usually.


Log in to reply