只是一些快速的想法来帮助你开始(但不是测试)
您会发现,您将编写的大多数代码都是错误检查
当你编写一段代码时,你应该考虑它可能崩溃或引起问题的所有方式。
通常情况下,可以使用if语句进行验证,但这完全取决于您正在尝试做什么。
总的错误陷阱总是一件值得学习的事情,因此当程序崩溃时,所有设置都会返回到原来的位置。
这个网站上有很多错误陷阱的例子,只要搜索一下就可以了
我希望这有帮助
-
- (DEFUN C:SW1 ()
- (Prompt "SolidWorks DWG Cleanup:")
- (setq TEST (tblsearch "LAYER" "Dim"))
- (if (= TEST nil)
- (progn
- (Command "-layer" "n" "Dim" "C" "Red" "Dim" "")
- )
- )
- (setq ss1 (ssget "x" '((0 . "INSERT")(2 . "*SW_CENTERMARKSYMBOL_*,*SW_NOTE_1*,*SW_TABLEANNOTATION_0*"))))
- (if ss1
- (Command "Erase" SS1 "")
- );_if
- ;;;(setq ss2 (ssget "x" '((0 . "INSERT")(2 . "*SW_NOTE_1*"))))
- ;;;(Command "Erase" SS2 "")
- ;;;(setq ss3 (ssget "x" '((0 . "INSERT")(2 . "*SW_TABLEANNOTATION_0*"))))
- ;;;(Command "Erase" SS3 "")
- ;;; before you make a style use tblsearch to chaeck if it is there
- (Command "-style" "Romans" "romans" "" "0.9" "" "" "n" "n")
- (princ "\nRomans Text Style Created:")
- ;; also check for the below items
- (command "dimstyle" "r" "standard")
- (command "dimtxsty" "romans")
- (Command "dimstyle" "s" "standard" "y" )
- ;****this is a good code usinf the if to error trap
- (if (setq ss (ssget "x" '((0 . "DIMENSION"))))
- (repeat
- (setq i (sslength ss))
- (setq sset (ssname ss (setq i (1- i))))
- (if (not (eq (cdr (assoc 3 (setq e (entget sset)))) "Standard"))
- (entmod (subst (cons 3 "Standard") (assoc 3 e) e))
- )
- )
- (princ)
- )
- (setq ss4 (ssget "x" '((0 . "DIMENSION"))))
- (if ss4 ;_us if to check if ss is good
- (progn
- (Command "_CHANGE" SS4 "" "P" "LA" "DIM" "C" "BYLAYER" "")
- (Command "_LAYER" "C" "GREEN" "X50" "C" "yellow" "TEXT" "")
- );_progn
- );_if
- (setq ss5 (ssget "x" '((6 . "PHANTOM,HIDDEN,DASHED"))))
- (if ss5
- (Command "_CHANGE" SS5 "" "P" "LA" "X25" "C" "BYLAYER" "LT" "PHANTOM" "")
- );_if
- ;;;(setq ss6 (ssget "x" '((6 . "HIDDEN"))))
- ;;;(Command "_CHANGE" SS6 "" "P" "LA" "X25" "C" "BYLAYER" "LT" "HIDDEN" "")
- ;;;
- ;;;(setq ss7 (ssget "x" '((6 . "DASHED"))))
- ;;;(Command "_CHANGE" SS7 "" "P" "LA" "X25" "C" "BYLAYER" "LT" "DASHED" "")
- (princ)
- );_defun
|