IT Knowledge Base

~ Without sacrifice, there can be no victory ~

發佈日期:

如何在AutoCAD中‧使用AutoLISP為尺寸加上公差值

在工程學中,很多時需要在尺寸上加上公差值。雖然在AutoCAD中,已經有Dimension style可以做到此要求,但要是公差種類太多時,使用本程式便可減少設置Dimension style的數目。

今次設計目的,會先把正公差值及負公差值,先由使用者輸入到兩組AutoCAD的變數中,再執行命令加到AutoCAD的尺寸上。

;Preset the tolerance value.
(DEFUN C:1(/ A B C D E) 
(GRAPHSCR)
(SETVAR "CMDECHO" 0)
(PROMPT "\nSet upper tolerance and lower tolerance.")
(PROMPT "\nCurrent tolerance is: ")
(SETQ A (RTOS (GETVAR "USERR4"))) ;Upper tolerance is stored in USERR4 variable.
(SETQ B (RTOS (GETVAR "USERR5"))) ;Lower tolerance is stored in USERR5 variable.
(SETQ C (STRCAT "+" A "/-" B))
(PRINC C)
(PROMPT "\nEnter upper tolerance <")
(PROMPT A)
(PROMPT ">: ")
(SETQ D (GETREAL))
(IF (/= D NIL)
(SETVAR "USERR4" D)
)
(PROMPT "\nEnter lower tolerance <")
(PROMPT B)
(PROMPT ">: ")
(SETQ E (GETREAL))
(IF (/= E NIL)
(SETVAR "USERR5" E)
)
(SETVAR "CMDECHO" 1)
(PRINC)
)

; Add tolerance after the dimensions.
(DEFUN C:2(/ A B C E1 E2 E4 E5 E6 I)
(GRAPHSCR)
(SETVAR "CMDECHO" 0)
(PROMPT "\nAdd tolerance after the dimension(s).")
(SETQ A (RTOS (GETVAR "USERR4")))
(SETQ B (RTOS (GETVAR "USERR5")))
(PROMPT "\nSelect the dimension(s): ")
(SETQ E1 (SSGET))
(SETQ I 0)
(REPEAT (SSLENGTH E1)
(SETQ E4 (ENTGET (SSNAME E1 I)))
(IF (= (CDR (ASSOC 0 E4)) "DIMENSION")
(PROGN
(SETQ E5 (ASSOC 1 E4))
(SETQ E6 (CDR E5))
(IF (= E6 "")
(PROGN
(IF (/= A B)
(SETQ C (STRCAT "<>{\\H0.7x;\\S+" A "^-" B ";}"))
(SETQ C (STRCAT "<>{\\H0.7x;%%P" A "}"))
)
)
(PROGN
(IF (/= A B)
(SETQ C (STRCAT E6 "{\\H0.7x;\\S+" A "^-" B ";}"))
(SETQ C (STRCAT E6 "{\\H0.7x;%%P" A "}"))
)
)
)
(SETQ E2 (CONS 1 C))
(SETQ E4 (SUBST E2 E5 E4))
(ENTMOD E4)
(SETQ I (1+ I))
)
)
)
(SETVAR "CMDECHO" 1)
(PRINC)
)

發佈留言

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