Download

FBX Import Automation - Auto Blueprint asset, not combined ** SceneImportFactory **

First of all, i am a hacky coder new to C++ and to the UE4 library. I am trying to import thousands of assets as blueprints. I don’t want a combined static mesh and I don’t want to hit okay every time. The USceneImportFactory is amazing! It creates a blueprint with all the static meshes oriented properly under a root and creates a sub folder for the static meshes but it requires you to press OK on a UI. Where is this menu outside of code? I’ve never seen it. I’m not sure why it isn’t easier to just skip the UI and go with these settings. I have tried two methods and they’re both really close but still not exactly what I want. I think it all comes down to
HierarchyType = FBXSOCHT_CreateLevelActors; but I don’t know how to get at that property.
I’ve also tried UE4Editor-Cmd.exe with a .bat file but I can’t find the HierarchyType

here’s the c++

// ----

#include “MassImporter.h”
#include “AssetToolsModule.h”
#include “FileHelpers.h” // FEditorFileUtils
#include “fbximporter.h”
#include “Factories/FbxFactory.h”
#include “Factories/fbxSceneImportFactory.h”
#include “Commandlets/ImportAssetsCommandlet.h”
#include “IAssetTools.h”
#include “Editor.h”

void FMassImporter::MassImporterRun()
{
FAssetToolsModule& AssetToolsModule = FModuleManager::Get().LoadModuleChecked<FAssetToolsModule>(“AssetTools”);
TArray<FString> Files;
// this will eventually be read rom a data file
Files.Add(TEXT(“C:/FBXs/Interior/Sign_1.fbx”));
Files.Add(TEXT(“C:/FBXs/Backroom/Water_Heater_1.fbx”));

FString RootDestinationPath = “/Game/Assets/”;
TArray<TPair<FString, FString>> FilesAndDestinations;
FString OutDir;

// This is a way I found to get the factories
// I’m sure there is a better way
USceneImportFactory SceneFactory = nullptr;
for (UClass
Class : TObjectRange<UClass>())
{
if (Class->IsChildOf<USceneImportFactory>())
{
USceneImportFactory* TestFactory = Class->GetDefaultObject<USceneImportFactory>();
if (TestFactory->FactoryCanImport(Files[0]))
{
/// Pick the first one for now
SceneFactory = TestFactory;
break;
}
}
}

// this is the really hacky part
for (int i = 0; i < Files.Num(); i++)
{
FString PathPart;
FString FilenamePart;
FString ExtensionPart;
FPaths::Split(Files*, PathPart, FilenamePart, ExtensionPart);
OutDir = PathPart.Replace(TEXT(“C:/FBXs/”), *RootDestinationPath);

FilesAndDestinations.Emplace(Files*, OutDir);

UAutomatedAssetImportData* newdata = NewObject<UAutomatedAssetImportData>();
newdata->bReplaceExisting = true;
newdata->DestinationPath = OutDir;
TArray<FString> FS;
FS.Add(Files*);
newdata->Filenames = FS;

newdata->Factory = SceneFactory;
//newdata->Factory = fFactory;
//newdata->Factory = FbxSceneFactory;

AssetToolsModule.Get().ImportAssetsAutomated(newdata);
}

}

// ----

— Or Command Line —

This one is good but has to be generated to get the right output based on the fbx path

— ImportFBX.bat —

@eCHo off

set UE4=“C:\Program Files\Epic Games\UE_4.19\Engine\Binaries\Win64\UE4Editor-Cmd.exe”
set project=“F:\UE4\PluginMaker_02_001\PluginMaker_02_001.uproject”
set json=“C:\Users\MyName\Desktop\ImportSettings.json”

:: Works but only does one file and doesn’t make a blueprint
::%UE4% %project% -run=ImportAssets -source=%fbx% -dest=/Game/TEST/ -importSettings="" -AllowCommandletRendering -nosourcecontrol -replaceexisting

:: WORKS
%UE4% %project% -run=ImportAssets -importSettings=%json% -AllowCommandletRendering -nosourcecontrol -replaceexisting > “C:\Users\MyName\Desktop\LOG.txt”

— ImportSettings.json —

