Drawing Utilities > Drawing Properties

Drawing Utilities > Drawing Properties

Anonymous
Not applicable
1,732 Views
18 Replies
Message 1 of 19

Drawing Utilities > Drawing Properties

Anonymous
Not applicable

Hi

 

I am trying add (vl-filename-base (getvar "dwgname"))) in below list, please help on this.

 

(defun c:dProps (/ dProps dProp)

(vl-load-com)

(setq acadObject (vlax-get-acad-object))

(setq acadDocument (vla-get-ActiveDocument acadObject))


   ;;Get the SummaryInfo

   (setq dProps (vlax-get-Property acadDocument 'SummaryInfo))
 


  
   ;;Add an entry to the "Custom" tab

   (vla-addcustominfo dProps "CONSULTANT" "DEWAN ARCHITECTS & ENGINEERS")
   (vla-addcustominfo dProps "DRAWING NUMBER" "(vl-filename-base (getvar "dwgname")))")
   (vla-addcustominfo dProps "DATE" "24/01/2016")
   (vla-addcustominfo dProps "REVISION NUMBER" "0")
   (vla-addcustominfo dProps "SITE LOCATION" "ABU DHABI REEM ISLAND SECTOR RR1 PLOT C5")

   (command "-layout" "rename" "" (vl-filename-base (getvar "dwgname")))

 

   (princ)

)

0 Likes
Accepted solutions (1)
1,733 Views
18 Replies
Replies (18)
Message 2 of 19

hmsilva
Mentor
Mentor

Try

 

(defun c:dProps (/ dProps dProp)

   (vl-load-com)

   (setq acadObject (vlax-get-acad-object))
   (setq acadDocument (vla-get-ActiveDocument acadObject))

   ;;Get the SummaryInfo

   (setq dProps (vlax-get-Property acadDocument 'SummaryInfo))

   ;;Add an entry to the "Custom" tab

   (vla-addcustominfo dProps "CONSULTANT" "DEWAN ARCHITECTS & ENGINEERS")
   (vla-addcustominfo dProps "DRAWING NUMBER" (vl-filename-base (getvar "dwgname")))
   (vla-addcustominfo dProps "DATE" "24/01/2016")
   (vla-addcustominfo dProps "REVISION NUMBER" "0")
   (vla-addcustominfo dProps "SITE LOCATION" "ABU DHABI REEM ISLAND SECTOR RR1 PLOT C5")

   (command "-layout" "rename" "" (vl-filename-base (getvar "dwgname")))

   (princ)
   
)

 

Hope this helps,
Henrique

EESignature

0 Likes
Message 3 of 19

Anonymous
Not applicable

Hi

 

Still showing ; error: Automation Error. Duplicate key

0 Likes
Message 4 of 19

hmsilva
Mentor
Mentor
Accepted solution

@Anonymous wrote:

Hi

 

Still showing ; error: Automation Error. Duplicate key


You are trying to add a new key, if already exists, will error...

You'll have to test if exist, the add or set Custom....

 

Or, simply remove custom infos before adding new ones...

 

(defun c:dProps (/ dProps dProp)

   (vl-load-com)

   (setq acadObject (vlax-get-acad-object))
   (setq acadDocument (vla-get-ActiveDocument acadObject))

   ;;Get the SummaryInfo

   (setq dProps (vlax-get-Property acadDocument 'SummaryInfo))

   ;; remove custom infos
   (repeat (setq n (vla-NumCustomInfo dProps))
      (vla-RemoveCustomByIndex dProps (setq n (1- n)))
   )

   ;;Add an entry to the "Custom" tab
   (vla-addcustominfo dProps "CONSULTANT" "DEWAN ARCHITECTS & ENGINEERS")
   (vla-addcustominfo dProps "DRAWING NUMBER" (vl-filename-base (getvar "dwgname")))
   (vla-addcustominfo dProps "DATE" "24/01/2016")
   (vla-addcustominfo dProps "REVISION NUMBER" "0")
   (vla-addcustominfo dProps "SITE LOCATION" "ABU DHABI REEM ISLAND SECTOR RR1 PLOT C5")

   (command "-layout" "rename" "" (vl-filename-base (getvar "dwgname")))

   (princ)

)

 

 

Hope this helps,
Henrique

EESignature

Message 5 of 19

Anonymous
Not applicable

Thanks....

0 Likes
Message 6 of 19

hmsilva
Mentor
Mentor

@Anonymous wrote:

Thanks....


You're welcome, snsdxb!
Glad I could help

Henrique

EESignature

0 Likes
Message 7 of 19

BeKirra
Advisor
Advisor

@hmsilva wrote:

@Anonymous wrote:

Hi

 

Still showing ; error: Automation Error. Duplicate key


You are trying to add a new key, if already exists, will error...

You'll have to test if exist, the add or set Custom....

Hope this helps,
Henrique


Hi Henrique / members,

I found this old thread and would like to know how to test if a key exists.

Thanks.

Please mark "Accept as Solution" and "Like" if my reply resolves the issue and it will help when others need helps.
= ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ =
A circle is the locus of a cursor, starting and ending at the same point on a plane in model space or in layout such that its distance from a given coordinates (X,Y) is always constant.
X² + Y² = C²
0 Likes
Message 8 of 19

hmsilva
Mentor
Mentor

@BeKirra wrote:
Hi Henrique / members,

I found this old thread and would like to know how to test if a key exists.

Thanks.


Hi BeKirra,

one way,

;; Change custom property
;; prop = custom property Name as a string
;; newvalue = New custom property Value as a string
;; usage (ch_info "Location Code" "123-XYZ")
(vl-load-com)
(defun ch_info (prop newvalue / a b proplst suminfo)
  (setq	suminfo	(vla-get-SummaryInfo
		  (vla-get-ActiveDocument (vlax-get-acad-object))
		)
  )
  (if (> (setq n (vla-NumCustomInfo suminfo)) 0)
    (repeat n
      (vla-GetCustomByIndex suminfo (setq n (1- n)) 'a 'b)
      (setq proplst (cons (list n a b) proplst))
    )
  )
  (if (vl-position prop (mapcar 'cadr proplst));<<< the test...
    (vla-SetCustomByKey suminfo prop newvalue)
  )
  (princ)
)

 

 

Hope this helps,
Henrique

EESignature

0 Likes
Message 9 of 19

BeKirra
Advisor
Advisor

Thanks Henrique.

It seems to work. But this line doesn't actually compare the user input and the existing key:

(vl-position prop (mapcar 'cadr proplst))

I know it will return the existing key postion value in the list if it is found.

How to rewrite it if I would like to compare the name of the existing key and user input?

Thanks for your help.

Please mark "Accept as Solution" and "Like" if my reply resolves the issue and it will help when others need helps.
= ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ =
A circle is the locus of a cursor, starting and ending at the same point on a plane in model space or in layout such that its distance from a given coordinates (X,Y) is always constant.
X² + Y² = C²
0 Likes
Message 10 of 19

hmsilva
Mentor
Mentor

@BeKirra wrote:

Thanks Henrique.

It seems to work. But this line doesn't actually compare the user input and the existing key:

(vl-position prop (mapcar 'cadr proplst))

I know it will return the existing key postion value in the list if it is found.

How to rewrite it if I would like to compare the name of the existing key and user input?

Thanks for your help.


You're welcome, BeKirra

 

If I understood...

 

;; Test custom property Name
;; prop = custom property Name as a string
;; usage (prop? "Property Name")
;; Return T if true, otherwise nil
(vl-load-com)
(defun prop? (prop / a b flag proplst suminfo)
  (setq	suminfo	(vla-get-SummaryInfo
		  (vla-get-ActiveDocument (vlax-get-acad-object))
		)
  )
  (if (> (setq n (vla-NumCustomInfo suminfo)) 0)
    (repeat n
      (vla-GetCustomByIndex suminfo (setq n (1- n)) 'a 'b)
      (setq proplst (cons (list n a b) proplst))
    )
  )
  (if (vl-position prop (mapcar 'cadr proplst))
    (setq flag T)
  )
    flag
)

 

Hope this helps,
Henrique

EESignature

0 Likes
Message 11 of 19

BeKirra
Advisor
Advisor

Thanks again.

I woulk like to know how to get a property name from the list.

For example, the format of the list of existing drawing property is:

((0 DWGprop_1 Value_1) (1 DWGprop_2 Value_2) (2 DWGprop_3 Value_3) …)

Supposed the name of "DWGprop_3" from the list is the same as user's input.

How do I take it out from the list so I can compare it with the user input? like:

(if (eq UserInput DWGprop_3)
…
)

 Thanks.

Please mark "Accept as Solution" and "Like" if my reply resolves the issue and it will help when others need helps.
= ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ =
A circle is the locus of a cursor, starting and ending at the same point on a plane in model space or in layout such that its distance from a given coordinates (X,Y) is always constant.
X² + Y² = C²
0 Likes
Message 12 of 19

hmsilva
Mentor
Mentor

@BeKirra wrote:

Thanks again.

I woulk like to know how to get a property name from the list.

For example, the format of the list of existing drawing property is:

((0 DWGprop_1 Value_1) (1 DWGprop_2 Value_2) (2 DWGprop_3 Value_3) …)

Supposed the name of "DWGprop_3" from the list is the same as user's input.

How do I take it out from the list so I can compare it with the user input? like:

(if (eq UserInput DWGprop_3)
…
)

 Thanks.


BeKirra,

with the 'prop?' function, we can test if the UserInput is one of the propreties Name.

 

_$ (setq UserInput (getstring))
"DWGprop_3"
_$ (prop? UserInput)
T

 

But if you need to get Name and Value from property...

Perhaps something like this...

 

;; Get custom property Index, Name and Value
;; prop = custom property Name as a string
;; usage (prop? "Property Name")
;; Return a list with three elements
;; nth 0 the property Index
;; nth 1 the property Name
;; nth 2 the property Value
;; otherwise nil
(vl-load-com)
(defun get_prop (prop / a b proplst result suminfo)
  (setq	suminfo	(vla-get-SummaryInfo
		  (vla-get-ActiveDocument (vlax-get-acad-object))
		)
  )
  (if (> (setq n (vla-NumCustomInfo suminfo)) 0)
    (repeat n
      (vla-GetCustomByIndex suminfo (setq n (1- n)) 'a 'b)
      (setq proplst (cons (list n a b) proplst))
    )
  )
  (if (setq result (vl-member-if (function (lambda (a) (equal (cadr a) UserInput))) proplst))
    (setq result (car result))
  )
    result
)

 

Test...

 

_$ (setq UserInput "DWGprop_3")
"DWGprop_3"
_$ (get_prop UserInput)
(2 "DWGprop_3" "789")
_$ 

 

Hope this helps,
Henrique

EESignature

Message 13 of 19

BeKirra
Advisor
Advisor

Incredible. It works great!

I have tried to use "vl-member-if" without success.

Thanks again for your help.

Please mark "Accept as Solution" and "Like" if my reply resolves the issue and it will help when others need helps.
= ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ =
A circle is the locus of a cursor, starting and ending at the same point on a plane in model space or in layout such that its distance from a given coordinates (X,Y) is always constant.
X² + Y² = C²
0 Likes
Message 14 of 19

BeKirra
Advisor
Advisor

Another question:

It seems the name of property in the "dwgprops" pop-up is case sensitive.

For example, if there is an existing name of "Sales", the user input has to be exactly the same. All other cases (i.e. "sales", "SALES", etc) this line will return "nil":

(vl-member-if (function (lambda (a) (equal (cadr a) UserInput))) proplst)

How to fix it? Thanks.

 

Please mark "Accept as Solution" and "Like" if my reply resolves the issue and it will help when others need helps.
= ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ =
A circle is the locus of a cursor, starting and ending at the same point on a plane in model space or in layout such that its distance from a given coordinates (X,Y) is always constant.
X² + Y² = C²
0 Likes
Message 15 of 19

hmsilva
Mentor
Mentor

@BeKirra wrote:

Incredible. It works great!

I have tried to use "vl-member-if" without success.

Thanks again for your help.


You're welcome, BeKirra!
Glad I could help

 


@BeKirra wrote:

Another question:

It seems the name of property in the "dwgprops" pop-up is case sensitive.

For example, if there is an existing name of "Sales", the user input has to be exactly the same. All other cases (i.e. "sales", "SALES", etc) this line will return "nil":

(vl-member-if (function (lambda (a) (equal (cadr a) UserInput))) proplst)

How to fix it? Thanks.

 


 Try

 

(vl-member-if (function (lambda (a) (equal (strcase (cadr a)) (strcase UserInput)))) proplst)

 

Hope this helps,
Henrique

EESignature

Message 16 of 19

BeKirra
Advisor
Advisor

Try

(vl-member-if (function (lambda (a) (equal (strcase (cadr a)) (strcase UserInput)))) proplst)

Hope this helps,
Henrique


Brilliant! I have never thought this:

(strcase (cadr a))

 Thanks for your help.

 

Just another thought after learning from your code:

What if I want to get the value from an attribute in a block?

It would be much appreciated if you can give more helps.

 

Here is a case.

For example, there are couple of attributes in an existing block "Block_ABC":

Attribute_1: Tag = "Tag_1", Prompt (Value) = "TagValue_1"

Attribute_2: Tag = "Tag_2", Prompt (Value) = "TagValue_2"

Attribute_3: Tag = "Tag_3", Prompt (Value) = "TagValue_3"

…,

etc

 

How to

1) get the value from "Attribute_3", then

2) allow user change the value if needed?

(Assuming all the names of attribute tag are known.)

Please mark "Accept as Solution" and "Like" if my reply resolves the issue and it will help when others need helps.
= ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ =
A circle is the locus of a cursor, starting and ending at the same point on a plane in model space or in layout such that its distance from a given coordinates (X,Y) is always constant.
X² + Y² = C²
0 Likes
Message 17 of 19

hmsilva
Mentor
Mentor

@BeKirra wrote:

Try

(vl-member-if (function (lambda (a) (equal (strcase (cadr a)) (strcase UserInput)))) proplst)

Hope this helps,
Henrique


Brilliant! I have never thought this:

(strcase (cadr a))

 Thanks for your help.

 

Just another thought after learning from your code:

What if I want to get the value from an attribute in a block?

It would be much appreciated if you can give more helps.

 

Here is a case.

For example, there are couple of attributes in an existing block "Block_ABC":

Attribute_1: Tag = "Tag_1", Prompt (Value) = "TagValue_1"

Attribute_2: Tag = "Tag_2", Prompt (Value) = "TagValue_2"

Attribute_3: Tag = "Tag_3", Prompt (Value) = "TagValue_3"

…,

etc

 

How to

1) get the value from "Attribute_3", then

2) allow user change the value if needed?

(Assuming all the names of attribute tag are known.)


You're welcome, BeKirra!

 

To get a list with TAGS and VALUES

;; enm = VLA-OBJECT or ENAME
;; (get_atts enm)
(defun get_atts (enm / att obj)
  (if (or (and (eq (type enm) 'ENAME)
               (setq obj (vlax-ename->vla-object enm))
               (eq (vla-get-hasattributes obj) :vlax-true)
          )
          (and (eq (type enm) 'VLA-OBJECT)
               (setq obj enm)
               (eq (vla-get-hasattributes obj) :vlax-true)
          )
      )
    (mapcar
      '(lambda (att)
         (cons (vla-get-TagString att) (vla-get-TextString att))
       )
      (vlax-invoke obj "GetAttributes")
    )
  )
)

 

to change specific TAG value

 

;; obj = VLA-OBJECT or ENAME
;; tag = the tag as a STRING
;; newstr = the new VALUE as a string
;; usage
;; (ed_att obj "tagname" "NewValue")
(defun ed_att (obj tag newstr / atts)
  (cond ((and (eq (type tag) 'STR)
              (eq (type newstr) 'STR)
              (or (eq (type obj) 'ENAME)
                  (eq (type obj) 'VLA-OBJECT)
              )
         )
         (if (eq (type obj) 'ENAME)
           (setq obj (vlax-ename->vla-object obj))
         )
         (if (and (eq (vla-get-objectname obj) "AcDbBlockReference")
                  (eq (vla-get-hasattributes obj) :vlax-true)
                  (vlax-write-enabled-p obj)
                  (setq atts (vlax-invoke obj "GetAttributes"))
             )
           (foreach att atts
             (if (eq (vla-get-tagstring att) (strcase tag))
               (vla-put-textstring att newstr)
             )
           )
         )
        )
  )
)

 

Hope this helps,
Henrique

EESignature

0 Likes
Message 18 of 19

BeKirra
Advisor
Advisor

Sorry, I tried but no success. Here is the code to change a tag value in block:

What is wrong?

 

(defun c:Test (/ ss obj TagName NewValue)
(if (princ "\nSelect a block: ")
(setq ss (ssget "_:S:E" '((0 . "INSERT") (2 . "BlockName")))) ; change "BlockName" to yours
)
(setq obj (vlax-ename->vla-object (ssname ss 0)))
(setq TagName "TAG") ; "TAG" is a tag name in your block.
(setq NewValue "123") ; to set new value "123" to "TAG".
(defun ed_att (obj tag newstr / atts)
  (cond ((and (eq (type tag) 'STR)
              (eq (type newstr) 'STR)
              (or (eq (type obj) 'ENAME)
                  (eq (type obj) 'VLA-OBJECT)
              )
         )
         (if (eq (type obj) 'ENAME)
           (setq obj (vlax-ename->vla-object obj))
         )
         (if (and (eq (vla-get-objectname obj) "AcDbBlockReference")
                  (eq (vla-get-hasattributes obj) :vlax-true)
                  (vlax-write-enabled-p obj)
                  (setq atts (vlax-invoke obj "GetAttributes"))
             )
           (foreach att atts
             (if (eq (vla-get-tagstring att) (strcase tag))
               (vla-put-textstring att newstr)
             )
           )
         )
        )
  )
)
(ed_att (vla-get-effectivename obj) TagName NewValue)
(princ)
)
Please mark "Accept as Solution" and "Like" if my reply resolves the issue and it will help when others need helps.
= ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ =
A circle is the locus of a cursor, starting and ending at the same point on a plane in model space or in layout such that its distance from a given coordinates (X,Y) is always constant.
X² + Y² = C²
0 Likes
Message 19 of 19

hmsilva
Mentor
Mentor

Hi

try

 

(vl-load-com)
(defun c:Test (/ ed_att ss obj TagName NewValue)
   (defun ed_att (obj tag newstr / atts)
      (cond ((and (eq (type tag) 'STR)
                  (eq (type newstr) 'STR)
                  (or (eq (type obj) 'ENAME)
                      (eq (type obj) 'VLA-OBJECT)
                  )
             )
             (if (eq (type obj) 'ENAME)
                (setq obj (vlax-ename->vla-object obj))
             )
             (if (and (eq (vla-get-objectname obj) "AcDbBlockReference")
                      (eq (vla-get-hasattributes obj) :vlax-true)
                      (vlax-write-enabled-p obj)
                      (setq atts (vlax-invoke obj "GetAttributes"))
                 )
                (foreach att atts
                   (if (eq (vla-get-tagstring att) (strcase tag))
                      (vla-put-textstring att newstr)
                   )
                )
             )
            )
      )
   )

   (if (and (princ "\nSelect a block: ")
            (setq ss (ssget "_:S:E" '((0 . "INSERT") (2 . "BlockName")))) ; change "BlockName" to yours
       )
      (progn
         (setq obj (vlax-ename->vla-object (ssname ss 0)))
         (setq TagName "TAG") ; "TAG" is a tag name in your block.
         (setq NewValue "123") ; to set new value "123" to "TAG".
         ;; ed_att function, needs a VLA-OBJECT or an ENAME as obj argument...
         (ed_att obj TagName NewValue)
      )
   )
   (princ)
)

 

Hope this helps,
Henrique

EESignature

0 Likes