Notifications
Clear all

[Closed] Breaking Selected Spline Knots

Having some problems with the a script that needs to break a spline based on the current selection and then close the resulting two splines. Below is the sample code:

First create a Line shape with one or more subsplines that are closed. Now enter Vertex sub-element mode and select two vertices (knots) in a single sub-spline.

If you run this MAXScript code in the MAXScript listener:

splineOps.startBreak $

The two selected vertices will be split into four. And if you switch to spline sub-object mode and select all splines and run:

splineOps.close $

The resulting two sub-splines now get connected and closed.

I need this to work in the following code:

function breakSplineAndConnect spline = (
	select spline
	max modify mode
        subObjectLevel = 1
	for i = 1 to (numsplines spline) do (
		if isClosed spline i then (
			local verts = getKnotSelection spline  i
			if verts.count != 2 then (
				setKnotSelection spline i (#()) keep:false
			)
		) else (
			setKnotSelection spline i (#()) keep:false
		)
	)
	splineOps.startBreak spline	 --doesn't break the selected verts
	
	subObjectLevel = 3
	max select all
	splineOps.close spline
	
	updateShape  spline
)

breakSplineAndConnect $

I don’t understand why the startbreak() fails inside this function. It’s like the function starts the code to pick points to break… whereas calling the startbreak in the global scope of the listener will just split the vertices.

Even more bizarre is that the break does work in the following edited version:

function breakSpline spline = (
	select spline
	max modify mode
	subObjectLevel = 1
	for i = 1 to (numsplines spline) do (
		if isClosed spline i then (
			local verts = getKnotSelection spline  i
			if verts.count != 2 then (
				setKnotSelection spline i (#()) keep:false
			)
		) else (
			setKnotSelection spline i (#()) keep:false
		)
	)
	
	splineOps.startBreak spline	 --doesn't break the selected verts
        updateShape  spline
)
breakSpline $

In that case, the knots are split. But if you put in the code to close the splits, the spline forgets it was split. I tried adding updateShape() function at different points, but it doesn’t matter.

Any ideas?

2 Replies

Try adding “windows.ProcessPostedMessages()” just after splineOps.StartBreak() and see if it solves the issues.

Other than that you could try with redraws calls. Sometimes they do the work as well.

Thanks a million. windows.ProcessPostedMessages() solved the dilemma.

I had already tried redraw functions as that’s what I suspected. Never used this one though. You never stop learning new things!