ScriptSpot

Forum topic · Scripts Wanted

objects for loop

By Amstia · 2009-11-25

Description

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 (3)

Anubis · 2009-11-30

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")

le1setreter · 2009-11-30

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

txt = "" myArray =

Anubis · 2009-11-29

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