Define AutoCAD command oneself with LISP language

  • Time:
  • Click:324
  • source:BREDA CNC Machining
AutoLISP language regards 2 development of AutoCAD as the tool, although be in,the respect such as function, traversal speed and confidential sex wants compared with the tool such as ARX a few more inferior, but as a result of it Yi Xueyi is used, alternant sex is good, flexibility is strong, for the average user that often uses AutoCAD to have plot to those, can yet be regarded as a kind of ideal development tool. The order of plot of a few AutoCAD that defines oneself with AutoLISP language introduces below, can rise to simplify the operation, function that improves constructive efficiency. One, the scale of keyway dimension view commands " Jct " in scale axis, gear or belt annulus when waiting for part drawing, often need the end panel view of the cutaway view that the keyway on painted scroll is in or hub keyway, more troublesome; Change along with the change of axial diameter as a result of the dimension of keyway, so we can realize automatic plot with LISP program. The program below to load, key in in command travel " Jct " and carriage return, through interactive form the input concerns parameter, can finish the scale of the end panel view of the cutaway view of the keyway on the axis and hub keyway automatically. Code give typical examples is shown as follows. (Defun C:jCt ()   (the central position dot that Setq Pt0 (getpoint "n inputs view please:" ) )   (Initget 7)   (  of Setq Loop T) (While Loop   (the axial diameter that Setq D (getreal "n inputs keyway to be in please (12<d<130)(mm) :" ) )   (If(or (<D 12) (>  of   of D 130))   (data of diameter of Alert " axis inputs a mistake! Nn asks new input! ")       (  of   of   of Setq Loop Nil) ) ;if     ) ;while   (diameter of Cond; basis axis retrieves keyway dimension   ((And (>D 12) (<= D 17)) (setq B 5 T1 3.

0 T2 2.

The width   that 3));b expresses keyway ((And (>D 17) (<= D 22)) (setq B 6 T1 3.

5 T2 2.

The deepness   that 8));t1 expresses the keyway on the axis ((And (>D 22) (<= D 30)) (setq B 8 T1 4.

0 T2 3.

The high   that 3));t2 expresses the keyway on hub ((And (>D 30) (<= D 38)) (setq B 10 T1 5.

0 T2 3.

3))     ((And (>D 38) (<= D 44)) (setq B 12 T1 5.

0 T2 3.

3))((and (>D 44) (<= D 50)) (setq B 14 T1 5.

5 T2 3.

8))((and (>D 50) (<= D 58)) (setq B 16 T1 6.

0 T2 4.

3))((and (>D 58) (<= D 65)) (setq B 18 T1 7.

0 T2 4.

4))((and (>D 65) (<= D 75)) (setq B 20 T1 7.

5 T2 4.

9))((and (>D 75) (<= D 85)) (setq B 22 T1 9.

0 T2 5.

4))((and (>D 85) (<= D 95)) (setq B 25 T1 9.

0 T2 5.

4))((and (>D 95) (<= D 110)) (setq B 28 T1 10.

0 T2 6.

4))((and (>D 110) (<= D 130)) (setq B 32 T1 11.

0 T2 7.

4)))(command "circle" Pt0 "d" D)(command "zoom" "a")(setq S1 (ssget "l" ))(setq Di (-(* (/ D 2.

0) (/ D 2.

0)) (* (/ B 2.

0) (/ B 2.

Dy (/ B 2 of   of   of   of   of Dx (sqrt Di) of   of   of 0)))     .

  of Pt1 (list (+ (car Pt0) Dx) (+ (cadr Pt0) Dy))) of   of   of 0)     (the cutaway view that Initget "Zc Lc");Zc expresses painted scroll keyway, the end panel view that Lc expresses to draw hub keyway (the end panel view of the cutaway view of keyway of painted scroll of Setq Zrl (getkword "n or hub keyway (Z/L) ? ") )   (  of   of If (= Zrl "Zc") (the coordinate     that Progn; computation nods on axial keyway (Setq Pt2 (list (+ (car Pt0) (-(/ D 2.

Pt3 (polar Pt2 (- (/ Pi 2 of   of   of   of   of 0) T1)) (+ (cadr Pt0) Dy)) .

Pt4 (polar Pt3 0 (- Dx (- (/ D 2 of   of   of   of 0)) B)   .

  of   of 0) T1))))   ) ;progn     ) ;if   (  of   of If (= Zrl "Lc") (the coordinate     that Progn; computation nods on hub keyway (Setq Pt2 (list (+ (car Pt0) (+(/ D 2.

Pt3 (polar Pt2 (- (/ Pi 2 of   of   of   of   of 0) T2)) (+ (cadr Pt0) Dy)) .

Pt4 (polar Pt3 (- Pi) (- (+ (/ D 2 of   of   of   of 0)) B)   .

  of   of   of 0) T2) Dx))) ) ;progn     ) ;if   (Command "pline" Pt1 Pt2 Pt3 Pt4 ""); draws keyway (  of Setq S2 (ssget "l")) (  of Command "layer" "m" 5 "l" "center" 5 "c" 1 5 "") (  of Command "ltscale" 8) (Command "line" (polar Pt0 (- Pi) (+ (/ D 2.

  of   of   of line of center of 0) 10)); picture (Polar Pt0 0 (+ (/ D 2.

  of 0) 10)) "") (  of Command "line" (polar Pt0 (- (/ Pi 2.

0)) (+ (/ D 2.

  of   of   of 0) 10))   (Polar Pt0 (/ Pi 2.

0) (+ (/ D 2.

  of 0) 10)) "") (  of   of Command "layer" "s" 0 "") (  of   of If (= Zrl "Zc") (  of Progn     (the target that Setq S3 (entsel "n chooses clip please:" ) )       (clip of Command "trim" S2 "" S3 ""); forms   of keyway     (the thalweg   of cutaway view of department of the keyway on painted scroll of Command "hatch" "U" "45" "2" "n" S1 S2 "")); ) ;if   (  of   of If (= Zrl "Lc") (Progn     (the target that Setq S4 (entsel "n chooses clip please:" ) )     (clip of Command "trim" S2 "" S4 ""); forms keyway   (Command "rotate" S1 S2 "" Pt0 90)); rotates the end panel view of hub keyway 90 degrees of   ) ;if   ) ;end Defun 2, the scale of whorl aperture cutaway view commands " Lwk " when scale machinery part drawing, often want to paint the cutaway view of whorl aperture, the nominal diameter that follows whorl as a result of the concerned dimension of whorl aperture likewise and change, we can finish the scale of its cutaway view automatically with the program below. Key in in command travel after to load " Lwk " and carriage return, input corresponding parameter according to clew can. Code give typical examples is shown as follows. (Defun C:lWk()   (the center of end panel of aperture of whorl of input of Setq Pc (osnap (getpoint "n:" )   of "near" )) (line of center of aperture of whorl of Setq Ang (getangle Pc "n and horizontal included angle:" ) )   (Initget 7)   (the nominal diameter that Setq D (getdist "n inputs whorl aperture please (Mm) :" ) )   (Cond; retrieves concerned data according to the nominal diameter of whorl aperture (the material with whorl spare parts is steel or bronze is exemple)     ((= D 6.

0) (setq L1 10 L2 12 D2 4.

917));l1 expresses whorl deepness   ((= D 8.

0) (setq L1 12 L2 16 D2 6.

647));l2 expresses bore deepness   ((= D 10.

0) (setq L1 16 L2 20 D2 8.

376));d2 expresses whorl trail   ((= D 12.

0) (setq L1 18 L2 22 D2 10.

106))     ((= D 14.

0) (setq L1 22 L2 26 D2 11.

835))     ((= D 16.

0) (setq L1 24 L2 28 D2 13.

835))     ((= D 18.

0) (setq L1 28 L2 34 D2 15.

294))     ((= D 20.

0) (setq L1 30 L2 35 D2 17.

294))     ((= D 22.

0) (setq L1 32 L2 38 D2 19.

294))     ((= D 24.

0) (setq L1 36 L2 42 D2 20.

725))     ((= D 27.

0) (setq L1 40 L2 45 D2 23.

725))     ((= D 30.

0) (setq L1 44 L2 52 D2 26.

211))     ((= D 36.

0) (setq L1 52 L2 60 D2 31.

670)))   (Setq R2 (/ D2 2.

0); computation smooth aperture nods coordinate   Pt1 (polar Pc (+ (/ Pi 2 each.

Pt3 (polar Pc Ang (+ L2 (* 0 of   of   of Pt2 (polar Pt1 Ang L2) of   of   of 0) Ang) R2) .

Pt4 (polar Pt2 (- Ang (/ Pi 2 of   of 57735 R2)))   .

Pt5 (polar Pc (+ (* Pi 1 of   of 0)) D2)   .

  of   of 5) Ang) R2)) (Command "pline" Pt1 Pt2 Pt3 Pt4 Pt5 "c"); draws smooth aperture (  of Setq S1 (ssget "l")) (line of center of picture of Command "line" (polar Pc (+ Pi Ang) 3) (polar Pt3 Ang 3) ""); (  of Command "pline" Pt2 Pt4 "") (Setq R1 (/ D 2.

The Pt11 (polar Pc (+ (/ Pi 2 of   of each bits of coordinate of line of 0); computation whorl.

Pt13 (polar Pt12 (- Ang (/ Pi 2 of   of   of Pt12 (polar Pt11 Ang L1) of   of   of 0) Ang) R1) .

Pt14 (polar Pc (+ (* Pi 1 of   of 0)) D)   .

  of 5) Ang) R1)) (Command "pline" Pt11 Pt12 Pt13 Pt14 ""); draws whorl line (  of Command "pline" Pt12 Pt13 "") (Setq Pt21 (polar Pc (+ (/ Pi 2.

0) Ang) (+ R1 10.

The Pt22 (polar Pt21 Ang (+ L2 15 of dot coordinate   on border of 0)); computation thalweg.

0)); can install the size   Pt23 (polar Pt22 (- Ang (/ Pi 2 of thalweg border according to need.

0)) (+ D 20.

Pt24 (polar Pc (+ (* Pi 1 of 0))     .

5) Ang) (+ R1 10.

0)))   (the border that Command "pline" Pt21 Pt22 Pt23 Pt24 "c"); generates thalweg (  of Setq S2 (ssget "l")) (  of Command "zoom" "a") (Command "hatch" "U" "45" "2" "n" S2 S1 ""); draws thalweg, form hole of disappear concealed whorl) ;end 3, round central line scale commands " Zxx " in plot, if need scale is foregone round center line, can call the program below. Key in in command travel after to load " Zxx " and carriage return, should choose a circle by clew only and input the outspread length of central line, can make this round center line automatically, and but successive scale. Code give typical examples is shown as follows. (Defun C:zXx()   (  of Setvar "osmode" 512) (  of Setq Loop T) (  of While Loop   (Setq Pc (getpoint "n chooses a circle with the mouse please:" ) )     (  of   of Setq S(ssget Pc)) (  of   of If S   (Progn     (the   of   of radius     that Pt0(cdr(assoc 10 S1)); of   of   of   of   of   of Setq S1(entget(ssname S 0)) obtains R (cdr(assoc 40 S1)); of   of   of   of   of coordinate of the centre of a circle to obtain a circle)     (Setq L (getreal "n inputs a center please the line is outspread:" ) )     (  of Command "layer" "m" 5 "l" "center" 5 "c" 1 5 "") (line of setting of Command "ltscale" 8); scale (Command "line" (polar Pt0 (- Pi) (+ R L)); draws central line (  of Polar Pt0 0 (+ R L)) "") (  of Command "line" (polar Pt0 (- (/ Pi 2.

  of 0)) (+ R L)) (Polar Pt0 (/ Pi 2.

  of 0) (+ R L)) "") (  of   of Command "layer" "s" 0 "") )   of;progn     (  of   of   of Setq Loop Nil) ) ;if     ) ;while   ) ;end Defun is in plot process, user but according to need, define an economic plot order conveniently with AutoLISP, raise plot rate thereby. Of course, OK still the AutoCAD command that will define oneself is custom-built into user menu or tool column, use in order to go to the lavatory. For example, will above command of a few plot is custom-built to next methods in pulling menu be: Open AutoCAD to install the ACAD in subdirectory of the SUPPORT below catalog.

MNU file, in ***POP7 join finally below content, again the menu document that to load already altered can. Again the menu document that to load already altered can.. - - ] ID_User   [keyway graph scale (Jct)]^C^C_(if(not Jct)(load "d:/Acad R14/jct.

Lip"));jct;^pID_User   [whorl aperture scale (Lwk)]^C^C_(if(not Lwk)(load "d:/Acad R14/lwk.

Lip"));lwk;^pID_User   [central line (Zxx)]^C^C_(if(not Zxx)(load "d:/Acad R14/zxx.

Lip"));zxx;^p CNC Milling CNC Machining