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

    SceneLoaderData question.

    Scheduled Pinned Locked Moved PYTHON Development
    7 Posts 0 Posters 1.0k 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 31/01/2018 at 00:27, xxxxxxxx wrote:

      Hello guys. I'm trying to drag and drop a custom extension file into the editor window. So far so good, but i can't figure out how to merge the file in the active document. It always creates a new doc.
      Where can i pass the flags for the Load() method ?
      I think i need to pass the c4d. _SCENEFILTER_MERGESCENE.
      Confused
      _

        
      import c4d  
        
      Plugin_ID = 123456  
        
        
      class dsLoader(c4d.plugins.SceneLoaderData) :  
        
        def Identify(self, node, name, probe, size) :  
            file_name = name.lower()  
            if not file_name.endswith('.ds') : return False  
            return True  
        
        def ReadLines(self, file) :  
            with open(file, 'rU') as data:  
                ds_file = data.read().splitlines()  
            for line in ds_file:  
                print line  
        
        def Load(self, node, name, doc, filterflags, error, bt) :  
            self.ReadLines(name)  
            c4d.EventAdd()  
            return c4d.FILEERROR_NONE  
        
        
      if __name__ == "__main__":  
        c4d.plugins.RegisterSceneLoaderPlugin(id=Plugin_ID,  
                                              str="dsLoader",  
                                              g=dsLoader,  
                                              info=c4d.PLUGINFLAG_SCENELOADER_MERGEORIGINAL,  
                                              description="")  
      

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

        On 01/02/2018 at 09:26, xxxxxxxx wrote:

        Hi,

        the short answer is, this a limitation. Sorry.

        In the end it is not on the SceneLoader to decide, if it's a merge situation or a new scene needs to be created. It's the user's decision (unfortunately does not have the option to decide this on drag&drop). So, when the user explicitly calls "Merge...", SCENEFILTER_MERGESCENE will be set in filterflags. Otherwise it's not and in a SceneLoader you have no means to change it.

        The PLUGINFLAG_SCENELOADER_MERGEORIGINAL, while our SDK documentation suggests otherwise, does not really have to do with this behavior. We need to (and will) think about how to improve the docs for this.

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

          On 01/02/2018 at 20:47, xxxxxxxx wrote:

          Oh, I see. Thanks. Is there a way to get the current document where the drag&drop happened? So i can somehow "fake" the merge operation ? The 'doc' argument returns the new document.

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

            On 02/02/2018 at 04:05, xxxxxxxx wrote:

            No, I can not really provide or recommend a workaround here.
            Please also consider Load() might also be called, because some script or plugin calls LoadDocument() maybe as reaction to a command line option, in such situation there is no active document at all.

            But I will add an idea for our development, so we might get keyboard modifiers to change a drag&drop into a merge operation. I think, that would be the clean way to solve it.

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

              On 05/02/2018 at 08:10, xxxxxxxx wrote:

              I found a workaround. I return c4d.FILEERROR_USERBREAK in the Load() method so the file isn't actually loaded, but before that i call a c4d.SpecialEventAdd() with the user's choices to a MessageData plugin which can get the current document and calls the LoadDocument() or MergeDocument().

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

                On 06/02/2018 at 02:25, xxxxxxxx wrote:

                Hi,

                this workaround may work for your special case. I just want to add for future readers, that we can not really recommend it.
                To name just two issues:
                a) It probably behaves differently compared to user expectations (or the other importers)
                b) There are situations, this approach will simply fail or misbehave, e.g. when used with command line (there is no active document in this case) or with Xrefs.

                Not saying you can not go with this workaround, just be aware of the restrictions.

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

                  On 06/02/2018 at 11:06, xxxxxxxx wrote:

                  Thanks for the info. It will be used for drag&drop only, so I think it won't cause any problems 🙂

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