Create custom document property, if doesn't exist

Create custom document property, if doesn't exist

jlaidle1
Advocate Advocate
1,029 Views
2 Replies
Message 1 of 3

Create custom document property, if doesn't exist

jlaidle1
Advocate
Advocate

How can you have a custom document property created, if it doesn't exist with LISP?

 

Thanks.

 

John Laidler
ITO - Application Management


Please use "Accept as Solution" & give "Kudos" if this response helped you.

0 Likes
Accepted solutions (1)
1,030 Views
2 Replies
Replies (2)
Message 2 of 3

jlaidle1
Advocate
Advocate

This appears to be working, and also is not clearing out the property value if it already exists:

(vla-addcustominfo(vla-get-summaryinfo(vla-get-activedocument(Vlax-get-acad-object)))"Division" "")

John Laidler
ITO - Application Management


Please use "Accept as Solution" & give "Kudos" if this response helped you.

0 Likes
Message 3 of 3

CodeDing
Advisor
Advisor
Accepted solution

@jlaidle1,

 

While your method does work, it draws an error if that property already exists. IMO it would be best to check for that property first. Here's my take:

 

 

(defun c:test (/ newProp)
(vl-load-com)
(setq newProp "Division2")
(if (not (PropertyExists newProp))
  (vla-addcustominfo (vla-get-summaryinfo (vla-get-activedocument (Vlax-get-acad-object))) newProp "")
);if
(princ "\nComplete.")
(princ)
);defun

(defun PropertyExists (pName / sumInfo tmp eProp eVal)
;IN: pName - property name to search as string (NOT case sensitive)
;OUT: returns t if property exists, else nil
(setq sumInfo (vla-get-summaryinfo (vla-get-activedocument (Vlax-get-acad-object)))
      tmp 0)
(vla-GetCustomByIndex sumInfo tmp 'eProp 'eVal)
(while (and (not (eq (setq eProp (strcase eProp)) (setq pName (strcase pName)))) (< (+ tmp 1) (vla-numcustominfo sumInfo)))
(setq tmp (1+ tmp))
(vla-GetCustomByIndex sumInfo tmp 'eProp 'eVal)
);while
(if (eq eProp pName) t nil)
);defun

...should be pretty easy to edit as you wish. 

 

Best,

~DD

 

 

0 Likes