你看过代码中的注释了吗?
这个lambda必须在progn块中使用,您只是将它复制到我提出的基本结构下面,并删除了语法,因此它不会进行计算。
无论如何FWIW:
- (defun C:GT ( / MFR MODEL nlyr olyr cmd vb MFRMODEL ) ; always localise your variables (unless you know what you're doing)
- (if ; main (if) function: (if <User Inputs> <Code do its stuff> <Else print whats wrong>)
- (setq ; Declare the initial variables (assign value to each symbol):
- MFR "GLASTENDER"
- MODEL "CBA-36L"
- nlyr "QF-EQPM"
- olyr (getvar 'clayer)
- cmd (getvar 'cmdecho)
- vb ; get user input (find the orientation and the corresponding block)
- (assoc
- (progn
- (initget "Plan Elev Side 3D")
- (getkword "Enter Orientation [Plan/Elev/Side/3D]:")
- )
- '(("Plan" . "GTC005P") ("Elev" . "GTC005E") ("Side" . "GTJ011S") ("3D" . "GTC0053"))
- ); assoc
- ); setq
- (progn ; if the user input are correct, proceed...
- (setq MFRMODEL (strcat MFR "_" MODEL "_" (strcase (car vb)))) ; assemble the total name
- (setvar 'cmdecho 0) (if (tblsearch "LAYER" nlyr) (setvar 'clayer nlyr)) ; temporarily change system variables
- (cond
- ( (tblsearch "BLOCK" MFRMODEL) ; if such block exist
- (command "_.INSERT" MFRMODEL "\" "1" "1" "\") ; prompt the user to inser it and exit
- )
- ( (tblsearch "BLOCK" (cdr vb)) ; if MFRMODEL block do not exist, check if a corrseponding block exist
- (and
- (not (command "_.INSERT" (cdr vb) "\" "1" "1" "\")) ; if a corresponding block exist, prompt to insert it
- (not (command "_.RENAME" "block" (cdr vb) MFRMODEL)) ; if the block is inserted, rename it
- )
- )
- ( (princ (strcat "\nBlocks "" MFRMODEL "" and "" (cdr vb) "" were not found.")) ) ; if none of the blocks were found, display this message
- )
- (setvar 'clayer olyr)(setvar 'cmdecho cmd) ; restore the system variables
- ); progn
- (princ "\nOrientation was not specified.") ; print what went wrong
- ); if
- (princ) ; exit cleanly
- ); defun
|