Announcement

Collapse
No announcement yet.

Importing assets into Unreal 4.20 using python

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

    Importing assets into Unreal 4.20 using python

    Hello,

    I am trying to use the Python interface to load in a .fbx file in an automated manner, essentially trying to replace the 'File -> Import into Level -> ...' process. Currently I am trying:

    importInfo = unreal.AutomatedAssetImportData()
    importInfo.destination_path = '/Game/Meshes/Building/pythonTest1/'
    importInfo.factory = unreal.FbxSceneImportFactory()
    importInfo.filenames = [fbxFilePath, ] # This is the file path to the .fbx file
    importInfo.level_to_load = 'temp'
    importInfo.group_name = 'tmp'
    fbxScene = unreal.AssetTools.import_assets_automated(importInfo)

    But this throws the error:
    TypeError: descriptor 'import_assets_automated' requires a 'AssetTools' object but received a 'AutomatedAssetImportData'

    The API suggests that it should be passed an AutomatedAssetImportData (https://api.unrealengine.com/INT/Pyt...ssetTools.html) but this doesn't work. Am I missing something or is this a bug?

    Thanks in advance for your help.

    #2
    Hey, that is odd. As you say, the signature for that function says it wants an AutomatedAssetImportData, but the code is expecting something else.

    Fortunately, you can do the same automated import another way. You create an unreal.AssetImportTask(), set it up with the parameters you need, including `automated = True`, then pass the task inside an array in a call to `unreal.AssetToolsHelpers.get_asset_tools().import_asset_tasks(tasks)`.

    For a code example, you can see how our Shotgun integration does it here:

    https://github.com/shotgunsoftware/t...ctions.py#L284

    hope that helps.

    Comment


      #3
      Hello, thank you for your help. I have also tried that but it is also not working as expected, I have tried:

      task = unreal.AssetImportTask()
      task.filename = fbxFilePath
      task.destination_path = '/Game/Meshes/Building/pythonTest1/'
      task.automated = True
      task.save = True
      task.replace_existing = True
      task.options = unreal.FbxSceneImportOptions()
      task.options.set_editor_property('hierarchy_type', unreal.FBXSceneOptionsCreateHierarchyType.FBXSOCHT_CREATE_BLUEPRINT)

      tasks = [task, ]
      unreal.AssetToolsHelpers.get_asset_tools().import_asset_tasks(tasks)
      fbxScene = tasks[0].imported_object_paths[0]

      This runs however it seems to ignore setting the task.options to FbxSceneImportOptions. If I run it with task.automated=False, it brings up the Fbx Import Options dialog box rather than Fbx Scene Import Options and the hierarchy option is not on the Fbx Import Options box.

      If I have understood this correctly, using task.options = unreal.FbxSceneImportOptions() should be the equivalent of taking me through the File -> Import into Level -> ... process, am I missing something here?

      Thanks again.

      Comment


        #4
        Basic ability to select face/s and perform operations on them, such as detaching to create a new mesh, deleting, or flipping their normals. This helps fix import problems where changing the source data is difficult or impossible. Mobdro
        Last edited by Ashton421; 10-22-2018, 12:38 AM.

        Comment


          #5
          you were right the issue was with the drive permission setting, now I have to edit the setting and after changing the access permission I am able to access my hard drive. To get the solution go here https://www.hptechsupportnumbers.com...-disk-problem/

          Comment


            #6
            I can confirm that using task.options = unreal.FbxSceneImportOptions() does not work as expected. It seems to do a standard static mesh import. This would be great to have working in Python.

            Comment


              #7
              you can go to through this link for more information about it <ahref="https://github.com/20tab/UnrealEnginePython/blob/master/Source/UnrealEnginePython/UnrealEnginePython.Build.cs#L10"</a>
              and also visit:<a href="https://samtechnology.org/download-adobe-photoshop-cs6-free-windows/"></a>

              Comment


                #8
                Hi Ro-Su-,

                Do you have any more input on how to rebuild the 'import into level' functionality in python without an UI popping up? I can also confirm that task.options = unreal.FbxSceneImportOptions() does not do what you would expect as it just does a static mesh import without building a blueprint and retaining the scene hierarchy.

                Maybe we are just using it wrong?

                There seems to be no proper example out there and the documentation doesnt help, really to understand how that feature is supposed to be used. I am not an engine programmer, so it is pretty hard to get a grip on that topic.

                Some more help and direction would be much appreciated. Thank you.

                Comment


                  #9
                  Good Morning,

                  This is the way I'm importing assets from Fbx at the moment. But, it doesn't use the 'Import Into Level' feature.
                  https://www.youtube.com/watch?v=SEjOZJ-IHro
                  Hope it still helps

                  I'm currently working to find how to make the 'Import Into Level' work.
                  I'll let you know if I manage to do something useful with it.


                  Have a nice day,
                  Alex
                  Have An Awesome And Productive Day
                  Alex, Youtube

                  Comment


                    #10
                    Originally posted by AlexQuevillon View Post
                    Good Morning,

                    This is the way I'm importing assets from Fbx at the moment. But, it doesn't use the 'Import Into Level' feature.
                    https://www.youtube.com/watch?v=SEjOZJ-IHro
                    Hope it still helps

                    I'm currently working to find how to make the 'Import Into Level' work.
                    I'll let you know if I manage to do something useful with it.


                    Have a nice day,
                    Alex
                    Alex,
                    Thanks for the Video. Interesting stuff.

                    Let me know what you find out with the import into level. Looking forward to your update.

                    Cheers.

                    Comment


                      #11
                      For now, I'm able to call the function with this code:

                      Code:
                      import unreal
                      data = unreal.AutomatedAssetImportData()
                      data.set_editor_property('destination_path', '/Game/MyNewFolder')
                      data.set_editor_property('filenames', ['C:/Assets/SM_ColorCalibrator.FBX'])
                      data.set_editor_property('level_to_load', '/Game/MyNewLevel')
                      data.set_editor_property('replace_existing', True)
                      factory = unreal.FbxSceneImportFactory()
                      data.set_editor_property('factory', factory)
                      unreal.AssetToolsHelpers.get_asset_tools().import_assets_automated(data)

                      But I'm not able to prevent Unreal from showing the pop-up asking for the import settings.
                      It does not seem to have a way to avoid GetFbxSceneImportOptions() from UFbxSceneImportFactory
                      Have An Awesome And Productive Day
                      Alex, Youtube

                      Comment


                        #12
                        After a little bit of research on UDN I found this: https://udn.unrealengine.com/questions/401847/view.html

                        Hi Andy,

                        Normally, I'd suggest using the ImportAssets commandlet as described in this thread. However, it looks like we haven't fully set up the FbxSceneImportFactory class for use through the commandlet. If you're able to make some code changes, you may be able to add that functionality in. You'd need to wrap the creation of the FBX Scene Import Options window in a conditional so that a window isn't created when UFactory::IsAutomatedImport is true, and you may want to implement UFactory::GetImportSettingsParser to parse json containing your settings and apply that to the import since you'll no longer be able to use the dialog. All of this is already working for the normal FbxFactory class, so you could look there to get an idea of how to set things up. It looks like this factory makes use of the ActorFactory as well, so that would need to be adjusted to handle automated imports.

                        Otherwise, there isn't a quick workflow right now for doing batch imports of FBX files to individual blueprints. The closest thing currently supported would be to batch import the FBX files, drop all of the parts of one desired blueprint into the world, and then click Blueprints->Convert Selected Components to Blueprint Class. This will give you a generated blueprint with a component for each of the meshes you had selected, at which point you can safely delete that instance from the level.

                        Best,

                        Cody
                        Have An Awesome And Productive Day
                        Alex, Youtube

                        Comment


                          #13
                          Originally posted by AlexQuevillon View Post
                          For now, I'm able to call the function with this code:

                          Code:
                          import unreal
                          data = unreal.AutomatedAssetImportData()
                          data.set_editor_property('destination_path', '/Game/MyNewFolder')
                          data.set_editor_property('filenames', ['C:/Assets/SM_ColorCalibrator.FBX'])
                          data.set_editor_property('level_to_load', '/Game/MyNewLevel')
                          data.set_editor_property('replace_existing', True)
                          factory = unreal.FbxSceneImportFactory()
                          data.set_editor_property('factory', factory)
                          unreal.AssetToolsHelpers.get_asset_tools().import_assets_automated(data)

                          But I'm not able to prevent Unreal from showing the pop-up asking for the import settings.
                          It does not seem to have a way to avoid GetFbxSceneImportOptions() from UFbxSceneImportFactory
                          That's some progress right there. I tested and can confirm your findings. Unfortunately, when I run the code again, the replace_existing flag doesnt seem to have an effect resulting in duplicated static meshes as well the blue print class.

                          Comment


                            #14
                            Originally posted by AlexQuevillon View Post
                            After a little bit of research on UDN I found this: https://udn.unrealengine.com/questions/401847/view.html
                            Doesnt sound too promising as dropping parts into a blueprint manually will make us lose the scene hierarchy as it was stored in the fbx to be loaded.

                            But thanks for digging into that, Alex.

                            Comment


                              #15
                              If it helps I gave up on this specific problem and just accepted that I had to click through some menus. I also had the same problem with a some other processes I am trying to automate, such as importing JSON files and assigning them for use, there are some menus that at present don't seem possible to automate. I haven't tried 4.21 yet but looking through the release notes I could not see anything Python specific but was just wondering if anyone has tried this stuff in that? I am hoping that at some point Epic will fix all these bugs as using Python is potentially a great feature but at the moment I find it is just too inconsistent to regularly use for automation.

                              Comment

                              Working...
                              X