Jump to content

Recommended Posts

Posted

I have a requirement in one of my projects to distribute some anchor bolt holes along the sides of an angle frame made from an aluminum extrusion. My parameters for this are as follows:

 

1. Place holes 1" from the outside edge along the perimeter of the frame.

2. The on-center spacing of the holes is not to exceed 18" max.

3. The distance from the corner of the frame is not to be smaller than 4". Otherwise the anchor bolts will be too close to one another in the corners. More on this point shortly.

4. Variables 'a' and 'b' are the only real change. When the users enter the size they need these two variables change based on what they entered.

 

I have come up with a nice snippet of code which handles this no matter what dimensions are required for variables 'a' and 'b'. I loop through the equation a few times, decreasing the on-center spacing by 2" increments until an edge dimension of at least 4" is achieved. NOTE: The oc spacing is decremented in 2" increments because I'd really rather not use things like 17" oc or 15" oc... the shop would of course prefer to work with something like 16" or 18" oc. When this runs, it generally comes up with 18" or 16" depending on the value for the 'a' and 'b' variables. However, it sometimes dips down as low as 12" or 10" o.c....usually though it finds a good pick by the first iteration and lands on either 18" or 16" o.c.

 

There are two main problems with this approach.

 

A). The users hate it because it picks a spacing less than 18" most of the time. They get locked into doing things a certain way and don't like to change. If I could space all the holes at 18" o.c. and always end up with an even distribution across the length of the frame with the distance between the last holes on the ends and the corners always congruent, that would be fine. The users tell me they do it all the time, but when the math meets the road...well you guys probably know the routine. Sometimes they often fudge their results and end up with very large or very small distances from the last hole to the corners. Which is what I'm trying to avoid.

 

B). The real problem with this method is that sometimes a dimension for 'a' or 'b' is chosen that will not work no matter what. The edge distance ends up being smaller than 4" each time through the loop, until it reaches 0" o.c. and of course that produces a division by zero error. For example, if you set 'a' or 'b' to 125" it will crash with a division by zero error. NOTE: the error trapping routines are included with this code to insure you get your original settings back when it does crash.

 

I already have permission from the supervisor to tell the users to go pound sand, because no matter how much they disagree, the math on this will never work such that you can always end up with 18" o.c. and the edge distances will be congruent and no less than 4".

 

I have come up with another method which will choose either 18" or 16" o.c. but it's still being tested. Knowing the talent that is in this forum, I would like to put this challenge before the group and see if there are other methods for doing this, Which I'm sure there will be.

 

I have included the code I'm currently tweaking around with and a drawing template which has the block for the holes and a dimension style which will work well for this.

 

(defun dtr (x)
(* pi (/ x 180.0))
); end function

