Lisp lệnh H2 trong chủ đề “Viết lisp theo yêu cầu [phần 2]”
Lỗi này do máy bạn chưa cài bộ Express Tool.Bạn cài lại nó vào đi :)
Nếu khó khăn trong việc cài bộ Express thì bạn dùng lại đoạn sau cho nó thuần :
;free lisp from cadviet.com @ ketxu (defun c:h2() (setq vList '("hpname" "hpscale" "hpang" "hpassoc" "hpgaptol" "clayer" "HPSEPARATE") ; Sys Var list vValue (mapcar 'getvar vList)) (initget 1 "0 WALL W GRASS GR GROUND G MARBLE M WC S SAND B BRICK") (setq s1 (getkword "\n0/Wall/Grass/Ground/MARBLE/WC/Sand/BRICK ")) (cond ((= "0" (strcase s1)) (SetHvar "ansi37" 1 0 1 20 )) ((= "WC" (strcase s1)) (SetHvar "ansi31" 1 0 1 20)) ((or (= "GR" (strcase s1)) (= "GRASS" (strcase s1)))(SetHvar "GRASS" 1 0 1 20)) ((or (= "S" (strcase s1)) (= "SAND" (strcase s1)))(SetHvar "AR-CONC" 1 0 1 20)) ((or (= "G" (strcase s1)) (= "GROUND" (strcase s1))) (SetHvar "AR-CONC" 1 0 1 20)) ((or (= "M" (strcase s1)) (= "MARBLE" (strcase s1))) (SetHvar "AR-CONC" 1 0 1 20)) ((or (= "B" (strcase s1)) (= "BRICK" (strcase s1))) (SetHvar "AR-CONC" 1 0 1 20)) ((or (= "W" (strcase s1)) (= "WALL" (strcase s1)))(SetHvar "AR-CONC" 1 0 1 20)) );end cond (command "-hatch") (while (< 0 (getvar "CMDACTIVE")) (command pause)) (mapcar 'setvar vList vValue) );END C: (defun SetHvar (hName hScale hAng hAssoc hGap) ;hLayer) (mapcar 'setvar vlist (list hname hScale hAng hAssoc hgap "00-08Hatch" 1)) )
e cài xong cái express tool thì dùng dc nhưng khi tắt cad bật lại thi lisp lai ba'o lỗi :
0/Wall/Grass/Ground/MARBLE/WC/Sand/BRICK w
; error: no function definition: SETHVAR
- Tải lisp
- 130116_h2.lsp
Cách dùng
- Tải tệp 130116_h2.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 H2 để chạy lisp.
Mã nguồn 130116_h2.lsp
;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/13203-vi%E1%BA%BFt-lisp-theo-y%C3%AAu-c%E1%BA%A7u-ph%E1%BA%A7n-2/?page=125&tab=comments#comment-130013
;free lisp from cadviet.com @ ketxu
(defun c:h2()
(setq vList '("hpname" "hpscale" "hpang" "hpassoc" "hpgaptol" "clayer" "HPSEPARATE") ; Sys Var list
vValue (mapcar 'getvar vList))
(initget 1 "0 WALL W GRASS GR GROUND G MARBLE M WC S SAND B BRICK")
(setq s1 (getkword "\n0/Wall/Grass/Ground/MARBLE/WC/Sand/BRICK[0/Wall/Grass/Ground/MARBLE/WC/Sand/BRICK] "))
(cond
((= "0" (strcase s1)) (SetHvar "ansi37" 1 0 1 20 ))
((= "WC" (strcase s1)) (SetHvar "ansi31" 1 0 1 20))
((or (= "GR" (strcase s1)) (= "GRASS" (strcase s1)))(SetHvar "GRASS" 1 0 1 20))
((or (= "S" (strcase s1)) (= "SAND" (strcase s1)))(SetHvar "AR-CONC" 1 0 1 20))
((or (= "G" (strcase s1)) (= "GROUND" (strcase s1))) (SetHvar "AR-CONC" 1 0 1 20))
((or (= "M" (strcase s1)) (= "MARBLE" (strcase s1))) (SetHvar "AR-CONC" 1 0 1 20))
((or (= "B" (strcase s1)) (= "BRICK" (strcase s1))) (SetHvar "AR-CONC" 1 0 1 20))
((or (= "W" (strcase s1)) (= "WALL" (strcase s1)))(SetHvar "AR-CONC" 1 0 1 20))
);end cond
(command "-hatch")
(while (< 0 (getvar "CMDACTIVE")) (command pause))
(mapcar 'setvar vList vValue)
);END C:
(defun SetHvar (hName hScale hAng hAssoc hGap) ;hLayer)
(mapcar 'setvar vlist (list hname hScale hAng hAssoc hgap "00-08Hatch" 1))
)Thảo luận gốc
Lisp được chia sẻ trong chủ đề Viết lisp theo yêu cầu [phần 2]. Xem đúng bài viết #130116 để đọc hướng dẫn và trao đổi thêm.