-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathnameplates.ms
More file actions
381 lines (348 loc) · 8.33 KB
/
nameplates.ms
File metadata and controls
381 lines (348 loc) · 8.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
struct AbstractNameplate
(
/**
Stores name-reference-correlation
and uses type-corresponding methods to
get/set reference name.
**/
id,
name,
newName,
ref,
fn getNameFromRef=(),
fn assignNameToRef=()
)--end struct
struct ObjectNameplate
(
id = undefined,
name = undefined,
newName = undefined,
ref = undefined,
fn getNameFromRef =
(
name = newName = ref.name
),
fn assignNameToRef =
(
ref.name = newName
)
)--end struct
struct MaterialNameplate
(
id = undefined,
name = undefined,
newName = undefined,
ref = undefined,
fn getNameFromRef =
(
name = newName = ref.name
),
fn assignNameToRef =
(
ref.name = newName
)
)--end struct
struct LayerNameplate
(
id = undefined,
name = undefined,
newName = undefined,
ref = undefined,
fn getNameFromRef =
(
name = newName = ref.name
),
fn assignNameToRef =
(
local layManClosed = false
if (LayerManager.isDialogOpen()) do -- if open, close to make changes committ
(
LayerManager.closeDialog()
layManClosed = true
)--end if
-- remember that layer names have to be unique or renaming is omitted
ref.setName newName
if layManClosed do macros.run "Layers" "LayerManager" -- reopen (there is no .openDialog() so use this)
)
)--end struct
struct AssetNameplate
(
id = undefined,
name = undefined,
newName = undefined,
ref = undefined,
fn getNameFromRef =
(
name = newName = ref
),
fn assignNameToRef =
(
dialogVisible = ATSOps.visible
if not dialogVisible do
ATSOps.visible = True
ATSOps.ClearSelection()
ATSOps.SelectFiles #(name)
try
ATSOps.RetargetSelection newName
catch (
messageBox ("Could not rename asset: " + name) title:"Rename Failed"
)
ATSOps.visible = dialogVisible
)
)--end struct
struct FileNameplate
(
id = undefined,
name = undefined,
newName = undefined,
ref = undefined,
fn getNameFromRef =
(
name = newName = (getFileNameFile ref) + (getFilenameType ref)
),
fn assignNameToRef =
(
HiddenDOSCommand ("rename " + "\"" + ref + "\"" + " " + "\"" + newName + "\"") --quot marks are needed for paths with blank spaces
)
)--end struct
struct AbstractNameplateFactory
(
/**
Use as Singleton, build one instance of this only.
Creates Nameplate-Objects to store name-reference-correlations
and use the corresponding methods to get/set the reference name.
**/
type,
mode,
refs,
nested,
dir,
-- Add helper functions here as needed,
fn collectRefs =
(
fn collectObjectRefs=()
fn collectMaterialRefs=()
fn collectLayerRefs=()
fn collectAssetRefs=()
fn collectFileRefs=()
),
fn buildNameplates=()
)--end struct
struct NameplateFactory
(
type = undefined, -- "objects", "materials", "layers", "assets", "files"
mode = undefined, -- "selection" or "scene"
refs = #(), -- node references
nested = false, -- only for materials mode. if true, get nested materials
dir = "", -- only for files mode. get all files from this folder as refs
fn getNestedLayersRecursive layer arr& = (
appendIfUnique arr layer
local parent = layer.getParent()
if parent != undefined do (
getNestedLayersRecursive parent arr
)
),
fn getNestedMaterialsRecursive theMat arr=
(
/*** Tries to collect all materials that are nested inside a base material recursively.
Supports an arbitrary number of materials that can have nested materials inside them
@param theMat The base material.
@param arr The array that all found materials are appended to.
***/
if theMat != undefined do -- may be undefined e.g. when back material slot of VRay2SidedMtl is empty
(
appendIfUnique arr theMat -- collect this one
case (classof theMat) of -- dig further if there is more to get
(
-- Standard nested materials:
Multimaterial :
(
for m in theMat do
getNestedMaterialsRecursive m arr
)
Blend :
(
getNestedMaterialsRecursive theMat.map1 arr
getNestedMaterialsRecursive theMat.map2 arr
)
Shell_Material :
(
getNestedMaterialsRecursive theMat.originalMaterial arr
getNestedMaterialsRecursive theMat.bakedMaterial arr
)
compositematerial :
(
getNestedMaterialsRecursive theMat.baseMaterial arr
for m in theMat.materiallist where m != undefined do
getNestedMaterialsRecursive m arr
)
Shellac :
(
getNestedMaterialsRecursive theMat.shellacMtl1 arr
getNestedMaterialsRecursive theMat.shellacMtl2 arr
)
TopBottom :
(
getNestedMaterialsRecursive theMat.topMaterial arr
getNestedMaterialsRecursive theMat.bottomMaterial arr
)
DoubleSided :
(
getNestedMaterialsRecursive theMat.material1 arr
getNestedMaterialsRecursive theMat.material2 arr
)
-- VRay nested materials:
VRay2SidedMtl :
(
getNestedMaterialsRecursive theMat.frontMtl arr
getNestedMaterialsRecursive theMat.backMtl arr
)
VRayBlendMtl :
(
getNestedMaterialsRecursive theMat.baseMtl arr
for m in theMat.coatMtl do
getNestedMaterialsRecursive m arr
)
VRayMtlWrapper :
(
getNestedMaterialsRecursive theMat.baseMtl arr
)
VRayOverrideMtl :
(
getNestedMaterialsRecursive theMat.baseMtl arr
getNestedMaterialsRecursive theMat.giMtl arr
getNestedMaterialsRecursive theMat.reflectMtl arr
getNestedMaterialsRecursive theMat.refractMtl arr
getNestedMaterialsRecursive theMat.shadowMtl arr
)
)--end case
)--end if
)--end fn
,
fn collectRefs =
(
refs = #()
fn collectObjectRefs =
(
refs = #()
case mode of
(
"selection": refs = for s in selection collect s
"scene": refs = for o in objects collect o
)--end case
refs -- return
)--end fn
fn collectMaterialRefs =
(
refs = #()
case mode of
(
"selection":
(
for s in selection where s.material != undefined do
(
if nested then -- get all nested materials as well
(
-- Referring to global accessor of script here; maybe move function to this file
getNestedMaterialsRecursive s.material refs
)
else -- only get base materials
(
appendIfUnique refs s.material
)--end else
)--end for
)
"scene":
(
-- get all materials by class
local matClasses = material.classes
for mc in matClasses do
(
local instances = getClassInstances mc
join refs instances
)--end for
)
)--end case
refs -- return
)--end fn
fn collectLayerRefs =
(
refs = #()
case mode of
(
"selection": (
for s in selection do (
if nested then (
getNestedLayersRecursive s.layer refs
)
else (
local layer = LayerManager.getLayerFromName s.layer.name
appendIfUnique refs layer
)
)
)
"scene": (
refs = for i = 0 to (LayerManager.count - 1) collect (LayerManager.getLayer i)
)
)
refs
)
fn collectAssetRefs =
(
refs = #()
-- Inital refresh needed to detect files
ATSOps.Refresh()
ATSOps.GetFiles &refs
refs -- return
)--end fn
fn collectFileRefs =
(
refs = #()
if dir != "" do
refs = sort (getFiles (dir + "\\" + "*.*"))
refs -- return
)--end fn
-- collection happens here using our sub-functions
case type of
(
"objects": refs = collectObjectRefs()
"materials": refs = collectMaterialRefs()
"layers": refs = collectLayerRefs()
"assets": refs = collectAssetRefs()
"files": refs = collectFileRefs()
)--end case
refs -- return
),--end fn
fn buildNameplates =
(
nameplates = #()
id = 0
for ref in refs do
(
np = undefined
id += 1
case type of
(
"objects": np = (ObjectNameplate id:id name:"" newName:"" ref:ref)
"materials": np = (MaterialNameplate id:id name:"" newName:"" ref:ref)
"layers": np = (LayerNameplate id:id name:"" newName:"" ref:ref)
"assets": np = (AssetNameplate id:id name:"" newName:"" ref:ref)
"files": np = (FileNameplate id:id name:"" newName:"" ref:ref)
)--end case
np.getNameFromRef()
append nameplates np
)--end for
nameplates -- return
)--end fn
)--end struct
-- workflow:
-- 1. create factory and specify type and mode
-- 2. let it collect references from scene or selection
-- 3. build nameplates from references and initialize them
-- example:
-- test = NameplateFactory type:"files" mode:"scene" nested:true
-- test.dir = @"C:\Users\Christoph\Desktop\2013 UI ordner"
-- test.collectRefs()
-- nps = test.buildNameplates()
-- print nps
"imported nameplates.ms"