Let me try to rephrase the question.
this is the error message I get if the custom property "PLOTFILE" has not been created
Error: Automation Error. Key not found
I would like the following to happen when the key is not found
(initdia)
(command "_.PLOT")
I need to know how to check to see if "PLOTFILE" exists in the custom drawing properties.
This is my entire code, it works fine right now, other than when there is no property "PLOTFILE" in the cross section sheets, then I get the above error
Code:
(command "undefine" "plot")
(defun C:PLOT (/ ss App Doc Dwgprops dname name file)
(vl-load-com)
;;===============================================
;; L o c a l F u n c t i o n s
;;===============================================
;; error function & Routine Exit
(defun *error* (msg)
(if
(not
(member
msg
'("console break"
"Function cancelled"
"quit / exit abort"
""
)
)
)
(princ (strcat "\nError: " msg))
) ; endif
(restore_sys_vars) ; reset vars
)
;; Function to save system variables in global variable
;; call to function
;; (save_sys_vars '("CMDECHO" "FILEDIA"))
(defun save_sys_vars (lst)
(setq *sysvarlist* '())
(repeat (length lst)
(setq *sysvarlist*
(append *sysvarlist*
(list (list (car lst) (getvar (car lst))))
)
)
(setq lst (cdr lst))
)
)
;; Function to reset system variables
(defun restore_sys_vars ()
(repeat (length *sysvarlist*)
(setvar (caar *sysvarlist*) (cadar *sysvarlist*))
(setq *sysvarlist* (cdr *sysvarlist*))
)
)
(save_sys_vars '("CMDECHO" "FILEDIA"))
(setvar "cmdecho" 0)
(setvar "filedia" 0)
(SETQ spellselect
(SSGET "all"
(LIST '(-4 . "<AND")
(CONS 410 (GETVAR "ctab"))
'(-4 . "<NOT")
'(-4 . "<AND")
'(0 . "INSERT")
'(2 . "M*")
'(-4 . "AND>")
'(-4 . "NOT>")
'(-4 . "AND>")
) ;end of LIST
) ;end of ssget
) ;end setq
;(if (/= spellselect nil)
;(COMMAND "SPELL" spellselect "")
;);end if
(setq spellselect nil)
(setvar "expert" 5)
(setq dname (getvar "DWGPREFIX")
filename (getvar "DWGNAME")
)
(setq dir (strcat dname "PLOTS\\"))
(vl-mkdir dir)
(setq extA (getvar "ctab"))
(if (/= (setq ss (ssget "_x"
(list '(-4 . "<and")
'(0 . "insert")
(CONS 410 (GETVAR "ctab"))
'(2 . "TBL8,TBL13,TBL14,TBL15,CTLB")
(CONS 10 '(0 0 0))
'(-4 . "and>")
) ;end list
) ;end ssget
) ;end setq
nil
) ;end =
(PROGN
(if (wcmatch extA "SH#*")
(progn
(setq file (strcat dir extA ".PLT"))
(setq
tfresult
(dwpMsgbox
"WIGHTMAN CAD WARNING"
(strcat "Do you wish to plot directly to file?"
"\n"
"(If yes click ok if not click cancel)"
)
vlax-vbOKCancel
vlax-vbExclamation
) ;end dwpmsgbox
) ;end setq
;;PLOT DIRECTLY TO FILE?
(if (= tfresult 1)
(progn
;(setvar "filedia" 0)
(command "-psetupin" "page setup" "*")
(if (/= (setq ss (ssget "_x"
(list '(-4 . "<and")
'(0 . "insert")
(CONS 410 (GETVAR "ctab"))
'(2 . "TBL15")
'(-4 . "and>")
) ;end list
) ;end ssget
) ;end setq
nil
) ;end =
(setq pagesetup "30x42PS")
) ;end if
(if (/= (setq
ss
(ssget "_x"
(list '(-4 . "<and")
(cons 0 "insert")
(CONS 410 (GETVAR "ctab"))
(cons 2 "TBL14,TBL8,TBL13,CTLB")
'(-4 . "and>")
) ;end list
) ;end ssget
) ;end setq
nil
) ;end =
(setq pagesetup "24x36PS")
) ;end if
(command ".-PLOT" "N" ;Detailed plot configuration? [Yes/No] <No>: N
"" ;Enter a layout name or [?] <Layout1>:
pagesetup ;Enter a page setup name <>:
"" ;Enter an output device name or [?] <current>:
"y" ;Write the plot to a file [Yes/No] <N>: y
file ;Enter file name <\\maverick\engineering\x5405\RCp01001-Layout1.PLT>:
"y" ;Save changes to page setup [Yes/No]? <N> n
"y" ;Proceed with plot [Yes/No] <Y>:
) ;end command
) ;end progn
(progn ;if you wish not to plot directly to file
(initdia)
(command "_.PLOT")
) ;end progn
) ;end tfresult if
) ;end progn for wcmatch t
(progn ;end if for wcmatch t
(if (= (wcmatch filename "rc#*") t)
(progn
(setq App (vlax-Get-Acad-Object)
Doc (vla-Get-ActiveDocument App)
DwgProps (vla-Get-SummaryInfo Doc)
) ;end setq
(setq name "PLOTFILE")
(vla-GetCustomByKey DwgProps name 'ext)
(if (/= ext "")
(progn
(setq
file (strcat dname "PLOTS\\" ext ".PLT")
)
(setq
tfresult
(dwpMsgbox
"WIGHTMAN CAD WARNING"
(strcat
"Do you wish to plot directly to file?"
"\n"
"(If yes click ok if not click cancel)"
) ;end strcat
vlax-vbOKCancel
vlax-vbExclamation
) ;end dwpmsgbox
) ;end setq
;;PLOT DIRECTLY TO FILE?
(if (= tfresult 1)
(progn
;(setvar "filedia" 0)
(command "-psetupin" "page setup" "*")
(if (/= (setq
ss
(ssget
"_x"
(list
'(-4 . "<and")
(cons 0 "insert")
(CONS 410 (GETVAR "ctab"))
(cons 2 "TBL14,TBL8,TBL13,CTLB")
'(-4 . "and>")
) ;end list
) ;end ssget
) ;end setq
nil
) ;end =
(setq pagesetup "24x36MS")
) ;end if
(command ".-PLOT" "N"
;Detailed plot configuration? [Yes/No] <No>: N
"" ;Enter a layout name or [?] <Layout1>:
pagesetup
;Enter a page setup name <>:
"" ;Enter an output device name or [?] <current>:
"y" ;Write the plot to a file [Yes/No] <N>: y
file ;Enter file name <\\maverick\engineering\x5405\RCp01001-Layout1.PLT>:
"y" ;Save changes to page setup [Yes/No]? <N> n
"y" ;Proceed with plot [Yes/No] <Y>:
) ;end command
) ;end progn tfresult = 1
(progn ;if you wish not to plot directly to file
(initdia)
(command "_.PLOT")
) ;end progn
) ;end tfresult if
) ;end progn for ext /= nil
(progn ;no drawing property
(initdia)
(command "_.PLOT")
) ;end progn
) ;end if
)
) ;end progn for wcmatch f
) ;end progn for crosssections
;end progn for wcmatch f
) ;end if for wcmatch
) ;END PROGN
(progn
(initdia)
(command "_.PLOT")
) ;end progn
) ;END IF
(*error* "") ; reset sysvars
) ;end defun
Any suggestions to simplify the code would also be appreciated, I kind of get lost in the ()