@@ -113,7 +113,7 @@ PyObject *py_unreal_engine_import_asset(PyObject * self, PyObject * args) {
113113 return PyErr_Format (PyExc_Exception, " no GEditor found" );
114114
115115 // char *filename;
116- PyObject * assetsObject = nullptr ;
116+ PyObject * assetsObject = nullptr ;
117117 char *destination;
118118 PyObject *obj = nullptr ;
119119 if (!PyArg_ParseTuple (args, " Os|O:import_asset" , &assetsObject, &destination, &obj)) {
@@ -166,71 +166,71 @@ PyObject *py_unreal_engine_import_asset(PyObject * self, PyObject * args) {
166166 }
167167
168168
169- TArray<FString> files;
170-
171- if ( PyList_Check ( assetsObject ) ) {
172- // parse the list object
173- int numLines = PyList_Size ( assetsObject );
174-
175-
176- if ( numLines <= 0 )
177- {
178- return PyErr_Format ( PyExc_Exception, " Asset paths is not a valid list" );
179- }
180-
181- for ( int i = 0 ; i < numLines; ++i ) {
182-
183- PyObject * strObj = PyList_GetItem ( assetsObject, i );
184- #if PY_MAJOR_VERSION >= 3
185- char * filename = PyBytes_AS_STRING ( PyUnicode_AsEncodedString ( strObj, " utf-8" , " Error" ) );
186- #else
187- char * filename = PyString_AsString ( PyObject_Str (strObj) );
188- #endif
189- files.Add ( UTF8_TO_TCHAR ( filename ) );
190- }
191- }
192- else if ( PyUnicodeOrString_Check ( assetsObject ) ) {
193- #if PY_MAJOR_VERSION >= 3
194- char * filename = PyBytes_AS_STRING ( PyUnicode_AsEncodedString ( assetsObject, " utf-8" , " Error" ) );
195- #else
196- char * filename = PyString_AsString ( PyObject_Str ( assetsObject ) );
197- #endif
198- files.Add ( UTF8_TO_TCHAR ( filename ) );
199- }
200- else {
201- return PyErr_Format ( PyExc_Exception, " Not a string nor valid list of string" );
202- }
203-
204- FAssetToolsModule& AssetToolsModule = FModuleManager::LoadModuleChecked<FAssetToolsModule>(" AssetTools" );
205- TArray<UObject *> objects = AssetToolsModule.Get ().ImportAssets (files, UTF8_TO_TCHAR (destination), factory, false );
206-
207- if ( objects.Num () == 1 ) {
208-
209- UObject *object = objects[0 ];
210- ue_PyUObject *ret = ue_get_python_wrapper ( object );
211- if ( !ret )
212- return PyErr_Format ( PyExc_Exception, " PyUObject is in invalid state" );
213- Py_INCREF ( ret );
214- return (PyObject *)ret;
215- }
216- else if ( objects.Num () > 1 ) {
217- PyObject *assets_list = PyList_New ( 0 );
218-
219- for ( UObject *object : objects )
220- {
221- ue_PyUObject *ret = ue_get_python_wrapper ( object );
222- if ( !ret )
223- return PyErr_Format ( PyExc_Exception, " PyUObject is in invalid state" );
224- PyList_Append ( assets_list, (PyObject *)ret );
225- }
226-
227- return assets_list;
228-
229- }
230-
231- Py_INCREF (Py_None);
232- return Py_None;
233- }
169+ TArray<FString> files;
170+
171+ if (PyList_Check (assetsObject) ) {
172+ // parse the list object
173+ int numLines = PyList_Size (assetsObject);
174+
175+
176+ if (numLines <= 0 )
177+ {
178+ return PyErr_Format (PyExc_Exception, " Asset paths is not a valid list" );
179+ }
180+
181+ for (int i = 0 ; i < numLines; ++i) {
182+
183+ PyObject * strObj = PyList_GetItem (assetsObject, i);
184+ #if PY_MAJOR_VERSION >= 3
185+ char * filename = PyBytes_AS_STRING (PyUnicode_AsEncodedString (strObj, " utf-8" , " Error" ) );
186+ #else
187+ char * filename = PyString_AsString (PyObject_Str (strObj));
188+ #endif
189+ files.Add (UTF8_TO_TCHAR (filename) );
190+ }
191+ }
192+ else if (PyUnicodeOrString_Check (assetsObject) ) {
193+ #if PY_MAJOR_VERSION >= 3
194+ char * filename = PyBytes_AS_STRING (PyUnicode_AsEncodedString (assetsObject, " utf-8" , " Error" ) );
195+ #else
196+ char * filename = PyString_AsString (PyObject_Str (assetsObject) );
197+ #endif
198+ files.Add (UTF8_TO_TCHAR (filename) );
199+ }
200+ else {
201+ return PyErr_Format (PyExc_Exception, " Not a string nor valid list of string" );
202+ }
203+
204+ FAssetToolsModule& AssetToolsModule = FModuleManager::LoadModuleChecked<FAssetToolsModule>(" AssetTools" );
205+ TArray<UObject *> objects = AssetToolsModule.Get ().ImportAssets (files, UTF8_TO_TCHAR (destination), factory, false );
206+
207+ if (objects.Num () == 1 ) {
208+
209+ UObject *object = objects[0 ];
210+ ue_PyUObject *ret = ue_get_python_wrapper (object);
211+ if (!ret)
212+ return PyErr_Format (PyExc_Exception, " PyUObject is in invalid state" );
213+ Py_INCREF (ret);
214+ return (PyObject *)ret;
215+ }
216+ else if (objects.Num () > 1 ) {
217+ PyObject *assets_list = PyList_New (0 );
218+
219+ for (UObject *object : objects)
220+ {
221+ ue_PyUObject *ret = ue_get_python_wrapper (object);
222+ if (!ret)
223+ return PyErr_Format (PyExc_Exception, " PyUObject is in invalid state" );
224+ PyList_Append (assets_list, (PyObject *)ret);
225+ }
226+
227+ return assets_list;
228+
229+ }
230+
231+ Py_INCREF (Py_None);
232+ return Py_None;
233+ }
234234
235235PyObject *py_unreal_engine_message_dialog_open (PyObject * self, PyObject * args) {
236236
@@ -311,12 +311,14 @@ PyObject *py_unreal_engine_get_assets(PyObject * self, PyObject * args) {
311311 return assets_list;
312312}
313313
314- PyObject *py_unreal_engine_get_assets_by_filter (PyObject * self, PyObject * args) {
314+ PyObject *py_unreal_engine_get_assets_by_filter (PyObject * self, PyObject * args, PyObject *kwargs ) {
315315
316316 PyObject *pyfilter;
317317 PyObject *py_return_asset_data;
318318
319- if (!PyArg_ParseTuple (args, " O|O:get_assets_by_filter" , &pyfilter, &py_return_asset_data)) {
319+ static char *kw_names[] = { " filter" , " return_asset_data" , NULL };
320+
321+ if (!PyArg_ParseTupleAndKeywords (args, kwargs, " O|O:get_assets_by_filter" , kw_names, &pyfilter, &py_return_asset_data)) {
320322 return NULL ;
321323 }
322324
@@ -609,9 +611,9 @@ PyObject *py_unreal_engine_add_component_to_blueprint(PyObject * self, PyObject
609611 PyObject *py_blueprint;
610612 PyObject *py_component;
611613 char *name;
612- char *parentName = nullptr ;
614+ char *parentName = nullptr ;
613615
614- if (!PyArg_ParseTuple (args, " OOs|s:add_component_to_blueprint" , &py_blueprint, &py_component, &name, &parentName )) {
616+ if (!PyArg_ParseTuple (args, " OOs|s:add_component_to_blueprint" , &py_blueprint, &py_component, &name, &parentName)) {
615617 return NULL ;
616618 }
617619
@@ -640,28 +642,28 @@ PyObject *py_unreal_engine_add_component_to_blueprint(PyObject * self, PyObject
640642 return PyErr_Format (PyExc_Exception, " unable to allocate new component" );
641643 }
642644
643- USCS_Node *parentNode = nullptr ;
644- if ( parentName )
645- {
646- FString strParentName = UTF8_TO_TCHAR ( parentName );
647- if ( strParentName.IsEmpty () )
648- {
649- parentNode = bp->SimpleConstructionScript ->GetDefaultSceneRootNode ();
650- }
651- else
652- {
653- parentNode = bp->SimpleConstructionScript ->FindSCSNode ( UTF8_TO_TCHAR ( parentName ) );
654- }
655- }
656- else
657- {
658- parentNode = bp->SimpleConstructionScript ->GetDefaultSceneRootNode ();
659- }
660-
661-
662- if ( parentNode ) {
663- parentNode->AddChildNode ( node );
664- }
645+ USCS_Node *parentNode = nullptr ;
646+ if (parentName)
647+ {
648+ FString strParentName = UTF8_TO_TCHAR (parentName);
649+ if (strParentName.IsEmpty ())
650+ {
651+ parentNode = bp->SimpleConstructionScript ->GetDefaultSceneRootNode ();
652+ }
653+ else
654+ {
655+ parentNode = bp->SimpleConstructionScript ->FindSCSNode (UTF8_TO_TCHAR (parentName) );
656+ }
657+ }
658+ else
659+ {
660+ parentNode = bp->SimpleConstructionScript ->GetDefaultSceneRootNode ();
661+ }
662+
663+
664+ if (parentNode) {
665+ parentNode->AddChildNode (node);
666+ }
665667 else {
666668 bp->SimpleConstructionScript ->AddNode (node);
667669 }
@@ -755,55 +757,55 @@ PyObject *py_unreal_engine_editor_on_asset_post_import(PyObject * self, PyObject
755757 return Py_None;
756758}
757759
758- PyObject *py_unreal_engine_create_material_instance ( PyObject * self, PyObject * args ) {
760+ PyObject *py_unreal_engine_create_material_instance (PyObject * self, PyObject * args) {
759761
760- PyObject *py_material;
761- char *materialPacakgePath = nullptr ;
762- char *materialName = nullptr ;
762+ PyObject *py_material;
763+ char *materialPacakgePath = nullptr ;
764+ char *materialName = nullptr ;
763765
764- if ( !PyArg_ParseTuple ( args, " O|ss:create_material_instance" , &py_material, &materialPacakgePath, &materialName ) ) {
765- return NULL ;
766- }
766+ if (!PyArg_ParseTuple (args, " O|ss:create_material_instance" , &py_material, &materialPacakgePath, &materialName) ) {
767+ return NULL ;
768+ }
767769
768- if ( !ue_is_pyuobject ( py_material ) ) {
769- return PyErr_Format ( PyExc_Exception, " argument is not a UObject" );
770- }
770+ if (!ue_is_pyuobject (py_material) ) {
771+ return PyErr_Format (PyExc_Exception, " argument is not a UObject" );
772+ }
771773
772- ue_PyUObject *py_obj = (ue_PyUObject *)py_material;
773- if ( !py_obj->ue_object ->IsA <UMaterialInterface>() )
774- return PyErr_Format ( PyExc_Exception, " uobject is not a UMaterialInterface" );
775- UMaterialInterface *materialInterface = (UMaterialInterface *)py_obj->ue_object ;
774+ ue_PyUObject *py_obj = (ue_PyUObject *)py_material;
775+ if (!py_obj->ue_object ->IsA <UMaterialInterface>())
776+ return PyErr_Format (PyExc_Exception, " uobject is not a UMaterialInterface" );
777+ UMaterialInterface *materialInterface = (UMaterialInterface *)py_obj->ue_object ;
776778
777- FAssetToolsModule& AssetToolsModule = FModuleManager::LoadModuleChecked<FAssetToolsModule>( " AssetTools" );
779+ FAssetToolsModule& AssetToolsModule = FModuleManager::LoadModuleChecked<FAssetToolsModule>(" AssetTools" );
778780
779- // Determine an appropriate name
780- FString Name;
781- FString PackagePath;
782- FString PackageName;
781+ // Determine an appropriate name
782+ FString Name;
783+ FString PackagePath;
784+ FString PackageName;
783785
784- // Create the factory used to generate the asset
785- UMaterialInstanceConstantFactoryNew* Factory = NewObject<UMaterialInstanceConstantFactoryNew>();
786- Factory->InitialParent = materialInterface;
786+ // Create the factory used to generate the asset
787+ UMaterialInstanceConstantFactoryNew* Factory = NewObject<UMaterialInstanceConstantFactoryNew>();
788+ Factory->InitialParent = materialInterface;
787789
788- if ( materialPacakgePath && materialName )
789- {
790- Name = UTF8_TO_TCHAR ( materialName );
791- PackagePath = UTF8_TO_TCHAR ( materialPacakgePath );
792- }
793- else
794- {
795- AssetToolsModule.Get ().CreateUniqueAssetName ( materialInterface->GetOutermost ()->GetName (), UTF8_TO_TCHAR ( " _inst" ), PackageName, Name );
796- PackagePath = FPackageName::GetLongPackagePath ( PackageName );
797- }
790+ if (materialPacakgePath && materialName)
791+ {
792+ Name = UTF8_TO_TCHAR (materialName);
793+ PackagePath = UTF8_TO_TCHAR (materialPacakgePath);
794+ }
795+ else
796+ {
797+ AssetToolsModule.Get ().CreateUniqueAssetName (materialInterface->GetOutermost ()->GetName (), UTF8_TO_TCHAR (" _inst" ), PackageName, Name);
798+ PackagePath = FPackageName::GetLongPackagePath (PackageName);
799+ }
798800
799- UObject* NewAsset = AssetToolsModule.Get ().CreateAsset ( Name, PackagePath, UMaterialInstanceConstant::StaticClass (), Factory );
801+ UObject* NewAsset = AssetToolsModule.Get ().CreateAsset (Name, PackagePath, UMaterialInstanceConstant::StaticClass (), Factory);
800802
801- ue_PyUObject *ret = ue_get_python_wrapper ( NewAsset );
802- if ( !ret )
803- return PyErr_Format ( PyExc_Exception, " uobject is in invalid state" );
803+ ue_PyUObject *ret = ue_get_python_wrapper (NewAsset);
804+ if (!ret)
805+ return PyErr_Format (PyExc_Exception, " uobject is in invalid state" );
804806
805- Py_INCREF ( ret );
806- return (PyObject *)ret;
807+ Py_INCREF (ret);
808+ return (PyObject *)ret;
807809}
808810
809811#endif
0 commit comments