2
2
macroScript UnityImport category: " Unity" tooltip: " Import an FBX file from a Unity project and auto-configure for exporting"
3
3
(
4
4
origObjects = #()
5
+ currSetName = " "
5
6
6
7
persistent global unityFbxFilePathAttr
7
8
persistent global unityFbxFileNameAttr
@@ -10,7 +11,7 @@ macroScript UnityImport category:"Unity" tooltip:"Import an FBX file from a Unit
10
11
global afterImport
11
12
fn afterImport = (
12
13
unityFbxExportSet = #()
13
- currSet = selectionSets[" UnityFbxExportSet " ]
14
+ currSet = selectionSets[currSetName ]
14
15
if not isdeleted currSet and currSet != undefined then (
15
16
unityFbxExportSet = unityFbxExportSet + currSet
16
17
)
@@ -20,7 +21,7 @@ macroScript UnityImport category:"Unity" tooltip:"Import an FBX file from a Unit
20
21
append unityFbxExportSet obj
21
22
)
22
23
)
23
- selectionSets[" UnityFbxExportSet " ] = unityFbxExportSet
24
+ selectionSets[currSetName ] = unityFbxExportSet
24
25
);
25
26
26
27
fn loadUnityFbxImportSettings = (
@@ -79,39 +80,71 @@ macroScript UnityImport category:"Unity" tooltip:"Import an FBX file from a Unit
79
80
unityAskSetUnits = true
80
81
)
81
82
)
82
-
83
- -- reset persistent values, in case import fails
84
- unityFbxFilePathAttr = " "
85
- unityFbxFileNameAttr = " "
86
-
87
- -- Get all objects in scene before importAction
88
- origObjects = objects as array
89
- callbacks.addScript #postImport (" afterImport()" ) id: #unityPlugin
90
-
91
- importFile fbxFileName #noPrompt using: FBXIMP
92
83
93
- unityFbxFilePathAttr = getFilenamePath fbxFileName
94
- unityFbxFileNameAttr = filenameFromPath fbxFileName
95
-
96
- -- Change Unity project if fbx is from a different Unity project.
97
- -- Get the project based on the folder structure (i.e. folder above Assets)
98
- local head = unityFbxFilePathAttr
99
- head = trimRight head " \\ /"
100
- -- Check that we are not at the root directory.
101
- while head != " " and not (pathConfig.isRootPath head) do (
102
- if (pathConfig.stripPathToLeaf head) == " Assets" do (
103
- -- this is a valid Unity project, so set it
104
- unityProject = pathConfig.removePathLeaf head
105
- maxIniFile = (GetMAXIniFile())
106
- setINISetting maxIniFile " Unity" " UnityProject" unityProject
107
-
108
- -- in order to break out of loop without calling break (because "break" is slow)
109
- head = " "
110
- )
111
- head = pathConfig.removePathLeaf head
112
- )
113
-
114
- callbacks.removeScripts #postImport id: #unityPlugin
84
+ for fbxFileName in fbxFileNames do (
85
+ -- Get all objects in scene before importAction
86
+ origObjects = objects as array
87
+
88
+ local unityFbxFilePathAttr = getFilenamePath fbxFileName
89
+ local unityFbxFileNameAttr = filenameFromPath fbxFileName
90
+ local unityFbxFileName = getFilenameFile fbxFileName
91
+
92
+ currSetName = unityFbxFileName + " _UnityExportSet"
93
+
94
+ callbacks.addScript #postImport (" afterImport()" ) id: #unityPlugin
95
+
96
+ importFile fbxFileName #noPrompt using: FBXIMP
97
+
98
+ -- check if dummy already exists in scene
99
+ currSetName = unityFbxFileName + " _UnityExportSet"
100
+ unityDummy = getNodeByName (currSetName)
101
+ if (unityDummy == undefined ) do (
102
+ unityDummy = Dummy()
103
+ unityDummy.name = currSetName
104
+ unityDummy.boxsize = [1 ,1 ,1 ]
105
+ )
106
+
107
+ if not (isProperty unityDummy " filePath" ) do (
108
+ unitySetData = attributes unityData
109
+ (
110
+ parameters main rollout: params
111
+ (
112
+ filePath type: #string ui: filep default: " "
113
+ fileName type: #string ui: filen default: " "
114
+ )
115
+ rollout params " Unity Export Parameters"
116
+ (
117
+ edittext filep " File Path:" text: filePath readOnly: false
118
+ edittext filen " File Name:" text: fileName readOnly: false
119
+ )
120
+ )
121
+
122
+ custAttributes.add unityDummy unitySetData #unique
123
+ )
124
+
125
+ unityDummy.unityData.filePath = unityFbxFilePathAttr
126
+ unityDummy.unityData.fileName = unityFbxFileNameAttr
127
+
128
+ -- Change Unity project if fbx is from a different Unity project.
129
+ -- Get the project based on the folder structure (i.e. folder above Assets)
130
+ local head = unityFbxFilePathAttr
131
+ head = trimRight head " \\ /"
132
+ -- Check that we are not at the root directory.
133
+ while head != " " and not (pathConfig.isRootPath head) do (
134
+ if (pathConfig.stripPathToLeaf head) == " Assets" do (
135
+ -- this is a valid Unity project, so set it
136
+ unityProject = pathConfig.removePathLeaf head
137
+ maxIniFile = (GetMAXIniFile())
138
+ setINISetting maxIniFile " Unity" " UnityProject" unityProject
139
+
140
+ -- in order to break out of loop without calling break (because "break" is slow)
141
+ head = " "
142
+ )
143
+ head = pathConfig.removePathLeaf head
144
+ )
145
+
146
+ callbacks.removeScripts #postImport id: #unityPlugin
147
+ )
115
148
)
116
149
)
117
150
macroScript UnityExport category: " Unity" tooltip: " Export a model to Unity"
0 commit comments