Importing duplicating fbx models into Maya

Hello,

I’ve wrote a python script to import fbx files into Maya but when trying import the same fbx twice it would not import a duplicate. I worked around this by creating the duplicate fbx as a reference than converted back to a standard mesh. I’m finding I’m getting duplicate materials. Does anyone know an easier way to import duplicate fbx’s or a way to fix duplicate materials from being created. Here is the current code I’m using:

        if not does_fbx_exist_scene:
            # If fbx does not exist within scene then import.
            new_nodes = cmds.file(model_path, absoluteName=False,  i=True)
            print(f"FBX piece imported as: {selected_model_name}")
        # If nothing was added to the scene, import as reference
        else:
            # If fbx does exist within scene then import as ref and use scene namespace as name.
            # Then convert ref to mesh object!
            cmds.file(model_path, mnc=True, reference=True)
            # Make reference part of the scene
            cmds.file(model_path, importReference=True)
            ref_name = cmds.ls(f"{selected_model_name}*", type="transform")[-1]

Thanks

Hi Elfis!
Can’t give you a definitive solution, but maybe this gives you a direction to Look at:
If I remember correctly the Standard Import fbx setting for Import method is “add and update”, which means, if the Importer finds already existing objects in the scene with the same Name, it will try to Update the Animation of These objects with data from the fbx. If there is no animation data for the objects in the fbx, it will do nothing.
You’d need to change that setting to “add” instead of “add and update”. Then it should Import objects, even if there are objects with the same name in the scene.
I think you have to pass Importer options objects to the Import command, or Set the options before importing. It’s been a while since I’ve dealt with fbx, das ist Importer, but I can remember, it wasn’t aß straight forward as just setting a flag. But googling for python fbx Import options should send you on the right track.
hope that helps!

1 Like

I couldn’t finding any options, is this for the FBX SDK? I’m currently using maya cmds. I decided to keep the additional imported fbx converted in to Maya as refs than converted back to objects. Duplicate materials are now removed by methods I added. It all works correctly now. But thanks for your update I appreciate it. :slightly_smiling_face:

Hi. While you your method works from a functional standpoint, shade0625’s answer above is correct and the clean way to deal with it. When you use cmds.file() you should set the options flag to the necessary settings. As he/she suggests, fbx needs to be set to add and not be allowed the option to update. in addition to this, with the options, you are able to simply tell it to only bring in meshes and not materials and not animations etc.

an example from online i pulled quickly that is not the set of options you need, but shows how to set these options is:

# these options are not the ones you need but fbx has a bunch of import options and this is where you could set them
options = "targetTime=3;option=insert;match=string;selected=childrenToo;search=XXX;replace={};".format(prefix)
cmds.file(file_path, i=True, type="Fbx", options=options)

in addition you could use:

import maya.mel as mel
# and then here you could use the ton of mel commands to control the import

those commands can be found here:
Maya FBX Import Help Docs

2 Likes