ScriptSpot home

Forum topic · General Scripting

connect vertex/knots in a shape with 2 splines

By Ralf Bartsch · 2020-01-30

Description

Hello. Basic question (but i can't find it on the internet)

I have a shape with 2 splines: /sp1v1--sp1v2/ /sp2v1--sp2v2/.

Now i want to connect sp1v2 with sp2v1.
something like this:

select $MyShape
subObjectLevel = 1
splineOps.startConnect (1,2) (2,1)

can someone give me a hit? tnx

Comments (8)
Ralf Bartsch

follow-up question (i have a problem selecting things)


GB1 = Rectangle name:"GB1" Length: 1.0 width: 1.0 steps:0 
GB2 = Rectangle name:"GB2" Length: 1.0 width: 1.0 steps:0 
rotate $GB2 (eulerangles 0 0 45)

convertToSplineShape $GB1
convertToSplineShape $GB2
addAndWeld $GB1 $GB2 0.0
					
select $GB1
max modify mode
subobjectlevel = 3
setSplineSelection $GB1#(1)
splineOps.startUnion $

It works untill the last line.
But "$GB1#(2)","(3 2)", "the-other-spline" gives me errors.

Can you tell me whats wrong

(I have the book "maxscript essentials", but these essential-syntax things are missing..)

tnx.

Reply to Ralf Bartsch
Vojtech Cada
(
	local GB1 = Rectangle prefix:"GB" length:1 width:1 steps:0 isSelected:on
	local GB2 = Rectangle prefix:"GB" length:1 width:1 steps:0 transform:(rotateZMatrix 45)

	startObjectCreation ShapeBooleanObject
	GB1.AppendOperand GB1 GB2 on
	GB1.SetOperationType (GB1.getNumOperands()) #union
	convertToSplineShape GB1
)
miauu

.


(
	spl1 = $Line001
	spl2 = $Line002
	
	--	"create new spline which knots match the spl1knot2 and spl2knot1"
	ss = splineShape()
	addNewSpline ss
	addKnot ss 1 #smooth #curve (getKnotPoint spl1 1 2)
	addKnot ss 1 #smooth #curve (getKnotPoint spl2 1 1)
	updateShape ss
	
	--	"if you want to attach all splines"
	addAndWeld spl1 ss -1 	
	addAndWeld spl1 spl2 -1 
	updateShape spl1
)
Reply to miauu
Ralf Bartsch

yes, tnx a lot Miauu.

my shape is complexer as in the startpost, but i think i can adjust your code for that.

 

cs = color 0 48 192
d=1.0
P=2.0
N =24
Ang = 20.0	-- 5 < Ang < atan (0.5 p/d)
Hgt = 2.0	-- 0.25 < hgt
T = 30.0	-- 0.0 < T < 100.0
CH = 0.15	-- 0.15 < ch < (N*P)/(4.8*Pi) -0.2084*d 

TA = d*tan(Ang)
WR = (N*P)/(2*Pi)
ZT = (0.5*Hgt-0.2)*(1-(T/100))+0.1
	
--R2= If CH>1 then (2.4*CH) else (1.4*Ch + 1)		
-- C20 = circle name:"C20"  Radius:R2 steps:(4*N) 
	
ss =line name:"Th001" pos:[0,0,0] 
  addNewSpline ss
  addKnot ss 1 #corner #curve [-0.25 *P-0.5*TA , WR-0.5*d , 0.5*Hgt-0.1]
  addKnot ss 1 #corner #curve [0.5*TA-0.25 *P , WR+0.5*d , ZT]
  addKnot ss 1 #corner #curve [0.25 *P - 0.5*TA , WR+0.5*d , ZT]
  addKnot ss 1 #corner #curve [ 0.25 *P+0.5*TA , WR-0.5*d , 0.5*Hgt-0.1]
  updateShape ss	
	
	EA = eulerangles 0 0 (-360.0/N)
	rotate ss EA
	
	for i=1 to (N-1) do ( 
		copy ss
		EA = eulerangles 0 0 (-360.0/N)
		rotate ss EA 		)
	
	for i=1 to (N-1) do (
			ss2 = splineShape()
			tharr = $th*  as array
			addNewSpline ss2
			addKnot ss2 1 #corner #curve (getKnotPoint tharr[i] 1 4)
			addKnot ss2 1 #corner #curve (getKnotPoint tharr[i+1] 1 1)
			updateShape ss	)	
			
	(		ss2 = splineShape()
			tharr = $th*  as array
			addNewSpline ss2
			addKnot ss2 1 #corner #curve (getKnotPoint tharr[N] 1 4)
			addKnot ss2 1 #corner #curve (getKnotPoint tharr[1] 1 1)
			updateShape ss	)
			
	for i=0 to (N-2) do (
		tharr = $th*  as array
		addAndWeld $th001 tharr[N-i] 0.0 	
		)
	
	for i=1 to (N) do (
		Sharr = $Shape*  as array
		addAndWeld $th001 Sharr[1] 0.0 	
		)
Reply to Ralf Bartsch
Panteleev Sergey

.

AddAndWeld is a global shape operation. It will weld any end knots that are in tolerance distance from each other. You probably better use splineOps.weld to weld only the selected knots

Reply to Panteleev Sergey
Ralf Bartsch

.

Tnx Jahman.. if i run the script a second time i'm having trouble. Ill try your solution.