Place drill holes evenly between two points

Place drill holes evenly between two points

Anonymous
Not applicable
2,307 Views
9 Replies
Message 1 of 10

Place drill holes evenly between two points

Anonymous
Not applicable

Thank in advance for any help on this topic.  I would love to learn how to write LISP routines like you guys do, you are AMAZING!

 

I'm a CNC programmer and I program ACM panels to run through a software that converts them to G code.  What I need to do is place drill holes spaced evenly between my First and Last drill hole.  These drill holes cannot be more than 16" O.C.  So what I do know is:  Draw a line, dimension the line, divide by 16, round up, divide the line by this number, and copy my first hole to the nodes created by the division.

 

My hope is that I can automate this so I can pick the center point of the first hole and the center point of the second hole than everything else is automated.  I have to have the holes on a specific layer so when I import the drawing into the CNC software it will recognize them as holes and use the right tool to cut them.  I also can't have them as blocks or grouped together.  

 

Again thanks for any and all help.

 

Michael

 

Note: I was going to do a screencast but either Screencast doesn't like my PC or doesn't like AutoCAD 19....

0 Likes
Accepted solutions (1)
2,308 Views
9 Replies
Replies (9)
Message 2 of 10

Anonymous
Not applicable

Would it be this ? @Anonymous

(defun c:test ()
  (setq p1 (getpoint "\nPoint 1: ")
	p2 (getpoint p1 "\nPoint 2: "))
  (command "_.Line" p1 p2 "")
  (command "_.Divide" (entlast) 16 "")
  (setq ra (getreal "\nCircle radius: "))
  (setq ss (ssget "_X" '((0 . "POINT")))
	i 0)
  (repeat (sslength ss)
	(setq inspt (cdr (assoc 10 (entget (ssname ss i)))))
	(command "_circle" inspt ra)
	(setq i (1+ i))
	)
  (princ)
  )

Júnior Nogueira.

Por favor,  Aceitar como Solução se meu post te ajudar.

Please Accept as Solution if my post helps you.

0 Likes
Message 3 of 10

Anonymous
Not applicable

@Anonymous It's close,  much closer than I was... However it's putting in circles at every 2.875" and has left the line and nodes behind.  I'd need it to not have those otherwise I have to go back through and pick them all out?

 

Thanks!

  

0 Likes
Message 4 of 10

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

....  What I need to do is place drill holes spaced evenly between my First and Last drill hole.  These drill holes cannot be more than 16" O.C.  ....  


You can use the DIV+ command defined in DivideMeasurePlus.lsp, available >here<.  You will need to draw a Line between the centers of the first and last drill holes.  But two things DIV+ does that ordinary DIVIDE doesn't, that are appropriate to what you're doing, are:
1)  It allows selection of whatever object(s) you want, rather than being limited to Points or Blocks -- you would select one of your drill hole [presumably Circle?] objects.

