CommaCommand to draw a tapped hole, top and side and add dimension

CommaCommand to draw a tapped hole, top and side and add dimension

Anonymous
Not applicable
2,479 Views
22 Replies
Message 1 of 23

CommaCommand to draw a tapped hole, top and side and add dimension

Anonymous
Not applicable
;;Command to draw a tapped hole, top and side and add dimension.
;;
;;1) need help, how can we make "dimpost" a variable that fills in the dim dia?
;;2) want to make the pattern below work with a several different hole sizes
;;thanks for any help, Steve
 
(defun c:th3 ()
;;;(SETQ a (/(getreal "\nEnter Tap Dia :")2))
;;;(SETQ b (/(getreal "\nEnter Drill Size :")2))
(SETQ a 0.125) ;radius of .250 dia threads
(SETQ b 0.1005) ;radius of .201 dia thru hole
(SETVAR "DIMPOST" "\\P\ <>-20 TAP \\P\.201 DRILL")
(SETQ P (GETPOINT "\SELECT center point"))
(setq c1 (car P));x
(setq c2 (cadr P));Y
(setq xl (- c1 a))
(setq xr (+ c1 a))
(setq cpd (-(- c2 a)a))
(setq xdl (- c1 b))
(setq xdr (+ c1 b))
(setq sc (* 0.707106781 a)) ;trig for sin and csin
(setq lx (- c1 sc))
(setq ly (- c2 sc))
(SETQ SC1 (+(* 1.4 a)C1)) ;POINT X 90° OF P
(setq dir1 (polar p -100 (+ a 1.0)));
(setq dir2 (polar p 0 a))
(setq p1 (list xl cpd));xy left tap
(setq p2 (list xr cpd));xy right tap
(setq p3 (list c1 cpd));xy center
(setq p4 (list xdl cpd));xy left drill
(setq p5 (list xdr cpd));xy right drill
(setq p6 (list lx ly));POINT 45° AT A RAD
(setq p7 (list SC1 C2));POINT 90° OF P XY
(command "_circle" P b "")
(command "_line" p1 "@0.0, -2.0" "")
(command "_change" "last" ""  "p" "lt" "HIDDEN2" "")
(command "_line" p2 "@0.0, -2.0" "")
(command "_change" "last" ""  "p" "lt" "HIDDEN2" "")
(command "_line" p3 "@0.0, -2.0" "")
(command "_change" "last" ""  "p" "lt" "CENTER2" "")    
(command "_line" p4 "@0.0, -2.0" "")
(command "_line" p5 "@0.0, -2.0" "")
(command "_.ARC" "C" "_non" p "_non" (polar p (angtof "22.5") A) "_non" (polar p (angtof "67.5") A))
(command "_array" "LAST" "" "polar" p "4" "360" "y")
(command "_line" p P7 ""); drawl line for cross hairs
(command "_array" "LAST" "" "polar" p "4" "360" "y"); cross hairs
(command "_DIMDEC" 3)
(command "circle" p a "") ;draw circle
(setq h (entlast));get last ent
(command "dimdiameter"  dir2 dir1) ;dim circle
(command "erase" h "") ;erase circle
(command "_line" p P7 "")
(command "_arraypolar" "LAST" "" p "A" "90" "I" "4" "")
(SETVAR "DIMPOST" "<>")
)
0 Likes
2,480 Views
22 Replies
Replies (22)
Message 2 of 23

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:
....
;;1) need help, how can we make "dimpost" a variable that fills in the dim dia?
;;2) want to make the pattern below work with a several different hole sizes
....
(defun c:th3 ()
;;;(SETQ a (/(getreal "\nEnter Tap Dia :")2))
;;;(SETQ b (/(getreal "\nEnter Drill Size :")2))
(SETQ a 0.125) ;radius of .250 dia threads
(SETQ b 0.1005) ;radius of .201 dia thru hole
(SETVAR "DIMPOST" "\\P\ <>-20 TAP \\P\.201 DRILL")
....

I would think you could just un-comment-out the first two lines to ask the User for  the size, remove the fixed-size variable settings, and put the sizes into the DIMPOST string, something like [untested] :

 

(defun c:th3 ()
  (SETQ a (/ (getreal "\nEnter Tap Dia :") 2))
  (SETQ b (/ (getreal "\nEnter Drill Size :") 2))
  (SETVAR "DIMPOST"
    (strcat
      "\\P\ "
      (rtos a 2 3)
      "-20 TAP \\P\"
      (rtos b 2 3)
      " DRILL"
    ); strcat
  ); setvar
....
 
Change the arguments in the (rtos) functions if you want some format other than decimal numbers to 3 decimal places.
 
BUT:  Should the "-20" also be variable?  Or do you really always want the same thread pitch?
Kent Cooper, AIA
0 Likes
Message 3 of 23

Anonymous
Not applicable

Thanks for the Reply Kent,

had to blank out as shown to get it to run.

 

(SETVAR "DIMPOST"
    (strcat
     ; "\\P\ "
      (rtos a 2 3)
     ; "-20 TAP \\P\"
      (rtos b 2 3)
     ; " DRILL"
    ); strcat
  ); setvar

 

dim looked like this    ∅.500.250.225

 

Yes, would like thread size to be a variable also.

 

Was hoping to make a list of hole sizes to choose from,

in a dialog box .

Thanks, Steve

 

 

 

0 Likes
Message 4 of 23

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

....had to blank out as shown to get it to run.

 

(SETVAR "DIMPOST"
    (strcat
     ; "\\P\ "
      (rtos a 2 3)
     ; "-20 TAP \\P\"
      (rtos b 2 3)
     ; " DRILL"
    ); strcat
  ); setvar

 

dim looked like this    ∅.500.250.225

....

Was hoping to make a list of hole sizes to choose from, in a dialog box .

....


Just to get it to run?  Is that what you want  the Dimension text to look like?  I was only carrying forward your original code for the hard returns, but looking at it more closely, I think the backslashes after  the \\P's are incorrect.  If you want  the multiple lines with the wording, which was at least intended as part of the original, we can get a working combination going.

 

Dialog box commands are something I have somehow never gotten into, but I'm sure others around here can help with that.

Kent Cooper, AIA
0 Likes
Message 5 of 23

Anonymous
Not applicable

Kent,

Run the code at the top, gives the look I want.

is it possible  to insert a hard coded text string

into a dimension?

override as follows:

.201 DIA THRU HOLE

.250-20 THREADS

0 Likes
Message 6 of 23

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

....

override as follows:

.201 DIA THRU HOLE

.250-20 THREADS


Try this rearrangement, without what I think are the extraneous backslashes in the original [\\P alone is the new-line code]:

 

  (SETVAR "DIMPOST"
    (strcat
      "\\P" (rtos b 2 3) " DIA THRU HOLE"
      "\\P" (rtos a 2 3) "-20 THREADS"
    ); strcat
  ); setvar
 
You could also do it as not a suffix but an overall override, perhaps incorporating  <>  to represent the measured dimension, in which case you would need to feed it in as a Text option within the DIMensioning command, rather than set it into the DIMPOST System Variable beforehand.
Kent Cooper, AIA
0 Likes
Message 7 of 23

Anonymous
Not applicable

Kent, close, for .250 tap and .201 thru hole

this is what the dim gave me.

 

∅.250
.101 DIA THRU HOLE
.125-20 THREADS

 

I think two more setq's are needed that do not divide the dia's

 

thanks

0 Likes
Message 8 of 23

Kent1Cooper
Consultant
Consultant

I forgot the requested diameter was being divided for the radius right in the asking for it.  No need to set additional variables:

 

  (SETVAR "DIMPOST"
    (strcat
      "\\P" (rtos (* b 2) 2 3) " DIA THRU HOLE"
      "\\P" (rtos (* a 2) 2 3) "-20 THREADS"
    ); strcat
  ); setvar
 
Or, you could not  divide them in the asking, but save them as diameters, use them directly here, and do the dividing in half wherever a radius is called for.
Kent Cooper, AIA
0 Likes
Message 9 of 23

Sea-Haven
Mentor
Mentor

Your welcome to use this Multi radio buttons.lsp You can have as many choices as you like subject to some screen limitations. You need to use two lists one for the dcl display the 2nd has all the variable values (0.25 0.125 .15) etc When using the library function as shown in the examples it returns pick as string but you can run just the (AH:Butts part and look at this line (nth but butlst) the but is the number value of the item in the list so you can use (nth but lst2) to return the values.

 

Change the 1-4 etc or more with your diameters, make lst2 to suit your requirements.

 

(setq lst2 (list (list 0.25 0.2 1.0)(list 0.5 0.45 1.0)(list 1.0 0.9 1.0)(list 1.5 1.2 1.0)))

(if (not AH:Butts)(load "Multi Radio buttons.lsp"))
(if (not but)(setq but 1))
(setq ans (substr  (ah:butts but "V"   '("Choose size " "  1" "  2" "  3" "  4")) ))
(setq vals (nth but lst2)) ; this is what you want returns a list with 3 values.

screenshot239.png

 

0 Likes
Message 10 of 23

Anonymous
Not applicable

Kent, thanks, current code shown,

see jpg below, how do i fix so that

top line is gone?

Steve

 

 

(defun c:th4 ()
;;(SETQ a (/(getreal "\nEnter Tap Dia :")2))
;;(SETQ b (/(getreal "\nEnter Drill Size :")2))

(SETQ a 0.125) ;radius of .250 dia threads
(SETQ b 0.1005) ;radius of .201 dia thru hole
(SETVAR "DIMPOST"
(strcat
"\\P" (rtos (* b 2) 2 3) " DIA THRU HOLE"
"\\P" (rtos (* a 2) 2 3) "-20 THREADS"
); strcat
); setvar
(SETQ P (GETPOINT "\SELECT center point"))
(setq c1 (car P));x
(setq c2 (cadr P));Y
(setq xl (- c1 a))
(setq xr (+ c1 a))
(setq cpd (-(- c2 a)a))
(setq xdl (- c1 b))
(setq xdr (+ c1 b))
(setq sc (* 0.707106781 a)) ;trig for sin and csin
(setq lx (- c1 sc))
(setq ly (- c2 sc))
(SETQ SC1 (+(* 1.4 a)C1)) ;POINT X 90° OF P
(setq dir1 (polar p -100 (+ a 1.0)));
(setq dir2 (polar p 0 a))
(setq p1 (list xl cpd));xy left tap
(setq p2 (list xr cpd));xy right tap
(setq p3 (list c1 cpd));xy center
(setq p4 (list xdl cpd));xy left drill
(setq p5 (list xdr cpd));xy right drill
(setq p6 (list lx ly));POINT 45° AT A RAD
(setq p7 (list SC1 C2));POINT 90° OF P XY

(command "_circle" P b )

(command "_line" p4 "@0.0, -2.0" "")

(command "_line" p5 "@0.0, -2.0" "")

(command "_line" p1 "@0.0, -2.0" "")
(command "_change" "last" "" "p" "lt" "HIDDEN2" "")

(command "_line" p2 "@0.0, -2.0" "")
(command "_change" "last" "" "p" "lt" "HIDDEN2" "")

(command "_line" p3 "@0.0, -2.0" "")
(command "_change" "last" "" "p" "lt" "CENTER2" "")

(command "_line" p P7 ""); draw line for cross hairs
(command "_array" "LAST" "" "polar" p "4" "360" "y"); cross hairs

(command "circle" p a "" "") ;draw circle
(command "_change" "last" "" "p" "lt" "HIDDEN2" "")

(command "dimdiameter" dir2 dir1 "") ;dim circle

(SETVAR "DIMPOST" "<>")

 

TH4.jpg

)
(princ "\nType th4 to Run ")

0 Likes
Message 11 of 23

Anonymous
Not applicable

sea haven,

Thanks for the reply, your code is a bit over my head,

me and a co-worker made the code above, we are

learning together, still new at it.

thanks 

Steve

0 Likes
Message 12 of 23

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

... how do i fix so that top line is gone? ....


Don't bother with DIMPOST to build the text content as a suffix, which is meant to follow the measured distance, but rather invoke the Text option within your Dimension command, and give it either:

 

1)  the same text string that you had built into the DIMPOST System Variable; or

 

2)  the same text string, but with  "<>"  where the measured distance should be.  If you don't want the 0 before the decimal, set DIMZIN to 4 or 12 [read about it in Help to decide which].

Kent Cooper, AIA
0 Likes
Message 13 of 23

Sea-Haven
Mentor
Mentor

A better way than (SETQ a 0.125) ;radius of .250 dia threads (SETQ b 0.1005) ;radius of .201 dia thru hole make a list

((0.25 0.201) (0.375 0.3)........... then use a list box to select size as you have two variables you can have more like the text to be added. For me use the radio button select with the 1st item in the master list used in the radio button. 

(("1/4" 0.25 0.201) ("3/8" 0.375 0.3)......)

 

You can retrieve the correct values once picked as AH:BUTTS returns a value in BUT that is the list item number -1

 

screenshot240.png

Almost forgot can have "1/4 BSW" then can have more thread types "BSF" "mm"

 

0 Likes
Message 14 of 23

Anonymous
Not applicable

Kent, current code revised, had to blank out your rtos, could not get rid of dim on top .

Steve

_hole-thd-dim-05.JPG

 

;;command to draw a .250-20 tapped thru hole, top and side wih lable

(defun c:th5 ()
;;(SETQ a (/(getreal "\nEnter Tap Dia :")2))
;;(SETQ b (/(getreal "\nEnter Drill Size :")2))
(setq  RUFUS "\\P\.201 HOLE (#7) \\P\<>-20 UNF")
(SETQ a 0.125) ;radius of .250 dia threads
(SETQ b 0.1005) ;radius of .201 dia thru hole

;(strcat
;"\\P" (rtos (* b 2) 2 3) " DIA THRU HOLE"
;"\\P" (rtos (* a 2) 2 3) "-20 THREADS"
;); strcat
;); setvar
(SETQ P (GETPOINT "\SELECT center point"))
(setq c1 (car P));x
(setq c2 (cadr P));Y
(setq xl (- c1 a))
(setq xr (+ c1 a))
(setq cpd (-(- c2 a)a))
(setq xdl (- c1 b))
(setq xdr (+ c1 b))
(setq sc (* 0.707106781 a)) ;trig for sin and csin
(setq lx (- c1 sc))
(setq ly (- c2 sc))
(SETQ SC1 (+(* 1.4 a)C1)) ;POINT X 90° OF P
(setq dir1 (polar p -100 (+ a 1.0)));
(setq dir2 (polar p 0 a))
(setq p1 (list xl cpd));xy left tap
(setq p2 (list xr cpd));xy right tap
(setq p3 (list c1 cpd));xy center
(setq p4 (list xdl cpd));xy left drill
(setq p5 (list xdr cpd));xy right drill
(setq p6 (list lx ly));POINT 45° AT A RAD
(setq p7 (list SC1 C2));POINT 90° OF P XY

(command "_circle" P b )

(command "_line" p4 "@0.0, -2.0" "")

(command "_line" p5 "@0.0, -2.0" "")

(command "_line" p1 "@0.0, -2.0" "")
(command "_change" "last" "" "p" "lt" "HIDDEN2" "")

(command "_line" p2 "@0.0, -2.0" "")
(command "_change" "last" "" "p" "lt" "HIDDEN2" "")

(command "_line" p3 "@0.0, -2.0" "")
(command "_change" "last" "" "p" "lt" "CENTER2" "")

(command "_line" p P7 ""); draw line for cross hairs
(command "_array" "LAST" "" "polar" p "4" "360" "y"); cross hairs

(command "circle" p a "" "") ;draw circle
(command "_change" "last" "" "p" "lt" "HIDDEN2" "")

(SETVAR "DIMPOST"(PRINC RUFUS))

(command "dimdiameter" dir2 dir1 "") ;dim circle

(SETVAR "DIMPOST" "<>")


)
(princ "\nType th5 to Run ")

 

 

0 Likes
Message 15 of 23

Anonymous
Not applicable

sea haven,

thanks for the reply,

can you show what the .dcl

looks like?

thanks,

Steve

0 Likes
Message 16 of 23

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

Kent, current code revised, had to blank out your rtos, could not get rid of dim on top .

....


Probably because you haven't done what I suggested.  Re-read my previous reply, run the dimension command manually, see where it offer the Text option, use it with the constructed text string and without  involving DIMPOST, and put that sequence into the (command) function.

Kent Cooper, AIA
0 Likes
Message 17 of 23

Sea-Haven
Mentor
Mentor

Just supply a few example values as csv text, so I can grab them with correct values and will do the dcl to use in your code it is only 2 lines as the button dcl is a library routine that gets loaded when required. I will add the notes part as well using a different dcl but again only 2-3 lines of code.

 

1/4,0.25,0.2

3/8,0.375,0.35

1/2,0.5,0.45

 

0 Likes
Message 18 of 23

Sea-Haven
Mentor
Mentor

Change the lines at start add more sizes if happy. Just make sure the Multi Radio buttons .lsp is saved in a supported search path. If you don't know what that means post.

 

(defun c:th5 ()
(setq oldsnap (getvar 'osmode))
(setvar 'osmode 0)
(setq  RUFUS "\\P\.201 HOLE (#7) \\P\<>-20 UNF")
(setq lst '() lst2 '())
(setq lst (list (list "1/4" 0.125 0.1)(list "3/8" 0.1875 0.15)(list "1/2" 0.25 0.2)))
(foreach dia lst 
(setq lst2 (cons (nth 0 dia) lst2))
)
(setq lst2 (reverse lst2))
(if (not AH:Butts)(load "Multi Radio buttons.lsp"))
(if (not but)(setq but 1))
(ah:butts but "V"   (cons "Choose size " lst2))
(setq a (nth 1 (nth (- but 1) lst)))
(setq b (nth 2 (nth (- but 1) lst)))
(setq  RUFUS (strcat "\\P" (rtos (* 2.0 a) 2 3) " HOLE (#7) \\P\<>-20 UNF"))
(SETQ P (GETPOINT "\SELECT center point"))

, add  

0 Likes
Message 19 of 23

Anonymous
Not applicable

Kent,

Thanks, we relooked at what you suggested and made your way work.

The auto placement of the dim is not working?? you have to

place it manual, which works ok.

 

revised code:

 

;;command to draw a .250-20 tapped thru hole, top and side with a dynamic label.

(defun c:th6 ()
;;(SETQ a (/(getreal "\nEnter Tap Dia :")2))
;;(SETQ b (/(getreal "\nEnter Drill Size :")2))

(SETQ a 0.125) ;radius of .250 dia threads
(SETQ b 0.1005) ;radius of .201 dia thru hole

(SETQ P (GETPOINT "\SELECT center point"))
(setq c1 (car P));x
(setq c2 (cadr P));Y
(setq xl (- c1 a))
(setq xr (+ c1 a))
(setq cpd (-(- c2 a)a))
(setq xdl (- c1 b))
(setq xdr (+ c1 b))
(setq sc (* 0.707106781 a)) ;trig for sin and csin
(setq lx (- c1 sc))
(setq ly (- c2 sc))
(SETQ SC1 (+(* 1.4 a)C1)) ;POINT X 90° OF P
(setq dir1 (polar p -100 (+ a 1.0)));
(setq dir2 (polar p 0 a))
(setq p1 (list xl cpd));xy left tap
(setq p2 (list xr cpd));xy right tap
(setq p3 (list c1 cpd));xy center
(setq p4 (list xdl cpd));xy left drill
(setq p5 (list xdr cpd));xy right drill
(setq p6 (list lx ly));POINT 45° AT A RAD
(setq p7 (list SC1 C2));POINT 90° OF P XY

(command "_circle" P b )

(command "_line" p4 "@0.0, -2.0" "")

(command "_line" p5 "@0.0, -2.0" "")

(command "_line" p1 "@0.0, -2.0" "")
(command "_change" "last" "" "p" "lt" "HIDDEN2" "")

(command "_line" p2 "@0.0, -2.0" "")
(command "_change" "last" "" "p" "lt" "HIDDEN2" "")

(command "_line" p3 "@0.0, -2.0" "")
(command "_change" "last" "" "p" "lt" "CENTER2" "")

(command "_line" p P7 ""); draw line for cross hairs
(command "_array" "LAST" "" "polar" p "4" "360" "y"); cross hairs

(command "circle" p a "" "") ;draw circle
(command "_change" "last" "" "p" "lt" "HIDDEN2" "")

(command "dimdiameter" dir2  "T" (strcat
"\\P" (rtos (* b 2) 2 3) " DIA HOLE"
"\\P" (rtos (* a 2) 2 3) "-20 UNC"
); strcat
)
;;dir2 dir1 "" ) ;dim circle


(SETVAR "DIMPOST" "<>")

)
(princ "\nType th6 to Run ")

 

_hole-thd-dim-06.JPG

0 Likes
Message 20 of 23

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

Kent,

Thanks, we relooked at what you suggested and made your way work.

The auto placement of the dim is not working?? you have to place it manual....

....

(command "dimdiameter" dir2  "T" (strcat
"\\P" (rtos (* b 2) 2 3) " DIA HOLE"
"\\P" (rtos (* a 2) 2 3) "-20 UNC"
); strcat
)

....


You should be able to put that back in.  When done manually, after giving it content under the Text option, it then asks for the location, so supply it:
....

(command "dimdiameter" dir2  "T"

  (strcat
    "\\P" (rtos (* b 2) 2 3) " DIA HOLE"
    "\\P" (rtos (* a 2) 2 3) "-20 UNC"
  ); strcat

  dir1
); command

 

And if that's the entire content, not using the measured distance itself, you shouldn't need the first "\\P" and start with a hard return, unless that's to get the leader part coming into the upper [visually -- really middle] line, not centered between the two lines.

 

Also, since you're not setting a value into DIMPOST any more, you can omit the resetting of it down near the end.

Kent Cooper, AIA
0 Likes