Lisp to position drawers automatically

Lisp to position drawers automatically

paul9ZMBV
Advocate Advocate
926 Views
10 Replies
Message 1 of 11

Lisp to position drawers automatically

paul9ZMBV
Advocate
Advocate

Hi

I have produced a dynamic block so drawers can be adjusted for height and depth (according to the runners)

I would love to be able to position them automatically within a unit according to the height available.

The drawer front are not currently dynamic.

 

So ideally this is what I'm looking for:

 

  1. Select the 1st horizontal line (line goes blue to show its been selected)
  2. Select the 2nd horizontal line (line goes blue to show its been selected)
  3. The height between the above is taken automatically
  4. The user is then asked to input the number of drawers required
  5. The user is then asked to input the set back from the front edge of the carcass
  6. The user is then asked to input the length of the drawer runner (depth of drawer) (although this can also be adjusted by the dynamic block afterwards)
  7. The drawers are then positioned atomically with equal sized draw fronts.

 

The following parameters would have to be adhered to:

 

  • spacing to underside of drawers need to be 27mm (from the bottom, or from the top of the drawer front below it)
  • Drawer height would be 15mm less than drawer front
  • Bottom drawer front to have 5mm gap, subsequent drawers to have 3mm gaps

Its difficult because the bottom drawer is always not as high as the other drawers.

 

Please see sample attached

 

Any help much appreciated

 

 

 

 

 

 

 

0 Likes
Accepted solutions (1)
927 Views
10 Replies
Replies (10)
Message 2 of 11

Sea-Haven
Mentor
Mentor

You posted this request some where else please advise where that was. I answered other post.

0 Likes
Message 3 of 11

paul9ZMBV
Advocate
Advocate

Not aware i posted it anywhere else ?

0 Likes
Message 4 of 11

ВeekeeCZ
Consultant
Consultant

Here is your starting point

Put those variables into excel and do the math.

 

(defun c:drawerins ()

  (if (and (setq pl (getpoint "\nSpecify lower point: ")) ; plx, ply
	   (setq pt (getpoint pl "\nSpecify top point: ")) ; ptx, pty
	   (setq h (distance pl pt))
	   (setq n (getint "\nSpecify numeber of drawers: "))
	   (setq b (getdist "\nSpecify set back from the front edge of the carcass: "))
	   (setq d (getdist "\nSpecify depth of drawer: "))
	   )
(progn

    p0ins  ; insertion point x and y of the lower draw
    p1ins  ; ins point of 1st drawer
    dy
    distance1
    distnace2-low
    distnace2-rest



    )))
 

 

0 Likes
Message 5 of 11

paul9ZMBV
Advocate
Advocate

I get a syntex error when the appload has finished installing the lsp

0 Likes
Message 6 of 11

ВeekeeCZ
Consultant
Consultant

Of course, it just fills the input variables... did you do the calculation? I didn't. I just made a list of variables...

0 Likes
Message 7 of 11

komondormrex
Mentor
Mentor
Accepted solution

hey there,

check the code below. but you have to redefine yours block with one attached, otherwise it got messed.

