How can I one-click the fbx import?

On 02/07/2015 at 07:56, xxxxxxxx wrote:

Now I am writing a script that doing batch import fbx files that with animation into my c4d documents. Generally it should import each fbx into each c4d file by the specific folder. I have done most of all except the first step IMPORT... I have tried "c4d.documents.LoadDocument" but lose all of the animation in the fbx file.I also have tried "c4d.documents.LoadFile" but it always popup the Import Settings window and the Select Take window. My question is how I can make them auto press "OK" in the first window(Import Settings,that can be saved in the Preferences file) ,and auto check the Animation Start Time and Animation End Time(this setting cannot be saved so I need to check each time) then press "OK"?

On 02/07/2015 at 10:24, xxxxxxxx wrote:

OK. Now I know I should use MergeDocument. And it seems work well with animation. But how I can check the 2 option Animation Start Time and Animation End Time on the "Take Select" popup ?

On 03/07/2015 at 03:29, xxxxxxxx wrote:

Hello,

you cannot directly edit the import dialog of an importer or exporter. When you use MergeDocument() and don't set the SCENEFILTER_DIALOGSALLOWED flag, dialogs should not appear.

But you can edit the settings of the importer by accessing the importer plugin. You find an example showing to do this with the Alembic Exporter.

In the case of a FBX importer the configuration could look like this:

  
#select a file  
selectedFile = c4d.storage.LoadDialog(type=c4d.FILESELECTTYPE_ANYTHING, title="Choose FBX")  
  
if selectedFile is None:  
      return  
  
# find the FBX importer plugin  
plug = plugins.FindPlugin(1026369, c4d.PLUGINTYPE_SCENELOADER)  
if plug is None:  
      return  
  
# access the settings  
op = {}  
if plug.Message(c4d.MSG_RETRIEVEPRIVATEDATA, op) :  
      print op  
        
      fbximport = op["imexporter"]  
      if fbximport is None:  
              return  
        
      # define the settings  
      fbximport[c4d.FBXIMPORT_CAMERAS] = False  
  
      # import without dialogs  
      c4d.documents.MergeDocument(doc,selectedFile,c4d.SCENEFILTER_OBJECTS,None)  
  
c4d.EventAdd()  

You find the FBX settings defined in the header files of the FBX module in resource\modules\fbx\description and resource\modules\fbx\dialogs. Currently I have no FBX file with takes at hand to test your case.

Best wishes,
Sebastian

On 03/07/2015 at 08:34, xxxxxxxx wrote:

Thanks a lot Sebastian!!You gave me the way to find the answer!!Now I know how to configurate the import settings as the 1st POPUP window by script. But for the 2nd POPUP window that I indeed is to set the Animation Start Time and Animation End Time checked on. I have check the files that you mentioned above resource\modules\fbx\dialogs,what I understand is it is defining the UI of the popup window, not like the 1st popup window can be set the configuration like your example  fbximport[c4d.FBXIMPORT_CAMERAS] = False .I can find the 2 check script but they are just a ui script,right? 
Could you please explaind more of that? what I need is Animation Start Time and Animation End Time be checked.

Many thanks again!!

Best,
Ben

On 03/07/2015 at 09:18, xxxxxxxx wrote:

Originally posted by xxxxxxxx

Hello,

you cannot directly edit the import dialog of an importer or exporter. When you use MergeDocument() and don't set the SCENEFILTER_DIALOGSALLOWED flag, dialogs should not appear.

But you can edit the settings of the importer by accessing the importer plugin. You find an example showing to do this with the Alembic Exporter.

In the case of a FBX importer the configuration could look like this:

 
#select a file  
selectedFile = c4d.storage.LoadDialog(type=c4d.FILESELECTTYPE_ANYTHING, title="Choose FBX")  
 
if selectedFile is None:  
      return  
 
# find the FBX importer plugin  
plug = plugins.FindPlugin(1026369, c4d.PLUGINTYPE_SCENELOADER)  
if plug is None:  
      return  
 
# access the settings  
op = {}  
if plug.Message(c4d.MSG_RETRIEVEPRIVATEDATA, op) :  
      print op  
        
      fbximport = op["imexporter"]  
      if fbximport is None:  
              return  
        
      # define the settings  
      fbximport[c4d.FBXIMPORT_CAMERAS] = False  
 
      # import without dialogs  
      c4d.documents.MergeDocument(doc,selectedFile,c4d.SCENEFILTER_OBJECTS,None)  
 
c4d.EventAdd()  

