IT Knowledge Base

~ Without sacrifice, there can be no victory ~

發佈日期:

如何在AutoCAD中‧使用AutoLISP強化Offset命令

在AutoCAD中,Offset命令也算是一個常用的命令。但為何今天我仍要多加一個呢?

此Clearance命令,最早是一位做模師傅要求的,因為在五金模具中,公板、模板、打板等孔位之間,會出現些微尺寸的分別,用Offset命令當然可以做到,但要是只是些微的分別,根本不能用肉眼看出來,要是有一程式,加大縮少後,以不同顏色顯示出來,便更容易區分。

;Main program.
(DEFUN C:CLEARANCE()
(PROMPT "\\nClearance object.")
(GRAPHSCR)
(SETVAR "CMDECHO" 0)
(SETVAR "OSMODE" 0)
(SETQ IN 0.525399)
(INITGET (+ 1 2))
(SETQ A (GETREAL "\\nEnter clearance dimension: "))
(PROMPT "\\nSelect a close boundary object: ")
(SETQ B (SSGET))
(SETQ C (SSGET "P"))
(IF (/= (CDR (ASSOC 0 (ENTGET (SSNAME B 0)))) "CIRCLE")
(PROGN
(IF (= (CDR (ASSOC 0 (ENTGET (SSNAME B 0)))) "LWPOLYLINE")
(PROGN
(COMMAND "EXPLODE" B)
(SETQ B (SSGET "P"))
)
)
(COMMAND "PEDIT" B "" "J" B C "" "")
)
)
(SETQ D1 (SSGET "L"))
(SETQ D2 (ENTGET (SSNAME D1 0)))
(IF (= (CDR (ASSOC 0 (ENTGET (SSNAME B 0)))) "CIRCLE")
(PROGN
(SETQ D3 (CDR (ASSOC 10 D2)))
(IF (< A 0)
(SETQ E D3)
(PROGN
(SETQ DX (CAR D3))
(SETQ DY (CADR D3))
(SETQ DR (CDR (ASSOC 40 D2)))
(SETQ D4 (+ A (+ DX DR)))
(SETQ E (LIST D4 DY))
)
)
(COMMAND "OFFSET" (ABS A) D1 E)
)
)
(SETQ I 0)
(REPEAT 12
(IF (= (CDR (ASSOC 0 (ENTGET (SSNAME D1 0)))) "LWPOLYLINE")
(PROGN
(SETQ D3 (CDR (ASSOC 10 D2)))
(SETQ DX (CAR D3))
(SETQ DY (CADR D3))
(SETQ DX1 (COS (* I IN)))
(SETQ DY1 (SIN (* I IN)))
(SETQ X (+ DX DX1))
(SETQ Y (+ DY DY1))
(SETQ E (LIST X Y))
(COMMAND "AREA" "O" D1)
(SETQ PAREA (GETVAR "AREA"))
(COMMAND "OFFSET" (ABS A) D1 E "")
(COMMAND "AREA" "O" "L")
(SETQ CAREA (GETVAR "AREA"))
(IF (> A 0)
(SETQ DIFF (- CAREA PAREA))
(SETQ DIFF (- PAREA CAREA))
)
(IF (> DIFF 0)
(PROGN
(IF (> (- CAREA PAREA) 0)
(COMMAND "CHPROP" "L" "" "C" "151" "")
(COMMAND "CHPROP" "L" "" "C" "51" "")
)
(COMMAND "ERASE" D1 "")
(EXIT)
)
(COMMAND "ERASE" "L" "")
)
)
)
(SETQ I (+ 1 I))
)
(PROMPT "\\nCan't do clearance process.")
(SETVAR "OSMODE" 59)
(SETVAR "CMDECHO" 1)
(PRINC)
)

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *