SceneLoaderData question.



  • 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.

    _

      
    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="")  
    



  • 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.



  • 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.



  • 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.



  • 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().



  • 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.



  • 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 :)


Log in to reply