You find the FBX settings defined in the header files of the FBX module in resource\modules\fbx\description and resource\modules\fbx\dialogs. Currently I have no FBX file with takes at hand to test your case.

Best wishes,
Sebastian

Hi Sebastian, when I copy your script and add import c4d etc in a new script, it always appear this console error:KeyError: 'imexporter'. It was pointing at the line  fbximport = op["imexporter"].

On 04/07/2015 at 05:35, xxxxxxxx wrote:

Hi Sebastian,

I just found that, if my fbx file with a take but not name "C4D Animation Take", the 2nd popup window will show up. This can help me to "kill" the 2nd popup("Select Take")window. But I still have to make sure CHECKED the  Animation Start Time and Animation End Time. Because some of my fbx files with repeat pattern keyframes, that make my importing time so long and import over million keyframes in my timeline!!! The file became a huge size!!! So is there any other way that I can cut out the keyframes after the Take when it is in import progress? Just like the same result as I checked the Animation Start Time and Animation End Time.

I am in a ungent stage, hope can get your feedback ASAP.

Many thanks!!!!

Best,

Ben

On 04/07/2015 at 08:29, xxxxxxxx wrote:

Hello,

as said before I don't have a FBX file with takes at had so I can't test your scenario. If you want help you could provide a simple file to reproduce the issue.

Looking at the source code it might not be possible to edit the second popup window, but without a file to test it I can't say anything more.

Best wishes,
Sebastian

On 04/07/2015 at 12:54, xxxxxxxx wrote:

Hello Sebastian,

Yes, I can provide a simple fbx file.
please find the sample file by the link below:

https://www.dropbox.com/s/gd79ohfq3wl7sm4/cam_42_021_tql.rar?dl=0

Thanks,
Ben

On 06/07/2015 at 07:27, xxxxxxxx wrote:

Hi Ben,

I'm afraid there's no way to interact by script with the "Select Take" dialog and check the Animation Start Time and Animation End Time.
Also what version of Cinema do you use?

On 07/07/2015 at 14:53, xxxxxxxx wrote:

Hello, I am using R16. actually I didnot have to interact with the popup window, as long as I can setting the take start time and end time by script when importing fbx, like the script Sebastian wrote above.

Thanks,
Ben

On 08/07/2015 at 01:44, xxxxxxxx wrote:

Hi Ben,

Originally posted by xxxxxxxx

Hello, I am using R16. actually I didnot have to interact with the popup window, as long as I can setting the take start time and end time by script when importing fbx, like the script Sebastian wrote above.

I'm sorry I have not explained it well in my previous post: it's not possible to set the take start time and end time in the "Select Take" dialog by script.
The information shown in this dialog isn't stored in any BaseContainer.

Have you tried again the script Sebastian's posted? If you're using R16 it shouldn't give any error on fbximport = op["imexporter"].
I ran the script and opened the FBX file you provided and it's loading fine.
Here's the script I used:

import c4d
from c4d import plugins
  
def main() :
    # Select a file
    selectedFile = c4d.storage.LoadDialog(type=c4d.FILESELECTTYPE_ANYTHING, title="Choose FBX")
  
    if selectedFile is None:
        return
  
    # Find the FBX importer plugin
    plug = plugins.FindPlugin(1026369, c4d.PLUGINTYPE_SCENELOADER)
    if plug is None:
        return
  
    # Access the settings
    op = {}
    if plug.Message(c4d.MSG_RETRIEVEPRIVATEDATA, op) :
        print op
  
    fbximport = op["imexporter"]
    if fbximport is None:
        return
  
    # Define the settings
    fbximport[c4d.FBXIMPORT_CAMERAS] = False
  
    # Import without dialogs
    c4d.documents.MergeDocument(doc, selectedFile, c4d.SCENEFILTER_OBJECTS|c4d.SCENEFILTER_MATERIALS, None)
  
    c4d.EventAdd()
  
if __name__=='__main__':
    main()
  

On 09/07/2015 at 17:33, xxxxxxxx wrote:

Hi Yannick,

When you are loading the fbx file,have you check the take start time and end time? If not, did it load very slow and have over millions of keyframes in the timeline?

Thanks,
Ben

On 13/07/2015 at 02:44, xxxxxxxx wrote:

Hi Ben,

Originally posted by xxxxxxxx

When you are loading the fbx file,have you check the take start time and end time? If not, did it load very slow and have over millions of keyframes in the timeline?

I tried with the GUI and the script.
When I load the file with the Merge dialog and check the take start and end times it loads quickly.
When I run the script it loads exactly as fast but without showing the take dialog and having to check the start and end times!