AutoLISP 代码可以跨越多行,并包含空行和多余的空格。空行和多余的空格没有任何重要意义,但可以使代码更易于阅读。 函数名和变量名之间的多个空格,常量等效于单个空格。行尾和制表符也被视为单个空格。以下两个表达式产生相同的结果: (setq test1 123 test2 456) (setq test1 123 test2 456 ) 在AutoLISP代码中大量使用括号可能会使其难以阅读。消除这种混淆的传统技术是缩进,以及对齐函数的左括号和右括号。代码行嵌套得越深,行的位置就越靠右。 以下两个函数是相同的代码,但第二个函数更易于阅读,并且可以直观地确定 AutoLISP 表达式的括号是否平衡。 (defun c:mycmd () (setq old_clayer (getvar "clayer")) (setq insPt (getpoint "\nSpecify text insertion: ")) (if (/= insPt nil) (progn (command "_.UNDO" "_BE") (command "._-LAYER" "_M" "Text" "_C" "3" "" "") (command "_.-TEXT" insPt "" "0" "Sample Text") (command "_.UNDO" "_E"))) (setvar "clayer" old_clayer) (princ) ) (defun c:mycmd () (setq old_clayer (getvar "clayer")) (setq insPt (getpoint "\nSpecify text insertion: ")) (if (/= insPt nil) (progn (command "_.UNDO" "_BE") (command "._-LAYER" "_M" "Text" "_C" "3" "" "") (command "_.-TEXT" insPt "" "0" "Sample Text") (command "_.UNDO" "_E") ) ) (setvar "clayer" old_clayer) (princ) ) 父主题: |
|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1 苏公网安备32011402011833)
GMT+8, 2024-12-15 14:34
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.