How to select specific vertices on a spline (so I can manipulate them) ?

I've got a very simple shape that I want to write an automated script for.

I want to select the two lowest vertices (they will both be on the same height on the z-axis, say maybe 0), and I want to invert that selection so I have all the other vertices and move those up the z-axis a particular amount.

How can I find my two lowest vertices in my spline?

PS - I am a newbie in MaxScripting and am going through AutoDesk's MaxScript Essentials book, but I can't see it in there.

Many thanks.

Comments

Comment viewing options

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

Script is making the splines Unique (need to stay as Instanced)

Hi miauu,

I'm soooo close to using your script in Production, but I've just noticed that it is breaking the Instancing of those splines, and making them unique in the process.

Please can you tell me how alter the code so that when the vertices are moved up or down, the splines haven't been made unique during that process ? (as they play a part in the altering of other objects in the scene, namely ones which use that spline as part of a Sweep Modifier).

Many thanks.

JezUK's picture

Guys, you're the best, I

Guys, you're the best, I cannot thank you both enough.

I feel like scripting will take me years to understand :(

But seeing how it's done is a help - I'm going to try and follow the code and understand it all.

Thanks once again :)

JezUK's picture

Thanks miauu, but when I run

Thanks miauu, but when I run this nothing happens :(

JezUK's picture

I figured out that you're

I figured out that you're assuming that splines have been selected (some comments in your code would have been nice so a newbie like me understands something in this code), but it still doesn't work. It collapses the stack to an editable spline and selects all vertices.

To be honest, not that I know because I am no expert, but surely it's just a case of interrogating the z positions of all vertices and finding the two which are at z=0?

miauu's picture

.

The script works with editable spline objects without any modifiers.
What the script does is to collect the positions of all knots, then it sorts the knots by their Z position, and then the script starts moving all knots except the first 2(the first 2 knots can have different Z position, but they are with lower Z position).
The script convertToSplineShape is added so you can undo the operation.

Check this video:https://drive.google.com/file/d/1fQmttyyY6dAfcnHiaKtcKkFPaXrzwy6h/view?usp=sharing

JezUK's picture

Hi miauu, And thank you so

Hi miauu,

And thank you so much for helping me, unfortunately, it still doesn't do anything for me.

It doesn't move any vertices.

I've tried exactly as you've done in your video and I cannot understand why it is not working.

I copy the script into the MaxScript editor, I Select All. I Evaluate All, and I can tell that the script is being executed but the spline doesn't change at all.

Because I am a beginner and don't understand your code (my novice level), I don't understand the logic / syntax.

But nevertheless, it isn't working for me.

Maybe it's the Units Scale?

My grid is set to 200mm, my Units Scale is Inches, and I see your zOffset is set to 100 (my question there is a 100 what? - maybe that's the problem?).

I'm just guessing here....

miauu's picture

.

zOffset = 100 means that the knots will be moved 100 units. You can set this value to 10000 to see if there is any movement.
Can you provide a scene with single spline, so we can test it(for max2020 or lower version)?

Or, you can use the jahman version to select the knots you want and then to move them manually or with another script.

JezUK's picture

Thank you miauu, you're very

Thank you miauu, you're very kind but I've figured out what I was doing wrong.... :)

(my bad.....I'm sorry).

If I wanted this script to do this for a number of selected splines, please could you tell me how to do that?

I presume it would be in some main loop for all the selected splines?

miauu's picture

.

I am glad that you have solved the problem.
The script already works with all of the selected splines. This line:

for o in selection where classOf o == Line or classOf o == SplineShape do

Means that the script will process every spline from the selected objects. So you can select 5 splines and 5 Teapots and the script will check each of these 10 objects for its class. If the class of the object is a Line or SplineShape, the script will execute the code inside the for loop. Note that spline primitives(circles, rectangles, etc.) are different class than Line and SplineShape. If you have a circle(for example) you have to convert it to Editable Spline.

jahman's picture

.

first we collect all knots positions, spline index and knot index
then we sort them by z coord
then we remove 1st and 2nd from the selection (you wanted invert selection, so we select all and remove these two)
and finally select knots

(
	all_knots = #()
	vsel = #()
 
	for i = 1 to numsplines $ do 
	(
		nk = numKnots $ i
 
		append vsel #{ 1..nk }
 
		for k = 1 to nk do
		(
			pt = getKnotPoint $ i k
 
			append all_knots #( pt, i, k ) -- collect point pos, spline index and knot index
		)		
	)
 
	fn sortbyz a b = if a[1].z < b[1].z then -1 else if a[1].z > b[1].z then 1 else 0
 
	qsort all_knots sortbyz -- sort by z
 
	vsel[ all_knots[1][2] ][ all_knots[1][3] ] = false -- deselect 1st lowest z
	vsel[ all_knots[2][2] ][ all_knots[2][3] ] = false -- deselect 2nd lowest z
 
	for i = 1 to numSplines $ do
	(
		setKnotSelection $ i (vsel[i] as array) keep:true -- apply knot selection without these two 
	)
 
)

Comment viewing options

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