Auto Open Preferences directly to the Settings

  • On 03/09/2016 at 10:13, xxxxxxxx wrote:

    User Information:
    Cinema 4D Version:   R12+ 
    Platform:   Windows; 
    Language(s) :     Python ;

    Hi Guys,
    This my number 3 Plugin i am doing,  I am getting really good at it lol 😂 specially after Nurbo Generator.
    Okay so this the problem guys:
    Now I would like to know how to auto open a area in the Preferences directly like this:

    I think CV Smart Export is do it just press the settings and it opens up directly :

    This my the script so far for testing.
    but when i press execute noting is happen.
    Any Ideas, that will be appreciative guys,
    AP Ashton

    import c4d
    def main() :
    #--| Auto Open DAE 1.4 Area 
        FilesTool=c4d.plugins.FindPlugin(DAE1_4\_ID, c4d.PLUGINTYPE_PREFS)	
    if \__name\_\_=='\__main\_\_':

  • On 05/09/2016 at 07:20, xxxxxxxx wrote:

    Hi Ashton,

    the function you are looking for is called PrefsLib_OpenDialog().
    And you can directly use for example the DAE1_4_ID from your code example with this function.

    One note of caution, though. Unfortunately the IDs listed in the manual for PrefsLib_OpenDiaslog() are wrong. Instead, until we have corrected the manual, you can use the IDs obtained with the code snippet shown in this thread (the one looping over the FilterPluginList and printing name and ID).

  • On 05/09/2016 at 19:08, xxxxxxxx wrote:

    I did it like this , here the code :
    import c4d
    from c4d import gui
    #Welcome to the world of Python

    #--| The Main C4D Formats ID's |--#
    Dae14_ID = 1022316

    def main() :

    FilesTool=c4d.plugins.FindPlugin(Dae14_ID, c4d.PrefsLib_OpenDialog(Dae14_ID))
    if __name__=='__main__':

    IT Work Andreas!
    thank you again!😉😄🙂  You the best Andreas!

  • On 06/09/2016 at 00:10, xxxxxxxx wrote:

    Hi Ashton,

    yes, it works, but only due to the tolerance of Python.
    What happens in your code:
    First PrefsLib_OpenDialog() gets called. This succeeds, the prefs dialog opens. The function will return True. Then this return value is fed into the type parameter of FindPlugin(). This will probably fail, due to the strange type parameter it got passed. And the return value of FindPlugin() is then assigned to a variable that gets never used afterwards.
    So, yes, it works, but the code is a bit wonky.

    Simply doing this is enough:


  • On 06/09/2016 at 07:24, xxxxxxxx wrote:

    Is there any way to unfold the branches in that dialog?
    This does not work. It only makes it active.

    c4d.PrefsLib_OpenDialog(465001638)   #<---The Import/Export branch


  • On 06/09/2016 at 08:10, xxxxxxxx wrote:

    Hi Scott,

    there's no option to unfold the branches, but if you open the prefs dialog of a specific im-/exporter (like in Ashton's example), the branch gets unfolded as needed.

  • On 06/09/2016 at 08:39, xxxxxxxx wrote:

    The branch always stays closed for me in R13. It never unfolds.


  • On 06/09/2016 at 08:44, xxxxxxxx wrote:

    Hi Scott,

    just tested and yes, you are right. In R13 it's not unfolding. This behavior changed with R15, since then the tree properly unfolds.

  • On 06/09/2016 at 08:48, xxxxxxxx wrote:

    OK. Thanks.

    Can you tell me quick if we can add things to the preferences with Python?
    AFAIK. The PrefsDialogObject class is still not supported. So I don't see any way to add custom prefs using Python.
    I'll ask this question in a new thread if you want.


  • On 06/09/2016 at 08:49, xxxxxxxx wrote:

    Yep, please open a new thread to keep everything tidy.

  • On 06/09/2016 at 16:51, xxxxxxxx wrote:

    Thanks again Andreas , so like this and also i hope who else see this it post, it can help them. This is a mock up example plugin code:

    # Plugin: C4DPythonDevelopmentExample
    # Developer: Ashton Rolle AKA AP Ashton
    #--------| Imports |-------#
    import c4d
    from c4d import plugins
    import os
    import webbrowser
    from c4d import gui, bitmaps
    from c4d import documents, storage
    import collections
    import urllib
    import sys, subprocess
    import math
    #---------| Plugin ID Register |------------------------#
    PLUGIN_ID = 1000001  # Get yours at and Plugin IDs 1000001-1000010 are reserved for development.
    #---------| Plugin ID Name |------------------------#
    PLUGIN_Name = "C4DPythonDevelopmentExample" # Your Plugin Name
    #--| ID's for Dialog User Interface, UI Buttons, and Check Buttons |--# 
    UI_FormatsDropDownMenu = 1001
    UI_DevelopmentSettingsGearButton = 1004
    #--| UI Formats IDS for the format List |--#
    DAE_1_4 = 1011
    FBX_ALL = 1012
    #--| The Main C4D Formats ID's |--#
    fbx_ID = 00000000 # Get Main C4D Export Formats ID
    dae1_4_ID = 00000000 # Get Main C4D Export Formats ID
    #------| UI  Layout |--#
    class C4DPythonDevelopmentExampleDialog(c4d.gui.GeDialog) :
        def CreateLayout(self) :
            self.SetTitle(PLUGIN_Name)   # Your Title for the Main Dialog or You can put it like this: self.SetTitle("C4DPythonDevelopmentExample")      
            self.AddStaticText(0, c4d.BFH_CENTER, 0, 0, "C4DPythonDevelopmentExample", c4d.BORDER_WITH_TITLE_BOLD)
            self.AddSeparatorH(200, flags=c4d.BFH_MASK)      
            self.GroupBegin(201, c4d.BFH_MASK, 1, 0, "Development Settings:")
            self.GroupBorderSpace(20, 5, 20, 5)
            self.GroupBegin(201, c4d.BFH_MASK, 2, 0, "")
            self.format_list = self.AddComboBox(UI_FormatsDropDownMenu, c4d.BFH_MASK, 200, 10, False) # DROP MENU using a ComboBox and in the list that is (AddChild) .
            self.AddChild(UI_FormatsDropDownMenu, DAE_1_4, 'COLLADA 1.4 (*.dae)')
            self.AddChild(UI_FormatsDropDownMenu, FBX_ALL, 'FBX (*.fbx)')
    	#---| Adding a UI Custom Image  Button |---#      
            bc = c4d.BaseContainer()
            path = os.path.join(os.path.dirname(__file__), "res/Icons+UI Icons", "ID_OPERATOR_BITMAP.png")  #The path to the image 
            bc.SetFilename(UI_DevelopmentSettingsGearButton, path)  # Add this location info to the conatiner 
            bc.SetLong(c4d.BITMAPBUTTON_BORDER, c4d.BORDER_ROUND) # Sets the border to look like a button
            self.myBitButton=self.AddCustomGui(UI_DevelopmentSettingsGearButton, c4d.CUSTOMGUI_BITMAPBUTTON, "", c4d.BFH_MASK, 20, 0, bc)
            self.myBitButton.SetImage(path, False)  # Add the image to the button
            return True        
        #--| The Set State of the Layout Interface |--#
        def InitValues(self) :
            self.SetLong(UI_FormatsDropDownMenu, UI_FormatsDropDownMenu)        
            return True
        #--| F.U.N.C.T.I.O.N.S |--#
        def DevelopmentSettings(self) :
            # This execute when user click on the gear settings button and # Check For Main Format ID from #--| The Main C4D Formats ID's |--#
            if self.GetLong(UI_FormatsDropDownMenu)==DAE_1_4:
                ExportPLUGIN_ID = dae1_4_ID
                return True     
    #--| C.O.M.M.A.N.D.S to Execute the F.U.N.C.T.I.O.N.S as been Set |-------------------------------------------------------#
        def Command (self, id, msg) :
            if id == UI_DevelopmentSettingsGearButton:
    #------|Initialize|--------------------|The Plugin Info and Plugin Register|----------------------------------------------------#
    class PYTHONDevelopmentData(c4d.plugins.CommandData) :
        dialog = None
        def Init(self, op) :
            return True
        def Message(self, type, data) :
            return True
        def Execute(self, doc) :
            if self.dialog is None:
                self.dialog = C4DPythonDevelopmentExampleDialog()
                print "C4DPythonDevelopmentExample  is Open"
            return self.dialog.Open(dlgtype=c4d.DLG_TYPE_ASYNC, pluginid=PLUGIN_ID, defaultw=210, defaulth=35)
        def RestoreLayout(self, sec_ref) :
            if self.dialog is None:
                self.dialog = C4DPythonDevelopmentExampleDialog()        
            return self.dialog.Restore(pluginid=PLUGIN_ID, secret=sec_ref)
        def ExecuteOptionID(self, doc, plugid, subid) :
            return True        
    if __name__ == '__main__':
        bmp = c4d.bitmaps.BaseBitmap()
        dir, file = os.path.split(__file__)
        fn = os.path.join(dir, "res/Icons", "icon_PYTHONDevelopment.png")
        print "C4DPythonDevelopmentExample \nPlugin Initialized and By AP Ashton Rolle."
        result = plugins.RegisterCommandPlugin(id=PLUGIN_ID, # Plugin Register ID
                                               str=PLUGIN_Name,  # This is for the Plugin Name to show in the Plugins list. 
                                               info=0,  # if you want a option Button or have a ExecuteOptionID c4d.PLUGINFLAG_COMMAND_OPTION_DIALOG | c4d.PLUGINFLAG_COMMAND_HOTKEY,
                                               help="What C4DPythonDevelopmentExample is do", 

    Thanks and,
    Cheers Guys,
    AP Ashton

  • On 07/09/2016 at 06:11, xxxxxxxx wrote:

    Hi Ashton,

    thanks for sharing your code. In general I think, code is better shared via GitHub or something alike. Way easier to browse and share.

Log in to reply