Skip to content

Commit 09308fc

Browse files
committed
add functions for getting and creating dummies
parent all dummies under one root dummy
1 parent 5d8e931 commit 09308fc

File tree

1 file changed

+61
-43
lines changed

1 file changed

+61
-43
lines changed

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

Lines changed: 61 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ macroScript UnityImport category:"Unity" tooltip:"Import an FBX file from a Unit
33
(
44
origObjects = #()
55
currSetName = ""
6+
rootDummyName = "UnityFbxRootDummy"
67

78
persistent global unityFbxFilePathAttr
89
persistent global unityFbxFileNameAttr
@@ -32,7 +33,7 @@ macroScript UnityImport category:"Unity" tooltip:"Import an FBX file from a Unit
3233
);
3334

3435
-- allow multiple files to be selected for import
35-
fn GetMultiOpenFilenames caption:"Open" filename:"" types:"All Files (*.*)|*.*" default:1 =
36+
fn getMultiOpenFilenames caption:"Open" filename:"" types:"All Files (*.*)|*.*" default:1 =
3637
(
3738
local dialog = DotNetObject "System.Windows.Forms.OpenFileDialog"
3839
dialog.multiSelect = true
@@ -51,6 +52,42 @@ macroScript UnityImport category:"Unity" tooltip:"Import an FBX file from a Unit
5152
undefined
5253
)
5354

55+
fn getOrCreateRootDummy = (
56+
unityDummy = getNodeByName (rootDummyName)
57+
if (unityDummy == undefined) do (
58+
unityDummy = Dummy()
59+
unityDummy.name = rootDummyName
60+
unityDummy.boxsize = [1,1,1]
61+
)
62+
unityDummy -- return dummy
63+
)
64+
65+
fn getOrCreateSettingsDummy name = (
66+
unityDummy = getNodeByName (name)
67+
if (unityDummy == undefined) do (
68+
unityDummy = Dummy()
69+
unityDummy.name = name
70+
unityDummy.boxsize = [1,1,1]
71+
)
72+
73+
if not (isProperty unityDummy "filePath") do (
74+
unitySetData = attributes unityData
75+
(
76+
parameters main rollout:params
77+
(
78+
filePath type: #string ui:filep default:""
79+
fileName type: #string ui:filen default:""
80+
)
81+
rollout params "Unity Export Parameters"
82+
(
83+
edittext filep "File Path:" text:filePath readOnly:false
84+
edittext filen "File Name:" text:fileName readOnly:false
85+
)
86+
)
87+
custAttributes.add unityDummy unitySetData #unique
88+
)
89+
unityDummy -- return dummy
90+
)
5491

5592
-- Make sure the FbxImporter plugin is loaded
5693
pluginManager.loadClass FbxImporter
@@ -81,11 +118,12 @@ macroScript UnityImport category:"Unity" tooltip:"Import an FBX file from a Unit
81118
)
82119
)
83120

121+
local unityFbxFilePathAttr = ""
84122
for fbxFileName in fbxFileNames do (
85123
-- Get all objects in scene before importAction
86124
origObjects = objects as array
87125

88-
local unityFbxFilePathAttr = getFilenamePath fbxFileName
126+
unityFbxFilePathAttr = getFilenamePath fbxFileName
89127
local unityFbxFileNameAttr = filenameFromPath fbxFileName
90128
local unityFbxFileName = getFilenameFile fbxFileName
91129

@@ -97,54 +135,34 @@ macroScript UnityImport category:"Unity" tooltip:"Import an FBX file from a Unit
97135

98136
-- check if dummy already exists in scene
99137
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-
)
138+
unityDummy = getOrCreateSettingsDummy currSetName
124139

125140
unityDummy.unityData.filePath = unityFbxFilePathAttr
126141
unityDummy.unityData.fileName = unityFbxFileNameAttr
127142

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-
)
143+
unityRootDummy = getOrCreateRootDummy()
144+
unityDummy.parent = unityRootDummy
145145

146146
callbacks.removeScripts #postImport id:#unityPlugin
147147
)
148+
149+
-- Change Unity project if fbx is from a different Unity project.
150+
-- Get the project based on the folder structure (i.e. folder above Assets)
151+
local head = unityFbxFilePathAttr
152+
head = trimRight head "\\/"
153+
-- Check that we are not at the root directory.
154+
while head != "" and not (pathConfig.isRootPath head) do(
155+
if (pathConfig.stripPathToLeaf head) == "Assets" do (
156+
-- this is a valid Unity project, so set it
157+
unityProject = pathConfig.removePathLeaf head
158+
maxIniFile = (GetMAXIniFile())
159+
setINISetting maxIniFile "Unity" "UnityProject" unityProject
160+
161+
-- in order to break out of loop without calling break (because "break" is slow)
162+
head = ""
163+
)
164+
head = pathConfig.removePathLeaf head
165+
)
148166
)
149167
)
150168
macroScript UnityExport category:"Unity" tooltip:"Export a model to Unity"

0 commit comments

Comments
 (0)