Problems with some splits

Problems with some splits

Anonymous
Not applicable
689 Views
6 Replies
Message 1 of 7

Problems with some splits

Anonymous
Not applicable

Hello again,

 

I'm trying to do some splits, but I can't get it. Maybe you have an idea.

 

Here is the case:

 

Capture.PNG

 

Ui_spinner.PNG

 

I have a box called "base" and another one called "box_1" that follow the base, but with some free spaces called "space" with value 10 mm.

I want that if I change the value of the "splits", the left boxes of the "base" to be split it according to the "splits" spinner values and keep those free spaces.

 

I have a pice of code, too, but it works only with the "Splits" values 0 and 1. After 1 it's a disaster.

Here it is:

 

(

b=200.0 -- The base
space= 10.0 -- space between boxes
s=1.0 -- Splits	

rollout Split "Split"
(
    label lbl1 "Base height:" pos:[10,9] width:86 height:13
	spinner Base "" pos:[96,8] width:56 height:16 range:[0,10000,b] type:#worldUnits   
	label lbl2 "Splits:" pos:[8,33] width:86 height:13
	spinner splitCount "" pos:[94,32] width:56 height:16 range:[0,10000,s] type:#worldUnits   
	button Create "Create" pos:[8,64] width:144 height:48

on Base changed val do (b = val)
on Base entered do (b = Base.value)

on splitCount changed val do (s = val)
on splitCount entered do (s = splitCount.value)
	
on Create pressed do
    (				
function SPlit eMH:0 =
(
	
if eMH == 0 then 
(
print "0"
)
else if eMH > 0 then 
(
print "More than 0"
	
theBase=box length:50 width:50 height:b pos: [0,0,0]
theBase.name="theBase"
	
box_1=box length:50 width:100 height:((b/s)-(space*2)) pos: [-75,0,(space)*(s)]	
box_1.name="Boxes"

for i = 2 to eMH do
(		
nextBox= copy box_1 pos: [-75,0,(i-i)
)

)
)

-----------------------------------------
SPlit eMH:(splitCount.value)
-----------------------------------------
   )--end create	

)

theNewFloater = newRolloutFloater "Sp" 170 150
addRollout Split theNewFloater
)

 


Something is wrong. I have no idea how to do this. I tried so many ways, but I'm stuck.

I would appreciate if you could help me.


Thanks !

 

0 Likes
Accepted solutions (2)
690 Views
6 Replies
Replies (6)
Message 2 of 7

har1sf0x
Advocate
Advocate
Accepted solution

Hello,

 

  I am not sure what do you want to achieve with eMH==0 but you should better change your SPLit function with this:

fn SPLit eMH:0 =
(
	if eMH == 0 then 
	(
		print "0"
	)
	else 
	(
		print "More than 0"
		theBase=box length:50 width:50 height:b pos: [0,0,0] name:"theBase"

		boxHeight = ((b-(2*space)) - eMH*space)/eMH
		prevPos = [-75,0,-boxHeight]
		for i = 1 to eMH do
		(
			obj = box length:50 width:100 height:boxHeight pos:prevPos+[0,0,boxHeight+space] name:uniqueName("Boxes")
			prevPos = obj.pos
		)
	)
)

and you should also change the spinner's slitCount type to #integer.

 

Enjoy,

har1sf0x

 

 

 

Message 3 of 7

Anonymous
Not applicable

Thanks, har1sf0x !

But after I made the changes you specified, when I execute the code, I get this error:

 

Capture.PNG

 

Problem is in this line:

 

obj = box length:50 width:100 height:boxHeight pos:prevPos+[0,0,boxHeight+space] name:uniqueName("Boxes")

I suppose that "pos:prevPos" is the problem. Until there the code is OK.

0 Likes
Message 4 of 7

har1sf0x
Advocate
Advocate
Accepted solution

Hello,

 

  You are right, i forgot the parenthesis:

obj = box length:50 width:100 height:boxHeight pos:(prevPos+[0,0,boxHeight+space]) name:uniqueName("Boxes")

Enjoy,

har1sf0x

 

Message 5 of 7

Anonymous
Not applicable

I made 3 changes and your code works flawless !

 

changes.PNG

 

Thanks, har1sf0x !

 

You are a lifesaver ! Smiley Happy

0 Likes
Message 6 of 7

har1sf0x
Advocate
Advocate

Nice,

 

  I wrote it on my laptop and did not tested it so there were some 'bugs' 😉

 

Enjoy,

har1sf0x

0 Likes
Message 7 of 7

Anonymous
Not applicable

Everything is OK. You helped me alot.


Thanks again, har1sf0x ! Smiley Wink

0 Likes