[Solved] How to get position [x,y,z] of vertex of a Line

Hi,

I'm completely new to Maxscript (and to 3ds max), and I'm trying to do something that sounds very simple but for some reason I cannot find the solution online. Namely, I want to move an object to the position of a selected vertex on a spline. All I'm missing is the script to find the [x,y,z] position of a selected vertex. Can anyone help me out?

Comments

Comment viewing options

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

...

This is the function that you looking for
getKnotPoint shape spline_index_integer knot_index_integer
Easy draw a spline, select it and run this code to get print knot positions

spl = selection[1]
for s = 1 to (numsplines spl) do
(
	for k = 1 to (numknots spl s) do (format "spline_%_knot_%_pos = %\n" s k (getKnotPoint spl s k))
)

See the result in the listener
Also read this topic from MXS Help
http://docs.autodesk.com/3DSMAX/15/ENU/MAXScript-Help/index.html?url=fil...

barigazy

Enoughie's picture

Thank you for the quick

Thank you for the quick response!

This brings me one step closer to what I want, but I'm not sure I'm there yet. So this code basically gives me all the coordinates of vertices in a selected spline (is that right? I'm still reading through the Maxscript help in Autodesk). But what I'm looking for is just the coordinate of the one vertex I have selected in the spline. I then want to put that coordinate in a point3 variable, so I can then position my object on that location.

eg.:

obj.pos = vert_coordinate

Is there a simple way to do this?

barigazy's picture

...

Yup.
If you have shape with one spline and only one knot selected then

--this will create box object on selected knot
spl = selection[1] --store selected spline in variable
Box length:5 width:5 height:5 pos:(getKnotPoint spl 1 (getKnotSelection sp 1))

If your shape contains multiple splines then you need to use for-loop.
All about splines you have in link that I've posted earlier.

barigazy

Enoughie's picture

When I run this script I get

When I run this script I get the following error:

$Line:Line001 @ [6.562747,3.986450,0.000000]
-- Error occurred in anonymous codeblock; filename: ; position: 109; line: 2
--  Frame:
-- Unable to convert: #(2) to type: Integer
OK
barigazy's picture

...

spl = selection[1] --store selected spline in variable
Box length:5 width:5 height:5 pos:(getKnotPoint spl 1 (getKnotSelection sp 1)[1])

barigazy

Enoughie's picture

This is perfect! Thank you.

This is perfect! Thank you.

Comment viewing options

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