(defun c:place_drawers (/  interior_h_line_1 redraw_ interior_h_line_2 line_ends min_x max_x min_y max_y unit_interior_depth unit_interior_height
						   front_panel_thickness front_panels_gap front_panel_upper_gap front_panel_lower_gap drawer_front_panel_gap_top drawer_front_panel_gap_bottom
						   front_panel_chamfer drawer_runner_increment drawers_number drawer_set_back drawer_height drawer_runner_calculated drawer_runner drawer_block
						   drawer_front_panel drawer_front_panel_low_chamfer drawer_front_panel_top_chamfer index
					    )
	(redraw)
	(defun get_dyn_property_by_name (dyn_property_name insert_object / dyn_property_found)
		(if (vl-some '(lambda (dyn_property) (= dyn_property_name (vla-get-propertyname (setq dyn_property_found dyn_property))))
					  (vlax-invoke insert_object 'getdynamicblockproperties)
			) dyn_property_found nil
		)
	)
	(setq init_d_values (if (null init_d_values) (setq init_d_values '(3 70)) init_d_values)
		  interior_h_line_1 (car (entsel "\nPick unit interior horizontal 1st line: "))
		  redraw_ (redraw interior_h_line_1 3)
		  interior_h_line_2 (car (entsel "\nPick unit interior horizontal 2nd line: "))
		  redraw_ (redraw interior_h_line_2 3)
		  line_ends (apply 'append (mapcar '(lambda (line) (list (vlax-get (vlax-ename->vla-object line) 'startpoint)
												  		   		 (vlax-get (vlax-ename->vla-object line) 'endpoint)
														   )
											)
											(list interior_h_line_1 interior_h_line_2)
							 	   )
					)
		  min_x (apply 'min (mapcar 'car line_ends))
		  max_x (apply 'max (mapcar 'car line_ends))
		  min_y (apply 'min (mapcar 'cadr line_ends))
		  max_y (apply 'max (mapcar 'cadr line_ends))
		  unit_interior_depth (- max_x min_x)
		  unit_interior_height (- max_y min_y)
		  front_panel_thickness         19
		  front_panels_gap				3
		  front_panel_upper_gap         3
		  front_panel_lower_gap         5
		  drawer_front_panel_gap_top    15
		  drawer_front_panel_gap_bottom 27
		  front_panel_chamfer 			2
		  drawer_runner_increment		20
		  drawers_number (getint (strcat "\nEnter number of drawers <"   (itoa (nth 0 init_d_values)) ">: "))
		  drawers_number (if (null drawers_number)   					 	   (nth 0 init_d_values) drawers_number)
	      drawer_set_back (getint (strcat "\nEnter drawer set back <"    (itoa (nth 1 init_d_values)) ">: "))
		  drawer_set_back (if (null drawer_set_back) 						   (nth 1 init_d_values) drawer_set_back)
		  drawer_height (/ (- unit_interior_height (+ front_panel_lower_gap (* drawers_number (+ front_panels_gap drawer_front_panel_gap_top drawer_front_panel_gap_bottom)))) drawers_number)
		  drawer_runner_calculated (* drawer_runner_increment (fix (/ (- unit_interior_depth drawer_set_back front_panel_thickness drawer_runner_increment) drawer_runner_increment)))
	      drawer_runner (getint (strcat "\nEnter drawer runner <" (itoa drawer_runner_calculated) ">: "))		;	Drawer Runner
		  drawer_runner (if (null drawer_runner) drawer_runner_calculated drawer_runner)

		  drawer_block (vla-insertblock (vla-get-block (vla-get-activelayout (vla-get-activedocument (vlax-get-acad-object))))
									  	(vlax-3d-point (setq 1st_insert_point (list (- max_x drawer_set_back front_panel_thickness) (+ min_y front_panel_lower_gap drawer_front_panel_gap_bottom))))
									  	"Dynamic Drawer Side"
									  	1 1 1 0
					  )
		  drawer_front_panel (vla-addlightweightpolyline (vla-get-block (vla-get-activelayout (vla-get-activedocument (vlax-get-acad-object))))
														 (vlax-safearray-fill (vlax-make-safearray vlax-vbdouble (cons 0 7))
																			  (list (- max_x drawer_set_back) (+ min_y front_panel_lower_gap)
																					(- max_x drawer_set_back) (+ min_y front_panel_lower_gap drawer_front_panel_gap_bottom drawer_height drawer_front_panel_gap_top)
																					(- max_x drawer_set_back front_panel_thickness) (+ min_y front_panel_lower_gap drawer_front_panel_gap_bottom drawer_height drawer_front_panel_gap_top)
																					(- max_x drawer_set_back front_panel_thickness) (+ min_y front_panel_lower_gap)
																			  )
														 )
							 )
		  drawer_front_panel_low_chamfer (vla-addlightweightpolyline (vla-get-block (vla-get-activelayout (vla-get-activedocument (vlax-get-acad-object))))
												 					 (vlax-safearray-fill (vlax-make-safearray vlax-vbdouble (cons 0 3))
												 										  (list (- max_x drawer_set_back) (+ (+ min_y front_panel_lower_gap) front_panel_chamfer)
												 												(- max_x drawer_set_back front_panel_thickness) (+ (+ min_y front_panel_lower_gap) front_panel_chamfer)
												 										  )
												 					 )
							 )
		  drawer_front_panel_top_chamfer (vla-addlightweightpolyline (vla-get-block (vla-get-activelayout (vla-get-activedocument (vlax-get-acad-object))))
												 					 (vlax-safearray-fill (vlax-make-safearray vlax-vbdouble (cons 0 3))
												 										  (list (- max_x drawer_set_back) (- (+ min_y front_panel_lower_gap drawer_front_panel_gap_bottom drawer_height drawer_front_panel_gap_top) front_panel_chamfer)
												 												(- max_x drawer_set_back front_panel_thickness) (- (+ min_y front_panel_lower_gap drawer_front_panel_gap_bottom drawer_height drawer_front_panel_gap_top) front_panel_chamfer)
												 										  )
												 					 )
							 )
		  index 0
	)
	(vlax-put drawer_front_panel 'closed 1)
	(vlax-put (get_dyn_property_by_name "Height" drawer_block) 'value drawer_height)
	(vlax-put (get_dyn_property_by_name "Runner" drawer_block) 'value (float drawer_runner))
	(repeat (1- drawers_number)
		(foreach object (list drawer_block drawer_front_panel drawer_front_panel_low_chamfer drawer_front_panel_top_chamfer)
			(vla-move (vla-copy object)
					  (vlax-3d-point 1st_insert_point)
					  (vlax-3d-point (list (car 1st_insert_point) (+ (cadr 1st_insert_point) (* (1+ index) (+ drawer_front_panel_gap_bottom drawer_height front_panels_gap drawer_front_panel_gap_top)))))
			)
		)
		(setq index (1+ index))
	)
	(setq init_d_values (list drawers_number drawer_set_back))
	(redraw interior_h_line_1 4)
	(redraw interior_h_line_2 4)
	(princ)
)

 

0 Likes
Message 8 of 11

paul9ZMBV
Advocate
Advocate

Thanks

0 Likes
Message 9 of 11

paul9ZMBV
Advocate
Advocate

This is amazing

0 Likes
Message 10 of 11

paul9ZMBV
Advocate
Advocate

Hi Komondormrex

 

Your help with this is greatly appreciated,

 

As the icing on the cake, another lisp would be to do another drawer option where there are no drawer fronts, the drawers are just placed in the unit with a specified gap between them.

 

Please see attached and example, i have created a new block as its slightly different from the last.

 

There would be a user input to specify the gap between them (40mm in example)

 

as well as the quantity of drawers, set back and drawer length user input

 

Thanks again.

 

 
0 Likes
Message 11 of 11

daniel_cadext
Advisor
Advisor

I used to do this; I stored all the parameters in SQLite, accounted for drawer thickness, bumper pads, drilling info and everything

If your using hardware like Blum, they have an app that will export to AutoCAD, does all the for you

Python for AutoCAD, Python wrappers for ARX https://github.com/CEXT-Dan/PyRx
0 Likes