objects for loop

Hi!
Im using

txt = ""
for i in selection do
(
txt += (i.name + " = " + ((i.transform.position) as string) + "\n")
)
f = createfile "C:\\file.txt"
format txt to: f
close f

what id like to get are positions of selected build in same order as below regardless order of selecting.
Could somebody point me to good source for getting into that? or maybe someone has ready solution?

Ty :)

m1 = getNodeByName "Basement"
m2 = getNodeByName "Window Front1"
m3 = getNodeByName "Window Front2"
m4 = getNodeByName "Window Front3"
m5 = getNodeByName "Window Front4"
m6 = getNodeByName "Doors"
m7 = getNodeByName "Wall N"
m8 = getNodeByName "Wall E"
m9 = getNodeByName "Wall S"
m10 = getNodeByName "Wall W"
m11 = getNodeByName "Roof"

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Anubis's picture

I see so Amstia wanted

I see so Amstia wanted custom order - not alphabetically, so if the objects names are hard coded (not relative), just need to define them manual into array. Now i see so even "n.name" can be replaced with loop index (i) to optimize build string part of the code:
txt += (i + " = " + ((n.transform.position) as string) + "\n")

my recent MAXScripts RSS (archive here)

le1setreter's picture

in order to keep your

in order to keep your objects together depending on their names you can create an array with the names only and then sort it:

-- selection, empty array to store object-names only, the txt text:
mySelectOrig = selection as array
selectionNames = #()
txt = ""
 
-- create Array with names only:
for i=1 to mySelectOrig.count do (
    append selectionNames mySelectOrig[i].name
)
 
-- sort array:
sort(selectionNames)
 
 
-- write text line to line:
for i=1 to selectionNames.count do (
    n = getNodeByName selectionNames[i]
    txt += (n.name + " = " + ((n.transform.position) as string) + "\n")
)
 
 
-- save info:
f = createfile "C:\\file.txt"
format txt to: f
close f
Anubis's picture

txt = "" myArray =

txt = ""
myArray = #("Basement","Window Front1", ... )
for i in myArray do (
    n = getNodeByName i
    txt += (n.name + " = " + ((n.transform.position) as string) + "\n")
)
f = createfile "C:\\file.txt"
format txt to: f
close f

my recent MAXScripts RSS (archive here)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.