See the top rated post in this thread. Click here

Results 1 to 10 of 10

Thread: Check if Custom Drawing Property exists

  1. #1
    Certifiable AUGI Addict ccowgill's Avatar
    Join Date
    2004-08
    Location
    Iron Station, NC
    Posts
    3,197
    Login to Give a bone
    0

    Default Check if Custom Drawing Property exists

    Is there a way to run a test to determine if a particular custom property exists. I am using this to modify my autoplot to file program, however if the custom property does not exist, I get an error and the drawing will not plot. I would like to be able to check if the property exists, and if it does not, open the plot dialog box.

    Thanks,
    Christopher T. Cowgill, P.E.
    Autodesk Expert Elite
    AEC Collection Civil 3D 2020
    Windows 10

  2. #2
    AUGI Addict kennet.sjoberg's Avatar
    Join Date
    2002-05
    Posts
    1,707
    Login to Give a bone
    0

    Default Re: Check if Custom Drawing Property exists

    Quote Originally Posted by ccowgill
    Is there a way to run a test to determine if a particular custom property exists. . .
    Probably yes, but you must know what to search for.
    In your case, what is custom property ?

    : ) Happy Computing !

    kennet

  3. #3
    AUGI Addict fixo's Avatar
    Join Date
    2005-05
    Location
    Pietari, Venäjä
    Posts
    1,269
    Login to Give a bone
    0

    Default Re: Check if Custom Drawing Property exists

    Huh!
    Kennet I am do not late today

    Code:
    (defun IsCustomExist (custom)		; string 
      (vl-load-com)
      (setq	acapp	(vlax-get-acad-object)
    	adoc	(vla-get-activedocument acapp)
    	docinfo	(vla-get-summaryinfo adoc)
      )
      (setq check nil)
    
      (if (and (eq 'str (type custom))
    	   (not (eq "" (vlax-get-property docinfo custom)))
          )
        (setq check T)
      )
    )
    
    ;Call (IsCustomExist "LastSavedBy")
    ~'J'~
    "The whole problem with the world is that fools and fanatics are always
    so certain of themselves, and wiser people so full of doubts."
    Bertrand Russell

  4. #4
    Certifiable AUGI Addict ccowgill's Avatar
    Join Date
    2004-08
    Location
    Iron Station, NC
    Posts
    3,197
    Login to Give a bone
    0

    Default Re: Check if Custom Drawing Property exists

    Quote Originally Posted by kennet.sjoberg
    Probably yes, but you must know what to search for.
    In your case, what is custom property ?

    : ) Happy Computing !

    kennet
    PLOTFILE is the custom property. It is not in a particular location so vla-getbyindex wont work
    Christopher T. Cowgill, P.E.
    Autodesk Expert Elite
    AEC Collection Civil 3D 2020
    Windows 10

  5. #5
    AUGI Addict kennet.sjoberg's Avatar
    Join Date
    2002-05
    Posts
    1,707
    Login to Give a bone
    0

    Default Re: Check if Custom Drawing Property exists

    Quote Originally Posted by ccowgill
    PLOTFILE is the custom property. It is not in a particular location so vla-getbyindex wont work
    Wasn’t that an answer to your question ?

    : ) Happy Computing !

    kennet

    BTW the default plotfile location is saved in the registry, not in the drawing.

  6. #6
    Certifiable AUGI Addict ccowgill's Avatar
    Join Date
    2004-08
    Location
    Iron Station, NC
    Posts
    3,197
    Login to Give a bone
    0

    Default Re: Check if Custom Drawing Property exists

    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 ()
    Christopher T. Cowgill, P.E.
    Autodesk Expert Elite
    AEC Collection Civil 3D 2020
    Windows 10

  7. #7
    Certifiable AUGI Addict ccowgill's Avatar
    Join Date
    2004-08
    Location
    Iron Station, NC
    Posts
    3,197
    Login to Give a bone
    0

    Default Re: Check if Custom Drawing Property exists

    I know this thread is kind of old, but I never really got a reply that worked. everything I have tried returns an error and stops processing, even the vl-catch-all-apply and error-p commands. I would like to have the program continue to process if the custom drawing property doesnt exist, maybe just display a message that the property doesnt exist. It isnt an issue in new drawings, just older drawing that havent had the custom drawing property added.
    Christopher T. Cowgill, P.E.
    Autodesk Expert Elite
    AEC Collection Civil 3D 2020
    Windows 10

  8. #8
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    8,672
    Login to Give a bone
    1

    Default Re: Check if Custom Drawing Property exists

    Not sure if this will work, but it is a shot. I renamed a couple of your variables so you will need to adjust this snippet to fit your needs.

    In place of this code:
    Code:
    (setq name "PLOTFILE")
    	(vla-GetCustomByKey DwgProps name 'ext)
    Try this:
    Code:
      (setq	KeyName	 "PLOTFILE"
    	KeyCount 0
    	KeyValue nil
      )
      (while (and (null KeyValue)
    	      (< KeyCount (vla-NumCustomInfo DwgProps))
    	 )
        (vla-GetCustomByIndex
          dwgprops
          KeyCount
          'TempKeyName
          'TempKeyValue
        )
        (if	(= TempKeyName KeyName)
          (setq KeyValue TempKeyValue)
        )
        (setq KeyCount (1+ KeyCount))
      )
    You need to find out if the Key is set. If it is not set you would get the error you describe. Instead of looking for the Key by it's name, I cycled through the custom keys.

    You may just be able to add this to the end of my above code to adjust the values to the appropriate variable name.
    Code:
    (setq ext KeyValue)
    If you have a technical question, please find the appropriate forum and ask it there.
    You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
    jUSt

  9. #9
    Certifiable AUGI Addict ccowgill's Avatar
    Join Date
    2004-08
    Location
    Iron Station, NC
    Posts
    3,197
    Login to Give a bone
    0

    Default Re: Check if Custom Drawing Property exists

    that worked great, it wasnt a big issue, but any good code doesnt produce an error to the command line, and now, mine doesnt. Thanks again.
    Christopher T. Cowgill, P.E.
    Autodesk Expert Elite
    AEC Collection Civil 3D 2020
    Windows 10

  10. #10
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    8,672
    Login to Give a bone
    0

    Default Re: Check if Custom Drawing Property exists

    No problem.
    If you have a technical question, please find the appropriate forum and ask it there.
    You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
    jUSt

Similar Threads

  1. 2004: Autocad 2004 - Insert a "Custom Property" in the drawing ?
    By Dubweisertm in forum AutoCAD General
    Replies: 7
    Last Post: 2013-09-18, 04:09 PM
  2. Replies: 0
    Last Post: 2011-12-09, 02:57 PM
  3. Visual Lisp Help - Check if URL Exists
    By caddog71 in forum AutoLISP
    Replies: 13
    Last Post: 2010-10-19, 02:18 AM
  4. Check Standards Property: Implementation (not fixable)
    By sanderson.59642 in forum AutoCAD General
    Replies: 5
    Last Post: 2008-06-12, 09:56 PM
  5. Check to see if file exists
    By ccowgill in forum AutoLISP
    Replies: 11
    Last Post: 2006-04-10, 09:12 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •