Lisp lệnh BRANG trong chủ đề “xin các anh lisp bộ truyền bánh răng trụ răng thẳng!”
gần giống ... anh ạ. thanks anh nhe!
Hề hề hề,
Cái ni có giống không hè???
(defun c:brang ( / echo oldos ort p1 m z gak goc R x y toado e1 e3 e4 e5 e6 e7 e8 e9 e10 e0 p0 p1 p2)
(vl-load-com)
(princ "\n DAY LA CHUONG TRINH VE BANH RANG THAN KHAI RANG THANG THEO Z & M")
(setq echo (getvar "cmdecho") )
(setvar "cmdecho" 0)
(setq oldos (getvar "osmode") )
(setvar "osmode" 4287)
(setq osm (getvar "osmode")
ort (getvar "orthomode") )
(command "undo" "be")
(setq pt (getpoint "\n Chon vi tri tam vong tron co so")
m (getint "\n Nhap gia tri modun m: ")
z (getint "\n Nhap so rang: ")
gak (getint "\n Nhap goc an khop: ")
goc 0.0
)
(command "ucs" "n" pt)
(command "ucs" "z" 90)
(if (not gak) (setq gak 20))
(setvar "orthomode" 0)
(command "viewres" "y" 5000)
(command "color" 1)
(setvar "osmode" 0)
(defun dtr (x) (* x (/ pi 180)))
(command "spline")
(repeat 46
(setq R (/ (* m z (cos (dtr gak))) 2)
x (+ (* R (cos (dtr goc))) (/ (* pi R goc (sin (dtr goc))) 180))
y (- (* R (sin (dtr goc))) (/ (* R pi goc (cos (dtr goc))) 180))
goc (1+ goc)
toado (list x y) )
(command toado)
)
(command "" "" "" )
(setq e1 (entlast))
(command "color" 7)
(command "circle" '(0 0) R)
(command "arc" "c" '(0 0) (setq p1 (polar '(0 0) 0 (* 0.5 z m))) "angle" (* 1.5 (/ 360 z)) )
(setq e3 (entlast))
(setq p0 (trans (car (acet-geom-intersectwith e1 e3 0)) 0 1))
(command "break" e3 p0 p0)
(command "erase" e3 "")
(setq e3 (entlast))
(setvar "cecolor" "2")
(command "arc" "c" '(0 0) p0 "angle" (* 0.25 (/ 360 z)))
(setq e6 (entlast))
(setvar "cecolor" "7")
(command "arc" "c" '(0 0) (polar '(0 0) 0 (* (+ (* 0.5 z) 1) m)) "angle" 30)
(setq e4 (entlast))
(setq p0 (trans (car (acet-geom-intersectwith e1 e4 0)) 0 1))
(command "break" e1 p0 p0)
(command "erase" (entlast) "")
(command "break" e4 p0 p0)
(command "erase" e4 "")
(setq e4 (entlast))
(command "zoom" "e")
(command "fillet" "r" (* 0.2 m) )
(vl-cmdf ".MATCHPROP" e1 e4 "")
(command "fillet" e1 e4)
(setq e5 (entlast))
(command "arc" "c" '(0 0) (polar '(0 0) (dtr (- (* 1.5 (/ 360 z)))) (* (- (* 0.5 z) 1.25) m)) "a" (* 1.4 (/ 360 z)))
(setq e7 (entlast))
(if (acet-geom-intersectwith e1 e7 2)
(progn
(setq p0 (trans (car (acet-geom-intersectwith e1 e7 2)) 0 1))
(command "extend" e1 "" e7 "")
(command "break" e1 p0 p0)
(command "erase" e1"")
(setq e1 (entlast))
)
)
(if (> z 30)
(command "fillet" "r" (* 0.4 m) )
(command "fillet" "r" (* 1.2 (- (* 0.5 m z (cos (dtr gak))) (* 0.5 m (- z 2.5)))) )
)
(vl-cmdf ".MATCHPROP" e1 e7 "")
(command "fillet" e1 e7 "erase" e7 "")
;;(command "erase" e7 "")
(setq e7 (entlast))
(setq p0 (trans (vlax-curve-getendpoint (vlax-ename->vla-object e6)) 0 1))
(command "mirror" e5 "" p0 '(0 0) "n")
(setq e8 (entlast))
(command "mirror" e7 "" p0 '(0 0) "n")
(setq e9 (entlast))
(command "mirror" e1 "" p0 '(0 0) "n")
(setq e10 (entlast))
(setq p0 (trans (car (acet-geom-intersectwith e4 e8 0)) 0 1) )
(command "break" e4 p0 p0)
(command "erase" (entlast) "")
(command "array" e1 e10 e5 e7 e8 e4 e9 "" "p" '(0 0) z 360 "y")
(command "erase" e3 e6 "")
(setq e0 (entlast))
(setq p1 (trans (vlax-curve-getstartpoint (vlax-ename->vla-object e0)) 0 1)
p2 (trans (vlax-curve-getendpoint (vlax-ename->vla-object e7)) 0 1) )
(setvar "cecolor" "1")
(command "arc" "c" '(0 0) p1 p2)
(setq e0 (entlast))
(command "array" e0 "" "p" '(0 0) z 360 "y")
(command "linetype" "s" "center" "")
(setvar "cecolor" "2")
(command "ltscale" 10)
(command "circle" '(0 0) (* 0.5 m z))
(command "linetype" "s" "bylayer" "")
(command "regen")
(command "zoom" "all")
(command "ucs" "w")
(command "undo" "e")
(setvar "osmode" osm)
(setvar "orthomode" ort)
(setvar "cmdecho" echo)
(princ)
)
(prompt "\n Go lenh Brang de bat dau chuong trinh" )
- Tải lisp
- 230761_brang.lsp
Cách dùng
- Tải tệp 230761_brang.lsp về máy.
- Trong AutoCAD gõ lệnh APPLOAD, chọn tệp vừa tải rồi bấm Load. Cũng có thể kéo thả tệp .lsp vào cửa sổ bản vẽ.
- Gõ lệnh BRANG để chạy lisp.
Mã nguồn 230761_brang.lsp
;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/69902-xin-c%C3%A1c-anh-lisp-b%E1%BB%99-truy%E1%BB%81n-b%C3%A1nh-r%C4%83ng-tr%E1%BB%A5-r%C4%83ng-th%E1%BA%B3ng/
(defun c:brang ( / echo oldos ort p1 m z gak goc R x y toado e1 e3 e4 e5 e6 e7 e8 e9 e10 e0 p0 p1 p2)(vl-load-com)(princ "\n DAY LA CHUONG TRINH VE BANH RANG THAN KHAI RANG THANG THEO Z & M")(setq echo (getvar "cmdecho") )(setvar "cmdecho" 0)(setq oldos (getvar "osmode") )(setvar "osmode" 4287)(setq osm (getvar "osmode") ort (getvar "orthomode") )(command "undo" "be")(setq pt (getpoint "\n Chon vi tri tam vong tron co so") m (getint "\n Nhap gia tri modun m: ") z (getint "\n Nhap so rang: ") gak (getint "\n Nhap goc an khop: ") goc 0.0)(command "ucs" "n" pt)(command "ucs" "z" 90)(if (not gak) (setq gak 20))(setvar "orthomode" 0)(command "viewres" "y" 5000)(command "color" 1)(setvar "osmode" 0)(defun dtr (x) (* x (/ pi 180))) (command "spline")(repeat 46 (setq R (/ (* m z (cos (dtr gak))) 2) x (+ (* R (cos (dtr goc))) (/ (* pi R goc (sin (dtr goc))) 180)) y (- (* R (sin (dtr goc))) (/ (* R pi goc (cos (dtr goc))) 180)) goc (1+ goc) toado (list x y) ) (command toado))(command "" "" "" )(setq e1 (entlast))(command "color" 7)(command "circle" '(0 0) R) (command "arc" "c" '(0 0) (setq p1 (polar '(0 0) 0 (* 0.5 z m))) "angle" (* 1.5 (/ 360 z)) ) (setq e3 (entlast))(setq p0 (trans (car (acet-geom-intersectwith e1 e3 0)) 0 1))(command "break" e3 p0 p0)(command "erase" e3 "")(setq e3 (entlast))(setvar "cecolor" "2")(command "arc" "c" '(0 0) p0 "angle" (* 0.25 (/ 360 z)))(setq e6 (entlast))(setvar "cecolor" "7")(command "arc" "c" '(0 0) (polar '(0 0) 0 (* (+ (* 0.5 z) 1) m)) "angle" 30)(setq e4 (entlast))(setq p0 (trans (car (acet-geom-intersectwith e1 e4 0)) 0 1))(command "break" e1 p0 p0)(command "erase" (entlast) "")(command "break" e4 p0 p0)(command "erase" e4 "")(setq e4 (entlast))(command "zoom" "e")(command "fillet" "r" (* 0.2 m) )(vl-cmdf ".MATCHPROP" e1 e4 "")(command "fillet" e1 e4)(setq e5 (entlast))(command "arc" "c" '(0 0) (polar '(0 0) (dtr (- (* 1.5 (/ 360 z)))) (* (- (* 0.5 z) 1.25) m)) "a" (* 1.4 (/ 360 z)))(setq e7 (entlast)) (if (acet-geom-intersectwith e1 e7 2) (progn (setq p0 (trans (car (acet-geom-intersectwith e1 e7 2)) 0 1)) (command "extend" e1 "" e7 "") (command "break" e1 p0 p0) (command "erase" e1"") (setq e1 (entlast)) ))(if (> z 30) (command "fillet" "r" (* 0.4 m) ) (command "fillet" "r" (* 1.2 (- (* 0.5 m z (cos (dtr gak))) (* 0.5 m (- z 2.5)))) ))(vl-cmdf ".MATCHPROP" e1 e7 "")(command "fillet" e1 e7 "erase" e7 "");;(command "erase" e7 "")(setq e7 (entlast))(setq p0 (trans (vlax-curve-getendpoint (vlax-ename->vla-object e6)) 0 1))(command "mirror" e5 "" p0 '(0 0) "n")(setq e8 (entlast))(command "mirror" e7 "" p0 '(0 0) "n")(setq e9 (entlast))(command "mirror" e1 "" p0 '(0 0) "n")(setq e10 (entlast))(setq p0 (trans (car (acet-geom-intersectwith e4 e8 0)) 0 1) )(command "break" e4 p0 p0)(command "erase" (entlast) "")(command "array" e1 e10 e5 e7 e8 e4 e9 "" "p" '(0 0) z 360 "y")(command "erase" e3 e6 "")(setq e0 (entlast))(setq p1 (trans (vlax-curve-getstartpoint (vlax-ename->vla-object e0)) 0 1) p2 (trans (vlax-curve-getendpoint (vlax-ename->vla-object e7)) 0 1) )(setvar "cecolor" "1")(command "arc" "c" '(0 0) p1 p2)(setq e0 (entlast))(command "array" e0 "" "p" '(0 0) z 360 "y")(command "linetype" "s" "center" "")(setvar "cecolor" "2")(command "ltscale" 10)(command "circle" '(0 0) (* 0.5 m z))(command "linetype" "s" "bylayer" "") (command "regen")(command "zoom" "all")(command "ucs" "w")(command "undo" "e")(setvar "osmode" osm)(setvar "orthomode" ort)(setvar "cmdecho" echo)(princ))(prompt "\n Go lenh Brang de bat dau chuong trinh" )
https://www.cadviet.com/upfiles/3/5194_vebanhrangthankhai.lspThảo luận gốc
Lisp được chia sẻ trong chủ đề xin các anh lisp bộ truyền bánh răng trụ răng thẳng!. Xem đúng bài viết #230761 để đọc hướng dẫn và trao đổi thêm.