 Does anyone have this script?

#1

Somehow the last post didn’t go through (atleast not on my end).

Does anyone have a script that gets each objects position relative to 0,0,0 and puts the values in a file?

Nothing fancy, I just need the coordinates relative to 0.

Thanks!

#2

txt = ""
for i in selection do
(
txt += (i.name + " = " + ((coordsys world i.pos) as string) + "
")

)
f = createfile "C:\\TEMP\\file.txt"
format txt to: f
close f

change the path

#3

Thanks! Definately appreciate it!

#4

I also need a script like this but besides this info I also need to know the rotational offset and if possible the material name from a multisub. Any help would be appreciated. Thank you very much for what is currently here, and for any help in advance.

#5

Actually, to just get rotation, isn’t too hard, Just needed to change the line from pos to rotation. Since I wanted them both, I compounded it, but the resulting info seems strange, it doesn’t match the info in max. This is the modified script:

txt = ""
for i in selection do
(
txt += (i.name + " = " + ((coordsys world i.pos) as string) + ((coordsys world i.rotation) as string) + "
")

)
f = createfile "C:\\Users\\peter\\Desktop\\file.txt"
format txt to: f
close f

it results with info like this:

Box03 = [-15.7034,-14.2776,0](quat 0 0 -0.382683 0.92388)
Box04 = [7.6776,-14.0195,0](quat 0 0 -0.707107 0.707107)
Box02 = [28.5424,16.2574,0](quat 0 0 -0.999993 -0.00363246)
Box01 = [-14.0552,20.6396,0](quat 0 0 0 1)

I don’t understand why there are 4 sets of numbers in the rotational results nor why those numbers don’t relate to what max shows in its numeric transform.

#6

It’s because they are quaternion values while 3ds max displays Euler coordinates.
You need to convert them, search the maxScript help for “quatToEuler”.

#7

Did anyone manage to modify this script with quatToEuler embedded? I need to use this script also but cannot get the syntax right to include the quatToEuler conversion. (I’m new to maxscript) The position values all work perfectly.

#8

You want to be careful using the quatToEuler this way. Euler rotations can wind up and a quat can’t. Try this…

eulerToQuat (eulerAngles 0 0 0)
eulerToQuat (eulerAngles 360 0 0)

Both return the same value. If you are only concerned that the orientation of the object is correct then the quat will do but if you wanted to have the actualy values then you will need to get and print the seperate euler angle values.

#9

You should be able to get what you want by using quattoeuler2:

quatToEuler2 <quat>

Returns the same Euler value for the given Quaternion as shown in the Transform Type-In dialog. Available in 3ds Max 2008 and higher. Previously available in the [AVG] Avguard Extensions.
ScreaminBubba try this, modified the code to use the <node>.transform. context. This returns the Rotation values that match those in the Transformation Type-in dialog, this may differ from those in the Max UI values:

txt = ""
for i in selection do
(
txt += (i.name + " = " + ([b](i.transform.position)[/b] as string) +" "+ ([b](quattoeuler2 (i.transform.rotation))[/b] as string) + "
")

)
f = createfile "C:\\Users\\peter\\Desktop\\file.txt"
format txt to: f
close f

-Eric

#10

I tried yours pixel monkey, but it gave me this error:

– Type error: Call needs function or class, got: undefined

#11

… is likely due to tuse of quatToEuler2; that’s only available in 3ds Max 2008/2009; I suspect you’re using an older version of 3ds Max.

You may wish to hit www.maxplugins.de and download the AVG maxscript extension; that’s where quatToEuler2 existed before it was merged into the base 3ds Max package.

That’s the easiest route to fix that problem, anyway #12

I’m using max 2009, but will try the AVG extension.

#13

#14

hm… what do you get when you walk through things step-by-step?
( removed the loop so that you can get step-by-step output in the following )

-- blue text is Listener output
txt = ""
""
i = selection
\$Plane:Plane01 @ [-0.250304,6.708603,-0.003511]
txt += (i.name + " = " + ((i.transform.position) as string) +" "+ ((quattoeuler2 (i.transform.rotation)) as string) + "
")
"Plane01 = [-0.250304,6.7086,-0.00351107] (eulerAngles -1.34033 51.4492 -179.601)
"
f = createfile "c:\	emp\\file.txt"
<File:c:	emp\file.txt>
format txt to: f
OK
close f
OK

#15

It’s barfing on this line:
txt += (i.name + " = " + ((i.transform.position) as string) +" "+ ((quattoeuler2 (i.transform.rotation)) as string) + "
")
[size=1]-- Error occurred in anonymous codeblock

[/size][size=1]-- Frame:

– quattoeuler2: undefined

[/size][size=1]-- Type error: Call needs function or class, got: undefined

[color=white]I’m running Max 2009, not sure why this is undefined.
[/color][/size]

#16

Are you sure it’s not the createfile that’s giving the error? Remember to change the path to one you use and know it exists… for example:

txt = ""
for i in selection do
(
txt += (i.name + " = " + ((i.transform.position) as string) +" "+ ((quattoeuler2 (i.transform.rotation)) as string) + "
")

)
f = createfile "C:\\file.txt"
format txt to: f
close f

#17

The create file section works fine, it is still giving me the problem here:

[size=1]txt += (i.name + " = " + ((i.transform.position) as string) +" "+ ((quattoeuler2 (i.transform.rotation)) as string) + "
")

[/size][size=1]-- Error occurred in anonymous codeblock

[/size][size=1]-- Frame:

– quattoeuler2: undefined

[/size][size=1]-- Runtime error: Attempt to access deleted scene object

[/size]

#18

Hmm, it works now, but I had to change quattoeuler2 to quattoeuler.

#19

I do have another question:

The output format, I eventually have to feed the position and rotation values into an xml file, in a specific format.

Example: (from the maxscript)
NH_Arch01 = [148.44,142.466,-5.88535] (eulerAngles 0 0 -90)

I have to plug the values into this xml document manually:
[size=2]posX[/size][size=2]=[/size]"[size=2]148.44[/size]"[size=2] [/size][size=2]posY[/size][size=2]=[/size]“142.466”[size=2] [/size][size=2]posZ[/size][size=2]=[/size]"-[size=2]5.88535[/size]"[size=2] [/size][size=2]rotX[/size][size=2]=[/size]"[size=2]0[/size]"[size=2] [/size][size=2]rotY[/size][size=2]=[/size]"[size=2]0[/size]"[size=2] [/size][size=2]rotZ[/size][size=2]=[/size]"[size=2]-90[/size]"

Could the script be modified to this format on output?

P.S. Thank you all for the help.

#20

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.