Get vertices position from Line object and format the output string

Greetings,

I'm new to max scripting and I'm stuck at getting Line vertices positions, formatting the output and writing it to user properties of that object.
Here's the formatting I'm willing to have: x:"1.0" y:"1.0" z:"1.0" and It should be written to object's user properties (of course with real coords and not just 1.0)

And if possible, my Line is always consisted of two vertices, Is it possible to write left vertex position and right vertex position formatted strings separately?

Here's my approach to write into object's user properties:

for id = 1 to selection.count do
(
    selected_object = selection[id]
    Lcoords = --somehow add the formatted data here
    Rcoords = --somehow add the formatted data here
    setUserProp selected_object "Left Coords" Lcoords
    setUserProp selected_object "Right Coords" Lcoords
)

It is important to keep the formatting otherwise converting tool won't recognise the data and so will the engine.

Cheers

Comments

Comment viewing options

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

.

(
	selObjsArr = selection as array
	for o in selObjsArr where (classOf o == line or classOf o == splineShape) do
	(
		leftCoords = getKnotPoint o 1 1
		coordsToWrite = "x:\"" + (leftCoords.x as string) + "\" " + "y:\"" + (leftCoords.y as string) + "\" " + "z:\"" + (leftCoords.z as string) + "\""
		setUserProp o "Left Coords" coordsToWrite
		leftCoords = getKnotPoint o 1 2
		coordsToWrite = "x:\"" + (leftCoords.x as string) + "\" " + "y:\"" + (leftCoords.y as string) + "\" " + "z:\"" + (leftCoords.z as string) + "\""
		setUserProp o "Right Coords" coordsToWrite
	)
)

Comment viewing options

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