2)  It has a Maximum-spacing option, and it will figure out how many are needed and how far apart, to get the minimum number necessary, at equal spacing but with the spacing not exceeding your maximum [16" in your case].

 

Draw the Line between centers of first and last holes, in more than one location if desired, load the code, and then:

 

Command: DIV+

Divide with Points/Blocks/Lines/Selection ? <P>: S
For Selection set with which to Divide,
Select objects: {pick one of the Circles}  1 found

Select objects: {Enter to complete selection}
Base point in relation to Selection: CEN of {and Osnap to it for that Circle, or use END with the Line} 
Selection rotation, or Aligned with path or Relative angle to path [angle/A/R] <A>: 0 {really any option will do in this case}

Enter number of Segments, or M for Maximum spacing <M>: {Enter to accept default}

Maximum spacing of Selection: 16

Place Selection at division points (Standard) or at Midpoints of divisions [S/M]? <S>: {Enter to accept default}

Inset from both ends of path to endmost Selection <0">: {Enter to accept default}

Place Selection at Ends of unclosed path [Yes/No]? <Yes>: N {they're already there}

Select object to Divide: {pick the Line}

Select object to Divide: {pick more Lines if you want to do more than one; Enter to end command}

 

Alternatively, you can draw the Line(s) between where the centers of first and last holes will be, without  drawing the Circles first, and choose the Yes option when it asks whether to place them at the path ends -- something ordinary DIVIDE won't do [but you'll need to have one Circle drawn somewhere, to select].  If you use it again in the same editing session, it will remember your choices and offer them as defaults that you can just accept with Enter, rather than typing them in again.

Kent Cooper, AIA
0 Likes
Message 5 of 10

Anonymous
Not applicable

@Kent1Cooper Thanks I played with it a bit and it seems to work well!  I will play with it some more as I go forward and will let you know how it goes!

 

Thanks so much!

0 Likes
Message 6 of 10

doaiena
Collaborator
Collaborator

What kind of entities are you working with @Anonymous? Lines, polylines, or something in 3D? Do you want to place holes/circles over a line, or a certain distance away from it. An example drawing of one part would help to understand the problem better, or even offer different solutions.

0 Likes
Message 7 of 10

john.uhden
Mentor
Mentor
Accepted solution

Here's soething I wrote a couple of years ago for someone here.

 

I think changing the desired spacing to 16 out to work for you...

;; HOLES.lsp written for JYelton by John F. Uhden (12-22-16)
;; Modified (05-23-18) for 16" spacing. (defun c:HOLES ( / *error* vars e1 e2 p1 p2 r1 r2 ent d space ang p obj1 obj2) (defun *error* (err) (mapcar '(lambda (x)(setvar (car x)(cdr x))) vars) (vla-endundomark *doc*) (cond ((not err)) ((wcmatch (strcase err) "*CANCEL*,*QUIT*")) (1 (princ (strcat "\nERROR: " err))) ) (princ) ) (or *acad* (setq *acad* (vlax-get-acad-object))) (or *doc* (setq *doc* (vla-get-ActiveDocument *acad*))) (vla-endundomark *doc*) (vla-startundomark *doc*) (setq vars (mapcar '(lambda (x)(cons x (getvar x))) '("cmdecho" "osmode"))) (mapcar '(lambda (x)(setvar (car x) 0)) vars) (command "_.expert" (getvar "expert")) ;; dummy command (and (setq e1 (car (entsel "\nSelect first hole: "))) (setq ent (entget e1)) (or (= (cdr (assoc 0 ent)) "CIRCLE") (prompt "\nEntity selected is not a circle.") ) (setq p1 (cdr (assoc 10 ent))) (setq r1 (cdr (assoc 40 ent))) (setq e2 (car (entsel "\nSelect last hole: "))) (setq ent (entget e2)) (or (= (cdr (assoc 0 ent)) "CIRCLE") (prompt "\nEntity selected is not a circle.") ) (setq p2 (cdr (assoc 10 ent))) (setq r2 (cdr (assoc 40 ent))) (or (not (equal e1 e2)) (prompt "\nSame circle selected twice.") ) (or (equal r1 r2 1e-4) (prompt "\nCircles have different diameters.") ) (setq d (distance p1 p2)) (or (> d (* r1 2)) (prompt "\nCircles are too close together.") ) (setq spaces (+ (fix (/ d 16.0))(if (> (rem d 16) 0) 1 0))) (setq space (/ d spaces)) (setq ang (angle p1 p2)) (setq obj1 (vlax-ename->vla-object e1)) (setq i 1) (repeat (1- spaces) (setq obj2 (vla-copy obj1)) (setq p (polar p1 ang (* i space))) (vlax-invoke obj2 'move p1 p) (setq i (1+ i)) ) ) (princ (strcat "\nAdded " (itoa (1- i)) " holes at a spacing of " (rtos space))) (*error* nil) )

John F. Uhden

0 Likes
Message 8 of 10

Anonymous
Not applicable

I'm dealing with just circles, I draw a temporary line between them to get the division and distance I need.  I want the circles placed evenly at the greatest distance possible but no more than 16" 0.C.  I've attached a sample with dimensions.  The Width, Height, and Return can all vary from panel to panel and on some jobs I have 100's of panels of different sizes and shapes. When these dimensions change so does the distance between the holes A, B, and C so I have to figure out each panel individually.  Hope this helps, I was trying to do a screencast but it doesn't want to work for me...  Sorry!

 

Thanks,

0 Likes
Message 9 of 10

Anonymous
Not applicable

Thanks @john.uhden I gave this a try on a sample panel and it appears that it works great, for what I need!  Thanks so much for sending it my way.

0 Likes
Message 10 of 10

john.uhden
Mentor
Mentor

We all love good news.

I probably should have written it to allow for user input of the hole spacing.  It's almost nothing to do.

Let me know if you need that.

John F. Uhden