How to get slot name?

Hi,
I am currently importing fbx assets without the materials. Using : unreal.StaticMaterial — Unreal Python 5.1 (Experimental) documentation as a reference, I would like to be able to get:

  • imported_material_slot_name
  • material_slot_name

I’m just unsure of where to go once I get a static mesh. My snippet only works in some cases where I imported the materials with the fbx.



import unreal

@unreal.uclass()
class MyEditorUtility(unreal.GlobalEditorUtilityBase):
    pass

editor_util = MyEditorUtility()
editor_util.get_selected_assets()

for item in editor_util.get_selected_assets():
    materialSlot=]
    slotCount=10 # this is arbitrary, I don't know how to get total slots on a static mesh.
    for i in range(slotCount):
        try:
            print 'index: %s slotname: %s' % (i, item.get_material(i).get_name())
            materialSlot.append(item.get_material(i).get_name())
        except:
            break
editor_util.select_nothing



Hi @flatKAT ,

I believe what I was doing in a similar situation was to call get_material of the static mesh in a while loop as long as the get_material() returned a material (i.e. not None). This way I was counting the material slots until get_material ()returned None in which case I knew there are no more material slots.

I am not sure if my approach works with fbx that were imported without materials, though.

Out of interest: Could you share the snippet of how you import an fbx without material?

Thank you.

-T

Hi Totila_,

I’ve given up on UE python for now. If you look at AlexQuevillon posts and youtube channel, you will find a snippet to disable the option of importing materials,

To import a mesh without materials you would need to set the import task to not false:



def _generate_fbx_import_task(importFilePath, destination_path, replace_existing=True, importFileName=None,                              
automated=True, save=True, materials=False):    

task =ue.AssetImportTask()    
task.filename = importFilePath    
task.destination_path = os.path.dirname(destination_path)    
task.destination_name = importFileName      
task.replace_existing = replace_existing    
task.automated = automated    
task.save = save      

task.options = ue.FbxImportUI()      
task.options.import_materials = False      
task.options.import_mesh = mesh    
if mesh:
    task.options.mesh_type_to_import = ue.FBXImportType.FBXIT_STATIC_MESH      
return task


Thanks @Adam.Kelsey

FYI:
I am using the FbxSceneImportFactory to import an FBX into level and I was wondering if I could disable material import for this approach as well as you showed with yours.

From the docs it looks like it still uses AssetImportTask. So it should work the same, I haven’t explored FbxSceneImportFactory yet though.

https://api.unrealengine.com/INT/Pyt…eimportfactory