Request to automate

Request to automate

kczerwonka
Advocate Advocate
1,735 Views
32 Replies
Message 2 of 33

Request to automate

kczerwonka
Advocate
Advocate

I posted this in the Dynamic Blocks forum and did not get any response, so I am re-posting here.

I am looking to automate the following.

 

What I am trying to achieve is the following:

1. I want to input L, W, and D.

2. I want the Dblock  or lisp to find X, Y and Y/2.

 

Please see attached file. The dashed lines are for visual reference only. 

 

To summarize, I would input the length (L) and width (W) of a rectangle. I would then input the circle diameter (D) then the Dblock or lisp would create the rectangle and a staggered grid (array) of circles equally spaced from all edges of the rectangle and from each circle to the adjacent circles.

 

To anyone that could help with this, I would be very grateful.

0 Likes
Accepted solutions (4)
1,736 Views
32 Replies
Replies (32)
Message 21 of 33

leeminardi
Mentor
Mentor

I'm glad you like the program.

 

Is there a minimum for the hole spacing too?  I understand that the maximum is D/2.

lee.minardi
0 Likes
Message 22 of 33

kczerwonka
Advocate
Advocate

It would be great if the user could be prompted to input the minimum hole spacing. and have the program default value be D/2.

Because most times the spacing maximum would be D/2, but sometimes it is required to be less, so I would like to have the option to change the value, if possible.

Thank you.

0 Likes
Message 23 of 33

leeminardi
Mentor
Mentor

Currently the maximum hole spacing is D/2.  There is no minimum.   What is needed is an acceptable range for the hole spacing in addition to a minimum for the side margins and a minimum for the top and bottom margins.

 

I suggest you experiment with the current program and provide me with some example values for L, D, and W that yield unsatisfactory results and what would need to change to make them acceptable.

 

lee.minardi
0 Likes
Message 24 of 33

kczerwonka
Advocate
Advocate

OK.

The hole spacing should be 0.060- (D/2).

The minimum side margins should be 0.200.

The minimum top and bottom margins should also be 0.200.

Please see examples attached.

Thank you very much. 

0 Likes
Message 25 of 33

john.uhden
Mentor
Mentor

@kczerwonka 

You have my permission to automate.

John F. Uhden

0 Likes
Message 26 of 33

john.uhden
Mentor
Mentor

@leeminardi 

I am told that you can actually compute square roots in your head, which is important if you know the X and Y distances to your landing point but need to instantly figure out the hypotenuse.  Hey, they're just vectors, right? 🤔

John F. Uhden

0 Likes
Message 27 of 33

leeminardi
Mentor
Mentor

@john.uhden, while in sailing you only need to think about X and Y, in flying you cannot forget about Z!

lee.minardi
0 Likes
Message 28 of 33

leeminardi
Mentor
Mentor

@kczerwonka 

I've updated the code to consider minimum values for the margins and hole spacing.  Check the code to see where you can edit these minimums.  The program does no error checking of input values but should work if they are reasonable.  The length value is used to calculate the hole spacing based meeting the side margin value and circle diameter.   The number of rows ( the width side of the rectangle) is adjusted to meet or exceed the top and bottom minimum margin value. 

 

 

(defun c:test2 (/ c_doc ms w L D pll pur n_per_row xh s xV i dx dy ptbase n_rows pt Lmin Smin Vmin shift sin60 k)
;  Fills a rectangle of width W, length L, with circle of diameter D
; L. Minardi  revised 5/11/2022  v10 to consider minimum margins
;
; xh = side margins
; xV = top and bottom margins
; s = space between circles  
(setq c_doc (vla-get-activedocument (vlax-get-acad-object)))
(setq ms (vla-get-modelspace c_doc))
(setq w	(getreal "\nEnter rectangle width:  ")
      L	(getreal "nEnter rectangle length:  ")
      D	(getreal "nEnter circle diamter:  ")
)
(setq Lmin 0.2 ) ; minimum side margin
(setq  Smin 0.06) ; minimum circle spacing
(setq  Vmin 0.2) ; minimum top & bottom margin  
(setq pll '(0.0 0.0) ; Lower left rectangle corner
      pur (list L w) ; Upper right corner
)
(command "_rectangle" pll pur "")
(setq n_per_row  (/
		   (- L (* 0.25 D) (* 2. Lmin))
		   (* 1.5 D)))
(setq n_per_row (+ (fix n_per_row) 1))
(cond
  ((< s Smin)
   (progn
     (setq n_per_row (- n_per_row 1))
     (setq s (/	(- L (* D (+ n_per_row 0.5))
	(* 2.0 Lmin))(- n_per_row 0.5))))
  )
  ((> s (/ d 2))
   (progn
     (setq n_per_row (+ n_per_row 1))
     (setq s (/	(- L (* D (+ n_per_row 0.5))
	(* 2.0 Lmin))(- n_per_row 0.5))))
  )
) ;cond
(setq sin60 (sin (/ pi 3)))
(princ "\nHole spacing = ")
(princ s)
(setq n_rows (+	(/ (- W (/ D 2) (* 2. Vmin))
		   (* (+ s D) sin60) ) 1)
      n_rows (fix n_rows)
)
(setq  xv     (/ (- W (* (- n_rows 1) (+ D s) sin60) D) 2))
(setq i	     0
      dx     0
      dy     0
      ptbase (list (+ Lmin (/ D 2.)) (+ xV (/ D 2.)))
)
(repeat	n_rows
  (repeat n_per_row
    (if	(> (rem i 2) 0) ; determine if odd or even row
      (setq shift (/ (+ D s) 2.))
      (setq shift 0.0)
    )
    (setq pt (mapcar '+ ptbase (list (+ dx shift) dy)))
    (vla-addcircle ms (vlax-3d-point pt) (/ D 2.))
    (setq dx (+ dx s D))
  )					; repeat n_per_row 
(setq dx 0
      i	 (+ i 1)
      dy (+ dy (* (+ s D) sin60))
)
)					; repeat n_rows
(princ)
)
lee.minardi
0 Likes
Message 29 of 33

kczerwonka
Advocate
Advocate

Lee,

I tried your code with several different inputs and I was unable to have it create any circles. It only created the rectangles.

I attached the drawing that I tested and it only created the rectangles.

0 Likes
Message 30 of 33

john.uhden
Mentor
Mentor

<ROFLOL>

Well, I did get my M Scow almost flying once.  It was blowing probably 30 and we were on a plane skipping from tip to tip of waves... until the mast broke.  It was such fun.

John F. Uhden

0 Likes
Message 31 of 33

leeminardi
Mentor
Mentor
Accepted solution

I made some last minute format changes to make the code look nicer.  I was too aggressive and should have tested it.  The attached version 10 should work.  I have also corrected the code in my post #28.

lee.minardi
Message 32 of 33

kczerwonka
Advocate
Advocate
Accepted solution

Lee,

Thank you very much! I tested it and it works great! I am very pleased and I cannot thank you enough for the code and all the time and effort it took for you to create this for me.

I could never have done this myself.

I will be using your code very often, and it will definitely save me some time in creating these panels.

I attached a DWG with some tests that I did using various dimension inputs. 

I hastily marked previous replies as solutions, but your code 10 is the real solution.

Thank you.

Kevin  

0 Likes
Message 33 of 33

leeminardi
Mentor
Mentor

You are welcome Kevin.  It was a fun projects with a few interesting challenges.  I'm glad to know it will help you out and that the program will be used.

Lee

lee.minardi