Skip to content

Commit 5d8e931

Browse files
committed
store filepath/filename in dummy instead of persistant variable
1 parent 512f696 commit 5d8e931

File tree

1 file changed

+67
-34
lines changed

1 file changed

+67
-34
lines changed

Assets/Integrations/Autodesk/max/scripts/UnityFbxForMaxPlugin.ms

Lines changed: 67 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
macroScript UnityImport category:"Unity" tooltip:"Import an FBX file from a Unity project and auto-configure for exporting"
33
(
44
origObjects = #()
5+
currSetName = ""
56

67
persistent global unityFbxFilePathAttr
78
persistent global unityFbxFileNameAttr
@@ -10,7 +11,7 @@ macroScript UnityImport category:"Unity" tooltip:"Import an FBX file from a Unit
1011
global afterImport
1112
fn afterImport = (
1213
unityFbxExportSet = #()
13-
currSet = selectionSets["UnityFbxExportSet"]
14+
currSet = selectionSets[currSetName]
1415
if not isdeleted currSet and currSet != undefined then (
1516
unityFbxExportSet = unityFbxExportSet + currSet
1617
)
@@ -20,7 +21,7 @@ macroScript UnityImport category:"Unity" tooltip:"Import an FBX file from a Unit
2021
append unityFbxExportSet obj
2122
)
2223
)
23-
selectionSets["UnityFbxExportSet"] = unityFbxExportSet
24+
selectionSets[currSetName] = unityFbxExportSet
2425
);
2526

2627
fn loadUnityFbxImportSettings = (
@@ -79,39 +80,71 @@ macroScript UnityImport category:"Unity" tooltip:"Import an FBX file from a Unit
7980
unityAskSetUnits = true
8081
)
8182
)
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
9283

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+
)
115148
)
116149
)
117150
macroScript UnityExport category:"Unity" tooltip:"Export a model to Unity"

0 commit comments

Comments
 (0)