(defun c:test ()
 (vl-load-com)

 (error)
 (initerr)
 
; -------  SETUP POINTS & VARIABLES  -------
 (setq a 55
   b 45
   afrmtl 4
   holespc 18
   pt1 '(0.0 0.0)
   pt2 (polar pt1 (dtr 0.0) b)
   pt3 (polar pt2 (dtr 270.0) a)
   pt4 (polar pt1 (dtr 270.0) a)
   ctrl1 (polar pt1 (dtr 0.0) (/ b 2.0))
   ctrl2 (polar ctrl1 (dtr 90.0) 2)
   ctrl3 (polar pt1 (dtr 270.0) (/ a 2.0))
   ctrl4 (polar ctrl3 (dtr 180.0) 2)
)
 
 (setvar "cmdecho" 0)
 (setvar "osmode" 0)
 (command "pickbox" 0)
   
; ------- DRAW ANGLE FRAME WITH MITERED CORNERS ---------
 (command "._CLAYER" "Aluminum")
 (command "._RECTANGLE" pt1 pt3)
 (command "._OFFSET" afrmtl (entlast) (polar pt1 (dtr 90.0) 12) "")
 (command "._LINE" pt1 (polar (polar pt1 (dtr 90.0) afrmtl) (dtr 180.0) afrmtl) "")
 (command "._MIRROR" (entlast) "" ctrl1 ctrl2 "")
 (command "._MIRROR" (entlast) "" ctrl3 ctrl4 "")
 (command "._MIRROR" (entlast) "" ctrl1 ctrl2 "")

; PLACE ANCHOR BOLT HOLES ALONG B DIMENSION --------------------------------------------------------------------------------
; DEFAULT TARGET FOR ANCHOR BOLT HOLE SPACING is 18" O.C. MAX --------------------------------------------------------------
 (while (< (/ (- (+ b (* afrmtl 2)) (* (- (fix (+ (/ (+ b (* afrmtl 2)) holespc) 1)) 1) holespc)) 2) 4)
   (setq holespc (- holespc 2)))
 (setq numholes (fix (+ (/ (+ b (* afrmtl 2)) holespc) 1)))
 (setq edgespc (/ (- (+ b (* afrmtl 2)) (* (- numholes 1) holespc)) 2))

 (command "._INSERT" "HOLE" (polar (polar pt1 (dtr 0.0) (- edgespc afrmtl)) (dtr 90.0) (- afrmtl 1)) "" "" "")
 (command "._MIRROR" (entlast) "" ctrl3 ctrl4 "")
 (setq count 1)

 (while (< count numholes)
   (command "._INSERT" "HOLE" (polar (polar pt1 (dtr 0.0) (+ (- edgespc afrmtl) (* count holespc))) (dtr 90.0) (- afrmtl 1)) "" "" "")
   (command "._MIRROR" (entlast) "" ctrl3 ctrl4 "")
   (setq count (+ 1 count))
 ); end while

 (command "._CLAYER" "Dim1")
 (command "._DIMLINEAR"(polar (polar pt1 (dtr 90.0) (- afrmtl 0.5)) (dtr 0.0) (- (+ edgespc holespc) afrmtl))
              (polar (polar pt1 (dtr 90.0) (- afrmtl 0.5)) (dtr 0.0) (- edgespc afrmtl))
              (polar pt1 (dtr 90.0) 14))
 (command "._DIMCONTINUE" (polar (polar pt1 (dtr 90.0) afrmtl) (dtr 180.0) afrmtl) "" "")
 
; PLACE ANCHOR BOLT HOLES ALONG A DIMENSION --------------------------------------------------------------------------------
 (setq holespc 18)
 (command "._CLAYER" "Aluminum")

 (while (< (/ (- (+ a (* afrmtl 2)) (* (- (fix (+ (/ (+ a (* afrmtl 2)) holespc) 1)) 1) holespc)) 2) 4)
   (setq holespc (- holespc 2))
 )

 (setq numholes (fix (+ (/ (+ a (* afrmtl 2)) holespc) 1)))
 (setq edgespc (/ (- (+ a (* afrmtl 2)) (* (- numholes 1) holespc)) 2))

 (command "._INSERT" "HOLE" (polar (polar pt1 (dtr 270.0) (- edgespc afrmtl)) (dtr 180.0) (- afrmtl 1)) "" "" "")
 (command "._MIRROR" (entlast) "" ctrl1 ctrl2 "")
 (setq count 1)
 (while (< count numholes)
   (command "._INSERT" "HOLE" (polar (polar pt1 (dtr 270.0) (+ (- edgespc afrmtl) (* count holespc))) (dtr 180.0) (- afrmtl 1)) "" "" "")
   (command "._MIRROR" (entlast) "" ctrl1 ctrl2 "")
   (setq count (+ 1 count))
 ); end while    

 (command "._CLAYER" "Dim1")
 (command "._DIMLINEAR"(polar (polar pt1 (dtr 90.0) afrmtl) (dtr 180.0) afrmtl) (polar (polar pt1 (dtr 180.0) afrmtl)
           (dtr 270.0) (- edgespc afrmtl)) (polar pt1 (dtr 180.0) 12))
 (command "._DIMCONTINUE" (polar (polar pt1 (dtr 180.0) afrmtl) (dtr 270.0) (- (+ holespc edgespc) afrmtl))"" "")
 
 (reset)
 (princ)
 
); end test function

;--------------------------------------------------------------------------------------------
; ERROR TRAPPING                                                                             
;--------------------------------------------------------------------------------------------
(defun error()
(prompt "\nGlobal Error Trap Loaded")
(princ)
);defun
;;;*==========================================================
(defun initerr ()
 (setq oldlayer (getvar "clayer"))
 (setq oldsnap (getvar "osmode"))
 (setq oldpick (getvar "pickbox"))
 (setq oldblip (getvar "blipmode"))
 (setq temperr *error*)
 (setq *error* trap)
 (princ)
);defun
;;;*===========================================================
(defun trap (errmsg)
 (command nil nil nil)
 (if (not (member errmsg '("console break" "Function Cancelled"))
     )
   (princ (strcat "\nError: " errmsg))
 )                 
 (setvar "clayer" oldlayer)
 (setvar "blipmode" oldblip)
 (setvar "menuecho" 0)
 (setvar "highlight" 1)
 (setvar "osmode" oldsnap)
 (command "pickbox" oldpick)
 (princ "\nError Resetting Enviroment ")
 (terpri)
 (setq *error* temperr)
 (princ)
);defun
;;;*===========================================================
(defun reset ()
 (setq *error* temperr)
 (setvar "clayer" oldlayer)
 (setvar "blipmode" oldblip)
 (setvar "menuecho" 0)
 (setvar "highlight" 1)
 (setvar "osmode" oldsnap)
 (command "pickbox" oldpick)
 (princ)
);defun

test-holes.dwg

Posted

Why not delclare your rtd's at start of code make typing easier a90 = dtr 90 only need 3

Posted (edited)

Hey that's not a bad idea. I recently started leaving the dtr calls for zero off because (dtr 0.0) = 0.0 of course. I put the dtr routine up top because it's called most often. But most of the time I'm calling it with 0, 90, 180 or 270 so that's a really good idea. Thanks.

 

BTW - This snippet has a few more bugs in it than I thought. I'm working the problem from different angles. The trick is to get something which works with any dimension thrown at it, and hope the end users are happy with the results. I hope to nail this one today and will post results.

 

I tried the conversion above and it works fine. In fact, you would only need two of them since a180 would = pi. This will not only make things easier but it should speed execution. The thing is this whole program, about 3,000 lines of code only takes 2-3 seconds to complete so it's not like you could really register the speed increase just with the human eye. Still less typing is worth the change in itself. Learned something new today.

 

Just goes to show you...there's always someone out there more clever than yourself.

 

Thanks BigAl.

Edited by Bill Tillman

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...