{
“ImportGroups”:
{
“FileNames”:
“C:/FBXs/Interior/Sign_1.fbx”,
],
“bReplaceExisting”: “true”,
“DestinationPath”: “/Game/TEST/”,
“FactoryName”: “FbxFactory”,
“ImportSettings”: {
“bImportMesh”: 1,
“bConvertSceneUnit”: 1,
“bConvertScene”: 1,
“bCombineMeshes”: 1,
“bImportTextures”: 1,
“bImportMaterials”: 1,
“AnimSequenceImportData”: {},
“SkeletalMeshImportData”: {},
“TextureImportData”: {},
“StaticMeshImportData”: {
“bRemoveDegenerates”: 1,
“bAutoGenerateCollision”: 1
}
}
}
]
}

In the ImportSettings, make sure the slashes in the filename are forward slashes
and make sure to end each line with a comma

I know there is a solution but I can’t find any documentation.

– UPDATE — But still not complete

Okay, I figured out how to do my own import thus getting rid of AssetToolsModule.Get().ImportAssetsAutomated(newdata);
still have the confirm window

#include “MassImporter.h”
#include “AssetToolsModule.h”
#include “FileHelpers.h” // FEditorFileUtils
#include “fbximporter.h”
#include “Factories/FbxFactory.h”
#include “Factories/fbxSceneImportFactory.h”
#include “ObjectTools.h”
#include “Commandlets/ImportAssetsCommandlet.h”
#include “IAssetTools.h”
#include “Editor.h”

void FMassImporter::MassImporterRun()
{
FAssetToolsModule& AssetToolsModule = FModuleManager::Get().LoadModuleChecked<FAssetToolsModule>(“AssetTools”);
TArray<FString> Files;
Files.Add(TEXT(“C:/FBXs/Interior/Sign_1.fbx”));
Files.Add(TEXT(“C:/FBXs/Backroom/Water_Heater_1.fbx”));

UFbxSceneImportFactory FbxSceneFactory = nullptr;
for (UClass
Class : TObjectRange<UClass>())
{
if (Class->IsChildOf<UFbxSceneImportFactory>())
{
UFbxSceneImportFactory* TestFactory = Class->GetDefaultObject<UFbxSceneImportFactory>();
if (TestFactory->FactoryCanImport(Files[0]))
{
/// Pick the first one for now
FbxSceneFactory = TestFactory;
break;
}
}
}

FString RootDestinationPath = “/Game/Assets/”;
TArray<TPair<FString, FString>> FilesAndDestinations;
FString OutDir;

for (int i = 0; i < Files.Num(); i++)
{
FString PathPart;
FString FilenamePart;
FString ExtensionPart;
FPaths::Split(Files*, PathPart, FilenamePart, ExtensionPart);
OutDir = PathPart.Replace(TEXT(“C:/FBXs/”), *RootDestinationPath);

FilesAndDestinations.Emplace(Files*, OutDir);

UAutomatedAssetImportData* newdata = NewObject<UAutomatedAssetImportData>();
newdata->bReplaceExisting = true;
newdata->DestinationPath = OutDir;
TArray<FString> FS;
FS.Add(Files*);
newdata->Filenames = FS;

//FAssetImportParams

FbxSceneFactory->SetAutomatedAssetImportData(newdata);

UClass* ImportAssetType = FbxSceneFactory->ResolveSupportedClass();
bool bImportWasCancelled;
FString Name = ObjectTools::SanitizeObjectName(FPaths::GetBaseFilename(Files*));
FString PackageName = FPaths::Combine(*OutDir, Name);
const FString QualifiedName = PackageName + TEXT(".") + Name;
UPackage
Pkg = CreatePackage(nullptr, PackageName);
UObject
Result = FbxSceneFactory->ImportObject(ImportAssetType, Pkg, FName(*Name), RF_Public | RF_Standalone | RF_Transactional, Files[0], nullptr, bImportWasCancelled);

FbxSceneFactory->SetAutomatedAssetImportData(nullptr);

//AssetToolsModule.Get().ImportAssetsAutomated(newdata);
}
}

– UPDATE —

Found this window. Still can’t get it automated though.
https://docs.unrealengine.com/en-us/Engine/Content/FBX/FullScene