Customize AutoCAD commands in LISP language

Customize AutoCAD commands in LISP language

As the secondary development tool of AutoCAD, AutoLISP language is inferior to ARX and other tools in terms of function, running speed and confidentiality. For the average user who is drawing, it is an ideal development tool. The following introduces several AutoCAD drawing commands customized in AutoLISP language, which can simplify the operation and improve the efficiency of drawing.
1. The drawing command "jct" of the keyway size view
When drawing parts such as shafts, gears or pulleys, it is often necessary to draw a cross-sectional view of the keyway on the shaft or an end view of the keyway of the hub, which is more troublesome; because the size of the keyway changes with the change of the shaft diameter, we can use the LISP program Realize automatic drawing. Load the following program, type "jct" in the command line and press Enter, enter the relevant parameters through the form of human-computer interaction, you can automatically complete the section view of the keyway on the shaft and the end view of the keyway of the hub. The code example is shown below.
(defun C: jct ()
(setq pt0 (getpoint "Please enter the center point of the view:"))
(initget 7)
(setq loop T)
(while loop
(setq d (getreal "Please enter the shaft diameter at the keyway (12 (if (or (<d 12) (> d 130))
(alert "Shaft diameter data input error! Please re-enter!")
(setq loop nil)
); if
); while
(cond; Search keyway size based on shaft diameter ((and (> d 12) (<= d 17)) (setq b 5 t1 3.0 t2 2.3)); b represents the width of the keyway ((and (> d 17) (< = d 22)) (setq b 6 t1 3.5 t2 2.8)); t1 is the depth of the keyway on the shaft ((and (> d 22) (<= d 30)) (setq b 8 t1 4.0 t2 3.3)); t2 Indicates the height of the keyway on the 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.0)))
dx (sqrt di)
dy (/ b 2.0)
pt1 (list (+ (car pt0) dx) (+ (cadr pt0) dy)))
(initget "Zc Lc"); Zc represents the sectional view of the shaft keyway, Lc represents the end view of the hub keyway (setq zrl (getkword "The sectional view of the shaft keyway or the end view of the hub keyway (Z / L)?"))
(if (= zrl "Zc")
(progn; Calculate the coordinates of the point on the axis keyway (setq pt2 (list (+ (car pt0) (-(/ d 2.0) t1)) (+ (cadr pt0) dy))
pt3 (polar pt2 (-(/ pi 2.0)) b)
pt4 (polar pt3 0 (-dx (-(/ d 2.0) t1))))
); progn
); if
(if (= zrl "Lc")
(progn; Calculate the coordinates of the point on the hub keyway (setq pt2 (list (+ (car pt0) (+ (/ d 2.0) t2)) (+ (cadr pt0) dy))
pt3 (polar pt2 (-(/ pi 2.0)) b)
pt4 (polar pt3 (-pi) (-(+ (/ d 2.0) t2) dx)))
); progn
); if
(command "pline" pt1 pt2 pt3 pt4 ""); draw key slot (setq s2 (ssget "l"))
(command "layer" "m" 5 "l" "center" 5 "c" 1 5 "")
(command "ltscale" 8)
(command "line" (polar pt0 (-pi) (+ (/ d 2.0) 10)); draw the center line (polar pt0 0 (+ (/ d 2.0) 10)) "")
(command "line" (polar pt0 (-(/ pi 2.0)) (+ (/ d 2.0) 10))
(polar pt0 (/ pi 2.0) (+ (/ d 2.0) 10)) "")
(command "layer" "s" 0 "")
(if (= zrl "Zc")
(progn
(setq s3 (entsel "Please select the target for pruning:"))
(command "trim" s2 "" s3 ""); trim to form a keyway (command "hatch" "U" "45" "2" "n" s1 s2 "")); draw the cross-sectional view of the keyway at the keyway on the axis); if
(if (= zrl "Lc")
(progn
(setq s4 (entsel "Please select the target for pruning:"))
(command "trim" s2 "" s4 ""); trim to form a keyway (command "rotate" s1 s2 "" pt0 90)); rotate the end view of the hub keyway by 90 degrees); if
); end defun
Second, the drawing command "lwk" of the threaded hole section view
When drawing a mechanical part drawing, it is often necessary to draw a cross-sectional view of the threaded hole. Also because the relevant size of the threaded hole changes with the nominal diameter of the thread, we can use the following procedure to automatically complete the drawing of the cross-sectional view. After loading, type "lwk" in the command line and press Enter. Enter the corresponding parameters as prompted. The code example is shown below.
(defun C: lwk ()
(setq pc (osnap (getpoint "Enter the center point of the threaded hole end face:") "near"))
(setq ang (getangle pc "The angle between the center line of the threaded hole and the horizontal line:"))
(initget 7)
(setq d (getdist "Please enter the nominal diameter (mm) of the threaded hole:"))
(cond; Retrieve relevant data based on the nominal diameter of the threaded hole (take the threaded material as steel or bronze for example)
((= d 6.0) (setq l1 10 l2 12 d2 4.917)); l1 means thread depth ((= d 8.0) (setq l1 12 l2 16 d2 6.647)); l2 means drilling depth ((= d 10.0) ( setq l1 16 l2 20 d2 8.376)); d2 represents the small diameter of the thread ((= 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); calculate the coordinates of each point of the light hole pt1 (polar pc (+ (/ pi 2.0) ang) r2)
pt2 (polar pt1 ang l2)
pt3 (polar pc ang (+ l2 (* 0.57735 r2)))
pt4 (polar pt2 (-ang (/ pi 2.0)) d2)
pt5 (polar pc (+ (* pi 1.5) ang) r2))
(command "pline" pt1 pt2 pt3 pt4 pt5 "c"); draw light holes (setq s1 (ssget "l"))
(command "line" (polar pc (+ pi ang) 3) (polar pt3 ang 3) ""); draw the center line (command "pline" pt2 pt4 "")
(setq r1 (/ d 2.0); calculate the coordinates of each point of the thread pt11 (polar pc (+ (/ pi 2.0) ang) r1)
pt12 (polar pt11 ang l1)
pt13 (polar pt12 (-ang (/ pi 2.0)) d)
pt14 (polar pc (+ (* pi 1.5) ang) r1))
(command "pline" pt11 pt12 pt13 pt14 ""); draw a thread (command "pline" pt12 pt13 "")
(setq pt21 (polar pc (+ (/ pi 2.0) ang) (+ r1 10.0)); calculate the point coordinates on the boundary of the section line pt22 (polar pt21 ang (+ l2 15.0)); you can set Size pt23 (polar pt22 (-ang (/ pi 2.0)) (+ d 20.0))
pt24 (polar pc (+ (* pi 1.5) ang) (+ r1 10.0)))
(command "pline" pt21 pt22 pt23 pt24 "c"); generate the boundary of the section line (setq s2 (ssget "l"))
(command "zoom" "a")
(command "hatch" "U" "45" "2" "n" s2 s1 ""); draw a hatch to form a hidden thread hole); end

3. The center line drawing command "zxx"
In drawing, if you need to draw the center line of a known circle, you can call the following program. After loading, type "zxx" in the command line and press Enter. Just select the circle according to the prompt and enter the extension of the center line, the center line of the circle can be automatically generated and can be drawn continuously. The code example is shown below.
(defun C: zxx ()
(setvar "osmode" 512)
(setq loop T)
(while loop
(setq pc (getpoint "Please select the circle with the mouse:"))
(setq s (ssget pc))
(if s
(progn
(setq s1 (entget (ssname s 0))
pt0 (cdr (assoc 10 s1)); get the circle center coordinate r (cdr (assoc 40 s1)); get the radius of the circle)
(setq l (getreal "Please enter the centerline extension (mm):"))
(command "layer" "m" 5 "l" "center" 5 "c" 1 5 "")
(command "ltscale" 8); set the line scale (command "line" (polar pt0 (-pi) (+ rl)); draw the center line (polar pt0 0 (+ rl)) "")
(command "line" (polar pt0 (-(/ pi 2.0)) (+ rl))
(polar pt0 (/ pi 2.0) (+ rl)) "")
(command "layer" "s" 0 "")
); progn
(setq loop nil)
); if
); while
); end defun
In the drawing process, users can use AutoLISP to easily define practical drawing commands as needed to improve drawing speed. Of course, custom AutoCAD commands can also be customized into user menus or toolbars for ease of use. For example, the way to customize the several drawing commands described above to the drop-down menu is: open the ACAD.MNU file in the SUPPORT subdirectory of the AutoCAD installation directory, add the following content at the end of the *** POP7 item, and then load the modified Menu file.
[-]
ID_User [key slot drawing (jct)] ^ C ^ C_ (if (not jct) (load "d: / Acad R14 / jct.lip")); jct; ^ p
ID_User [Threaded Hole Drawing (lwk)] ^ C ^ C_ (if (not lwk) (load "d: / Acad R14 / lwk.lip")); lwk; ^ p
ID_User [Center Line (zxx)] ^ C ^ C_ (if (not zxx) (load "d: / Acad R14 / zxx.lip")); zxx; ^ p

Switching Power Supply

LED power supply, CCTV center power supply device, LCD display power supply.


We can meet your specific requirement of the products, like label design. The plug type is US/UK/AU/EU. The material of this product is PC+ABS. All condition of our product is 100% brand new. OEM and ODM are available in our company, and you deserve the best service. You can send more details of this product, so that we can offer best service to you!


Power Supply,5V Power Supply,12V Power Supply, 24V Power Supply

Shenzhen Waweis Technology Co., Ltd. , https://www.waweisasdapter.com