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

    Which Plugin Type to Choose?

    Scheduled Pinned Locked Moved PYTHON Development
    4 Posts 0 Posters 474 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 07/08/2017 at 08:35, xxxxxxxx wrote:

      I have a pretty basic question:

      I have a plugin that uses a dialog to get some values and then creates a bunch of objects in the current scene from data it loads externally. You might call it an import plugin.

      This sounds like it should probably be a "Tool" plugin?

      I coded it as a Tool plugin (RegisterToolPlugin) and it kind of works, but there is the kind of weird question on how to indicate back to Cinema when the plugin has done it's work and should give control back to Cinema. Right now, after it imports everything and the import is done, the cursor remains stuck with the icon of the plugin and I can't interact with the objects just imported.

      I'm clearly missing something...

      Here's the code if anybody has the nerves to have a quick look:

      import c4d  
      import os  
      import time  
      import array  
      import csv  
      import string  
      from c4d import gui, plugins, bitmaps, utils  
      from math import radians, atan2, asin, degrees, pi  
        
      PLUGIN_ID = 1039683  
      UI_LABEL = 10000  
      UI_FILENAME = 10001  
      UI_FILEDIALOG = 10002  
      UI_CHECKDEBUG = 10003  
      UI_CHECKLIMIT = 10004  
      UI_GO = 10005  
      UI_PROGRESS = 10006  
      UI_PROGRESSSUB = 10007  
        
      #The actual routine to import an ADT  
        
      def file_len(fname) :  
        with open(fname) as f:  
            for i, l in enumerate(f) :  
                pass  
        return i + 1  
          
      def objfile_has_geometry(fname) :  
        with open(fname) as f:  
            for l in iter(f) :  
                if(l.startswith("v")) :  
                    return True  
        return False  
          
      def escape_pressed() :  
        bc = c4d.BaseContainer()  
        rs = gui.GetInputState(c4d.BFM_INPUT_KEYBOARD, c4d.KEY_ESC, bc)  
        if rs and bc[c4d.BFM_INPUT_VALUE]:  
            if(gui.QuestionDialog("Stop Script and Abort Import?")) :  
                return True  
            else:  
                return False  
        return False  
        
      def ADTImport(filepath, debug, limit, dialog) :  
        
        ... (long routine to parse the file supplied)  
          
        return True  
        
      class SettingsDialog(gui.SubDialog) :  
        #Dialog Stuff  
          
        def CreateLayout(self) :  
            self.AddStaticText(id=UI_LABEL, flags=c4d.BFH_LEFT, initw=200, name="ADT File to Import")  
            self.AddEditText(id=UI_FILENAME, flags=c4d.BFH_SCALEFIT, initw=400, inith=10)  
            self.AddButton(id=UI_FILEDIALOG, flags=c4d.BFH_CENTER|c4d.BFH_SCALEFIT, name="Open File Browser")  
            self.AddCheckbox(id=UI_CHECKDEBUG, flags=c4d.BFH_LEFT, initw=200, inith=10, name="Debug Mode")  
            self.AddCheckbox(id=UI_CHECKLIMIT, flags=c4d.BFH_LEFT, initw=200, inith=10, name="Limit Parsing to first few objects")  
            self.AddButton(id=UI_GO, flags=c4d.BFH_CENTER|c4d.BFH_SCALEFIT, name="Start")  
            self.AddCustomGui(id=UI_PROGRESS, pluginid=c4d.CUSTOMGUI_PROGRESSBAR, name="Progress Bar", flags=c4d.BFH_SCALEFIT, minw=200, minh=10)  
            self.AddCustomGui(id=UI_PROGRESSSUB, pluginid=c4d.CUSTOMGUI_PROGRESSBAR, name="Progress Sub Bar", flags=c4d.BFH_SCALEFIT, minw=200, minh=10)  
            return True  
        
        def InitValues(self) :  
            self.SetBool(UI_CHECKDEBUG, False)  
            self.SetBool(UI_CHECKLIMIT, True)  
            return True  
                
        def Command(self, id, msg) :  
            if(id == UI_FILEDIALOG) :  
                self.SetString(UI_FILENAME, c4d.storage.LoadDialog(c4d.FILESELECTTYPE_SCENES, "Select ADT to import", c4d.FILESELECT_LOAD, "obj", "E:\Temp\Location\world\maps\ruinsoftheramore", "ruinsoftheramore_40_39.obj"))  
              
            if(id == UI_GO) :  
                if(self.GetString(UI_FILENAME)) :  
                    ADTImport(self.GetString(UI_FILENAME), self.GetBool(UI_CHECKDEBUG), self.GetBool(UI_CHECKLIMIT), self)  
            return True  
        
      class AIP(plugins.ToolData) :  
        #Plugin Stuff  
          
        def __init__(self) :  
            self.data = dict()                  #container   
        
        def AllocSubDialog(self, bc) :   
            return SettingsDialog(self.data)    #always return new instance(self.data)  
        
        
      if __name__ == "__main__":  
        bmp = bitmaps.BaseBitmap()  
        dir, file = os.path.split(__file__)  
        fn = os.path.join(dir, "res", "Icon.tif")  
        bmp.InitWith(fn)  
        if(plugins.RegisterToolPlugin(id=PLUGIN_ID, str="ADT Import",info=0, icon=bmp, help="ADT Import",dat=AIP())) :  
            print "ADT Import v0.1 initialized."  
      
      1 Reply Last reply Reply Quote 0
      • H Offline
        Helper
        last edited by

        On 07/08/2017 at 11:12, xxxxxxxx wrote:

        Hi,

        welcome to the Plugin Café forums 🙂

        No, a ToolData plugin is not the optimal way to go here. This plugin type is made for Tools, where the user interacts with the scene via the viewport (e.g. Move Tool,..).

        Of course you could implement it as a CommandData with a dialog to get the additional values.

        But for an importer actually SceneLoaderData is the plugin type to use. Unfortunately I only have a C++ example at hand (stl.cpp). In Python there's only an example of a SceneSaverData, but as it's more or less just the opposite, I guess, you can still get the idea: Py-IESMeta.pyp.

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

          On 07/08/2017 at 12:47, xxxxxxxx wrote:

          Thx for the input! That was exactly my "foobar".

          I changed it to a Command plugin and it works as intended now. I'll look into the SceneLoader to figure out whether that will give me any advantages.

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

            On 08/08/2017 at 01:47, xxxxxxxx wrote:

            One advantage of a SceneLoaderData is for example, that file of this type can be dragged directly onto Cinema.

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