Script to connect aligned vertexes of a spline ?

Script to connect aligned vertexes of a spline ?

Anonymous
Not applicable
1,347 Views
8 Replies
Message 1 of 9

Script to connect aligned vertexes of a spline ?

Anonymous
Not applicable

Hello Guys,

I need a little help with script creation and I thought maybe anyone could help.

 

I want to create a script that's capable of creating multiple splines (or connecting multiple verts of a spline) in a given axis of aligned vertexes.

 

For example, in the image bellow, I need it to close the selected spline to form 3 rectangles. I thought maybe I could make this happen by telling the script to connect the vertexes that are aligned in Y axis in this exemple.

 

And this is what I got so far, I cant tell Maxscript to enter in the sub_object and enter the connect modifier. But I have no clue how to do the rest

 

script spline creation.JPG

 

Could anyone help ?

 

It would be very handy to me and maybe to others too 🙂

0 Likes
1,348 Views
8 Replies
Replies (8)
Message 2 of 9

leeminardi
Mentor
Mentor

Posting a few examples of a before and after spline(s) would make it more clear what you want to do with the script.

lee.minardi
0 Likes
Message 3 of 9

Anonymous
Not applicable

Yeah sure,

So, this is a very simple example of what I'm trying to do :

script spline creation 2.JPG

Connect the aligned vertices in Y axis, in this example, to create multiple rectangles with it.

Since I work with architecture modelling I do this all the time to create the walls bellow a window or a door.

 

Maybe another way to do it could be creating multiple shapes in Y axis to form the rectangles and then weld the vertices later on (but it seems a bit more complicated, idk).

 

0 Likes
Message 4 of 9

Alfred.DeFlaminis
Alumni
Alumni

Hello @Anonymous and welcome to the community,

 

This script is a bit beyond my capabilities, I think the best path forward is for me to move this thread to the programming forum to see if anyone there has some suggestions for you.  I will do so now!  Thanks.

 

Best Regards,

Message 5 of 9

denisT.MaxDoctor
Advisor
Advisor

if you run this function with two selected splines of a splineshape, it will connect them...

 

fn connectTwoSplines sp: = 
(
	if sp == unsupplied do sp = selection[1]
	if iskindof sp SplineShape do
	(
		ss = getsplineselection sp
		if ss.count == 2 and not isclosed sp ss[1] and not isclosed sp ss[2] do
		(
			converttosplineshape sp

			k0 = getknotpoint sp ss[1] 1
			s = 1
			n = numknots sp ss[2]
			k1 = getknotpoint sp ss[2] s
			k2 = getknotpoint sp ss[2] n
			
			setKnotSelection sp ss[1] #(1)
			
			k = addnewspline sp
			if distance k0 k1 < distance k0 k2 then (swap s n) else (k1 = k2)
		
			addknot sp k #corner #line k0
			addknot sp k #corner #line k1

			weldSpline sp 0.0001
			n = numknots sp ss[1]
			setInVec sp ss[1] 1 (getknotpoint sp ss[1] 1)
			setOutVec sp ss[1] n (getknotpoint sp ss[1] n)
			close sp ss[1]
			
			converttosplineshape sp
			setsplineselection sp #(ss[1])
		)
	)
)
/*
connectTwoSplines()
*/

 

but it's not how i would do it...

Message 6 of 9

denisT.MaxDoctor
Advisor
Advisor

Here is a cleaner version. But as I said it's not how it should be done. The solution is very specific and might work in very narrow area:

fn connectTwoSplines sp: = 
(
	if sp == unsupplied do sp = selection[1]
	if iskindof sp SplineShape or iskindof sp Line do
	(
		ss = getsplineselection sp
		if ss.count == 2 do
		(
			s1 = ss[1]
			s2 = ss[2]
			if not isclosed sp s1 and not isclosed sp s2 do
			(
				converttosplineshape sp
				
				s1_0 = getknotpoint sp s1 1
				s1_1 = getknotpoint sp s1 (numknots sp s1)
				
				s2_0 = getknotpoint sp s2 1
				s2_1 = getknotpoint sp s2 (numknots sp s2)
				
				pp = if (distance s1_0 s2_0) > (distance s1_0 s2_1) do swap s2_0 s2_1
				
				i = addnewspline sp
				addknot sp i #corner #line s1_0
				addknot sp i #corner #line s2_0

				k = addnewspline sp
				addknot sp k #corner #line s1_1
				addknot sp k #corner #line s2_1
				
				weldSpline sp 0.0001
				setsplineselection sp #(s1)
				ok
			)
		)
	)
)
/*
connectTwoSplines()
*/

 

Message 7 of 9

Alfred.DeFlaminis
Alumni
Alumni

Hello @Anonymous,

 

Did the incredibly amazing post by @denisT.MaxDoctor help with this issue?  Are you all set now?  Thanks for the information!

Best Regards,

0 Likes
Message 8 of 9

Anonymous
Not applicable
Look, could you help me, please? I wanted a similar script so I would like to do 3 lines that are on the axis if they fudge and
0 Likes
Message 9 of 9

denisT.MaxDoctor
Advisor
Advisor

usually a picture can explain the problem better... draw what you have before and want to have after alignment/welding