@@ -112,10 +112,11 @@ PyObject *py_unreal_engine_import_asset(PyObject * self, PyObject * args) {
112112 if (!GEditor)
113113 return PyErr_Format (PyExc_Exception, " no GEditor found" );
114114
115- char *filename;
115+ // char *filename;
116+ PyObject * assetsObject = nullptr ;
116117 char *destination;
117118 PyObject *obj = nullptr ;
118- if (!PyArg_ParseTuple (args, " ss |O:import_asset" , &filename , &destination, &obj)) {
119+ if (!PyArg_ParseTuple (args, " Os |O:import_asset" , &assetsObject , &destination, &obj)) {
119120 return NULL ;
120121 }
121122
@@ -157,7 +158,6 @@ PyObject *py_unreal_engine_import_asset(PyObject * self, PyObject * args) {
157158 return PyErr_Format (PyExc_Exception, " invalid uobject" );
158159 }
159160
160-
161161 if (factory_class) {
162162 factory = NewObject<UFactory>(GetTransientPackage (), factory_class);
163163 if (!factory) {
@@ -183,6 +183,73 @@ PyObject *py_unreal_engine_import_asset(PyObject * self, PyObject * args) {
183183
184184 Py_INCREF (Py_None);
185185 return Py_None;
186+ =======
187+ TArray<FString> files;
188+
189+ if ( PyList_Check ( assetsObject ) ) {
190+ // parse the list object
191+ int numLines = PyList_Size ( assetsObject );
192+
193+
194+ if ( numLines <= 0 )
195+ {
196+ return PyErr_Format ( PyExc_Exception, " Asset paths is not a valid list" );
197+ }
198+
199+ for ( int i = 0 ; i < numLines; ++i ) {
200+
201+ PyObject * strObj = PyList_GetItem ( assetsObject, i );
202+ #if PY_MAJOR_VERSION >= 3
203+ char * filename = PyBytes_AS_STRING ( PyUnicode_AsEncodedString ( strObj, " utf-8" , " Error" ) );
204+ #else
205+ char * filename = PyString_AsString ( PyObject_Str (strObj) );
206+ #endif
207+ files.Add ( UTF8_TO_TCHAR ( filename ) );
208+ }
209+ }
210+ else if ( PyUnicodeOrString_Check ( assetsObject ) ) {
211+ #if PY_MAJOR_VERSION >= 3
212+ char * filename = PyBytes_AS_STRING ( PyUnicode_AsEncodedString ( assetsObject, " utf-8" , " Error" ) );
213+ #else
214+ char * filename = PyString_AsString ( PyObject_Str ( assetsObject ) );
215+ #endif
216+ files.Add ( UTF8_TO_TCHAR ( filename ) );
217+ }
218+ else {
219+ return PyErr_Format ( PyExc_Exception, " Not a string nor valid list of string" );
220+ }
221+
222+ FAssetToolsModule& AssetToolsModule = FModuleManager::LoadModuleChecked<FAssetToolsModule>(" AssetTools" );
223+ TArray<UObject *> objects = AssetToolsModule.Get ().ImportAssets (files, UTF8_TO_TCHAR (destination), factory, false );
224+
225+ if ( objects.Num () == 1 ) {
226+
227+ UObject *object = objects[0 ];
228+ ue_PyUObject *ret = ue_get_python_wrapper ( object );
229+ if ( !ret )
230+ return PyErr_Format ( PyExc_Exception, " PyUObject is in invalid state" );
231+ Py_INCREF ( ret );
232+ return (PyObject *)ret;
233+ }
234+ else if ( objects.Num () > 1 ) {
235+ PyObject *assets_list = PyList_New ( 0 );
236+
237+ for ( UObject *object : objects )
238+ {
239+ ue_PyUObject *ret = ue_get_python_wrapper ( object );
240+ if ( !ret )
241+ return PyErr_Format ( PyExc_Exception, " PyUObject is in invalid state" );
242+ PyList_Append ( assets_list, (PyObject *)ret );
243+ }
244+
245+ return assets_list;
246+
247+ }
248+
249+ Py_INCREF (Py_None);
250+ return Py_None;
251+ }
252+ >>>>>>> cb0d7e8d562e31278e51cde1155c0c4e50182823
186253}
187254
188255PyObject *py_unreal_engine_message_dialog_open (PyObject * self, PyObject * args) {
@@ -550,7 +617,9 @@ PyObject *py_unreal_engine_add_component_to_blueprint(PyObject * self, PyObject
550617 PyObject *py_blueprint;
551618 PyObject *py_component;
552619 char *name;
553- if (!PyArg_ParseTuple (args, " OOs:add_component_to_blueprint" , &py_blueprint, &py_component, &name)) {
620+ char *parentName = nullptr ;
621+
622+ if (!PyArg_ParseTuple (args, " OOs|s:add_component_to_blueprint" , &py_blueprint, &py_component, &name, &parentName )) {
554623 return NULL ;
555624 }
556625
@@ -573,16 +642,34 @@ PyObject *py_unreal_engine_add_component_to_blueprint(PyObject * self, PyObject
573642 return PyErr_Format (PyExc_Exception, " uobject is not a UClass" );
574643 UClass *component_class = (UClass *)py_obj->ue_object ;
575644
576-
577645 bp->Modify ();
578646 USCS_Node *node = bp->SimpleConstructionScript ->CreateNode (component_class, UTF8_TO_TCHAR (name));
579647 if (!node) {
580648 return PyErr_Format (PyExc_Exception, " unable to allocate new component" );
581649 }
582- USCS_Node *root = bp->SimpleConstructionScript ->GetDefaultSceneRootNode ();
583- if (root) {
584- root->AddChildNode (node);
585- }
650+
651+ USCS_Node *parentNode = nullptr ;
652+ if ( parentName )
653+ {
654+ FString strParentName = UTF8_TO_TCHAR ( parentName );
655+ if ( strParentName.IsEmpty () )
656+ {
657+ parentNode = bp->SimpleConstructionScript ->GetDefaultSceneRootNode ();
658+ }
659+ else
660+ {
661+ parentNode = bp->SimpleConstructionScript ->FindSCSNode ( UTF8_TO_TCHAR ( parentName ) );
662+ }
663+ }
664+ else
665+ {
666+ parentNode = bp->SimpleConstructionScript ->GetDefaultSceneRootNode ();
667+ }
668+
669+
670+ if ( parentNode ) {
671+ parentNode->AddChildNode ( node );
672+ }
586673 else {
587674 bp->SimpleConstructionScript ->AddNode (node);
588675 }
@@ -673,7 +760,57 @@ PyObject *py_unreal_engine_editor_on_asset_post_import(PyObject * self, PyObject
673760 py_delegate->AddToRoot ();
674761 FEditorDelegates::OnAssetPostImport.AddUObject (py_delegate, &UPythonDelegate::PyFOnAssetPostImport);
675762 Py_INCREF (Py_None);
676- return Py_None;
763+ }
764+
765+ PyObject *py_unreal_engine_create_material_instance ( PyObject * self, PyObject * args ) {
766+
767+ PyObject *py_material;
768+ char *materialPacakgePath = nullptr ;
769+ char *materialName = nullptr ;
770+
771+ if ( !PyArg_ParseTuple ( args, " O|ss:create_material_instance" , &py_material, &materialPacakgePath, &materialName ) ) {
772+ return NULL ;
773+ }
774+
775+ if ( !ue_is_pyuobject ( py_material ) ) {
776+ return PyErr_Format ( PyExc_Exception, " argument is not a UObject" );
777+ }
778+
779+ ue_PyUObject *py_obj = (ue_PyUObject *)py_material;
780+ if ( !py_obj->ue_object ->IsA <UMaterialInterface>() )
781+ return PyErr_Format ( PyExc_Exception, " uobject is not a UMaterialInterface" );
782+ UMaterialInterface *materialInterface = (UMaterialInterface *)py_obj->ue_object ;
783+
784+ FAssetToolsModule& AssetToolsModule = FModuleManager::LoadModuleChecked<FAssetToolsModule>( " AssetTools" );
785+
786+ // Determine an appropriate name
787+ FString Name;
788+ FString PackagePath;
789+ FString PackageName;
790+
791+ // Create the factory used to generate the asset
792+ UMaterialInstanceConstantFactoryNew* Factory = NewObject<UMaterialInstanceConstantFactoryNew>();
793+ Factory->InitialParent = materialInterface;
794+
795+ if ( materialPacakgePath && materialName )
796+ {
797+ Name = UTF8_TO_TCHAR ( materialName );
798+ PackagePath = UTF8_TO_TCHAR ( materialPacakgePath );
799+ }
800+ else
801+ {
802+ AssetToolsModule.Get ().CreateUniqueAssetName ( materialInterface->GetOutermost ()->GetName (), UTF8_TO_TCHAR ( " _inst" ), PackageName, Name );
803+ PackagePath = FPackageName::GetLongPackagePath ( PackageName );
804+ }
805+
806+ UObject* NewAsset = AssetToolsModule.Get ().CreateAsset ( Name, PackagePath, UMaterialInstanceConstant::StaticClass (), Factory );
807+
808+ ue_PyUObject *ret = ue_get_python_wrapper ( NewAsset );
809+ if ( !ret )
810+ return PyErr_Format ( PyExc_Exception, " uobject is in invalid state" );
811+
812+ Py_INCREF ( ret );
813+ return (PyObject *)ret;
677814}
678815
679816#endif
0 commit comments