Knotpoint distance and creating fixed

Hi. I am new to Maxscript.

I'm trying to write a script that can analyze a spline's knots and create a fixed window in it. I have a spline named "Layy" in scene . This is my code and I can't go forward. Anyone can help?

 
			local cc= for gg in 1 to (numsplines $'Layy') collect gg
					K11=getknotpoint $'Layy' cc  1 
					K12=getknotpoint $'Layy' cc  2
					A	=  k11 -k12
					p1 = fixed height:160 width:A.x  Number_of_Panels_Horizontally:1 name:"P1_0[i]" pos:[-a.x/2,-160,0]	
					p2 = fixed height:160 width:A.x  Number_of_Panels_Horizontally:2 name:"P1_0[i]" pos:[-a.x/2,-160,0]	
					p3 = fixed height:160 width:A.x  Number_of_Panels_Horizontally:3 name:"P1_0[i]" pos:[-a.x/2,-160,0]	
					p4 = Print "AB"
-- 			
			for i in 1 to (numsplines $'Layy')  do 
			(
				 case of 
				 (
					(A <= 120): P1
					(A <= 200): p2
					(A <= 280): p3
					(A  >  280): p4
				)
			)
 
<code>
AttachmentSize
ice_screenshot_20171222-162757.png2.85 KB

Comments

Comment viewing options

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

.

.

Nalme's picture

Thank you both, miauu and

Thank you both, miauu and jahman. I will work on it.

jahman's picture

.

Here's an example.
You'll have to find a way to compare float values because 50.001 isn't equal to 50.000 and window will not be placed as a result.

delete objects
 
--  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --
-- Creating Windows
--  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --
 
fn createWindow w h = (
 
	box width:w height:h length:1
 
)
 
w50x150  = createWindow 50 150
w100x150 = createWindow 100 150
w150x150 = createWindow 150 150
 
w50x150.pos  = [-350,0,0]
w100x150.pos = [-250,0,0]
w150x150.pos = [-100,0,0]
 
--  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --
-- Creating Main Rect
--  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --
 
fn addRectShape shp pt w h = (
 
	addnewspline shp
	splineIndex = numSplines shp
 
	addKnot shp splineIndex #corner #line pt
	addKnot shp splineIndex #corner #line (pt + [w,0,0])
	addKnot shp splineIndex #corner #line (pt + [w,0,h])
	addKnot shp splineIndex #corner #line (pt + [0,0,h])
	close shp splineIndex
 
	updateShape shp
 
)
 
mainSpline = splineShape wirecolor:yellow
 
addRectShape mainSpline [0,0,0] 500 400 -- Main rect
addRectShape mainSpline [50,0,50] 50 150 -- Window 50x150
addRectShape mainSpline [125,0,50] 100 150 -- Window 100x150
addRectShape mainSpline [250,0,50] 150 150 -- Window 150x150
 
--  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --
-- Checking spline shape "window" sizes and place appropriate window in it
--  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --
for splineIndex = 2 /* skip first rect */ to numsplines mainSpline do (
 
	_min = [ 1e6, 1e6, 1e6 ]
	_max = [-1e6,-1e6,-1e6 ]
 
	for knotIndex = 1 to numKnots mainSpline splineIndex do (
 
		knot = getKnotPoint mainSpline splineIndex knotIndex
 
		if knot.x < _min.x do _min.x = knot.x
		if knot.y < _min.y do _min.y = knot.y
		if knot.z < _min.z do _min.z = knot.z
		if knot.x > _max.x do _max.x = knot.x
		if knot.y > _max.y do _max.y = knot.y
		if knot.z > _max.z do _max.z = knot.z
 
	)
 
	center = (_min + _max) / 2.0	
	size   = _max - _min
 
	point pos:center centermarker:on cross:off wirecolor:yellow
 
	case of (
 
		(size.x == 50 and size.z == 150) : (
 
			-- create new window or copy existing one
 
			newWindow = instance w50x150
			newWindow.center = center
 
		)
 
		(size.x == 100 and size.z == 150) : (
 
			newWindow = instance w100x150
			newWindow.center = center
 
		)
 
		(size.x == 150 and size.z == 150) : (
 
			newWindow = instance w150x150
			newWindow.center = center
 
		)
 
 
 
	)
 
)
Nalme's picture

Thank you Jahman. That is

Thank you Jahman. That is better than mine. I will use it. But still my code doesnt work. And I dont kmow why.

miauu's picture

.

This row is not correct:

A	=  k11 -k12

it should be:

A	=  k11 - k12

Change it and test your code again.

jahman's picture

..

Are you sure that knot 1 & 2 will always be enough to know window dimensions? What if first spline knot will be upper left and the second one lower left.. etc
I'd rather collect all spline knots to know min/max knot position of particular spline.
Then just copy the corresponding window and place it in spline center

windowObject.center = (splineMinPoint3 + splineMaxPoint3)/2.0

Comment viewing options

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