Stumbled across this thread yesterday and found the code really useful. Thanks @CodeDing for pointing the code out, I wanted to throw my two cents in for potential quick improvements if anyone wants it.
-I have renamed the lisp "dwgpe" for dwg props edit.
-Edited so it's all in one program now with "export" and "import" options.
-I noticed when I used the above code it gets all of my properties correctly, stores them correctly, but when importing it reverses them. I have fixed this as well (it least on my end) so the new properties come in exactly as listed in order within the .prop file.
-I have also re-tabbed the whole code to make it easier to read.
cheers.
(defun c:dwgpe ( / dwgsel cdps path f str txt props )
(initget 1 "e i")
(setq dwgsel (getkword "\nSELECT DWGPROPS OPTION: [(E)xport/(I)mport] > "))
(cond
(
(eq dwgsel "e")
(vl-load-com)
(if
(and
(setq cdps (CDP-List))
(setq path (getfiled "\nSELECT FILE LOCATION AND NAME TO SAVE AS >" (getvar 'DWGPREFIX) "prop" 1))
)
(progn
(setq f (open path "w"))
(foreach cdp cdps
(write-line (car cdp) f)
(write-line (cdr cdp) f)
)
(close f)
(prompt (strcat "\nFILE CREATED >" path))
(setq str "\nEXPORT COMPLETE!")
(princ str)
)
(prompt "\nERROR: CUSTOM DRAWING PROPERTIES NOT FOUND OR INVALID FILE LOCATION.")
)
)
(
(eq dwgsel "i")
(vl-load-com)
(if
(setq path (getfiled "\nSELECT PROPERTIES IMPORT FILE >" (getvar 'DWGPREFIX) "prop" 0))
(progn
(setq cdps (CDP-List))
(if cdps (setq cdps (mapcar 'cons (mapcar 'strcase (mapcar 'car cdps)) (mapcar 'cdr cdps))))
(setq f (open path "r"))
(while
(setq txt (read-line f))
(cond
(
(and cdps (not (assoc (strcase txt) cdps)))
(setq props (append props (list (cons txt (read-line f)))))
)
(cdps (read-line f))
(t (setq props (append props (list (cons txt (read-line f))))))
)
)
(close f)
(foreach cdp props (CDP-Create (car cdp) (cdr cdp)))
(setq str "\nIMPORT COMPLETE!")
(princ str)
)
(prompt "\nERROR: NO PROPERTIES FILE SELECTED.")
)
)
)
(princ)
)
(defun CDP-Create ( key val / docProps return num keyVal propVal )
(vl-load-com)
(if
(and (eq 'STR (type key)) (eq 'STR (type val)))
(progn
(setq docProps (vla-get-SummaryInfo (vla-get-ActiveDocument (vlax-get-acad-object))))
(vla-AddCustomInfo docProps key val)
(cons key val)
)
)
)
(defun CDP-List ( / docProps cnt key val return )
(vl-load-com)
(setq docProps (vla-get-SummaryInfo (vla-get-ActiveDocument (vlax-get-acad-object))))
(repeat
(setq cnt (vla-NumCustomInfo docProps))
(vla-GetCustomByIndex docProps (setq cnt (1- cnt)) 'key 'val)
(setq return (cons (cons key val) return))
)
)