Author Topic: Get an attribute value to dwgprops  (Read 1301 times)

0 Members and 1 Guest are viewing this topic.

MeasureUp

  • Bull Frog
  • Posts: 462
Get an attribute value to dwgprops
« on: June 15, 2016, 02:07:10 AM »
By reading couple of posts, here is a code which I used for passing an attribute value from a block to "dwgprops".
But it doesn't look right.
What is wrong in the code? Thanks for your help.

Code: [Select]
(defun c:Test ()

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

(if (setq ss (ssget "_:S:E" '((0 . "INSERT") (2 . "BlockName")))) ; <= change "BlockName" to yours for testing
(progn (setq obj (vlax-ename->vla-object (ssname ss 0)))
   (if (eq (vla-get-effectivename obj) "BlockName") ; <= change "BlockName" to yours for testing
   (progn (get_att obj)
  (setq DwgCustomProperties (car (car (get_att obj)))) ; <= 1st attribute in the selected block
  (setq DwgCustomDescription (cdr (car (get_att obj))))
)
            )
    )
    (princ "\nSelect a block...")
)

(setq summaryinfo (vla-get-SummaryInfo (vla-get-ActiveDocument (vlax-get-acad-object))))

(vla-SetCustomByKey summaryinfo DwgCustomProperties DwgCustomDescription)

(princ)
); end

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Get an attribute value to dwgprops
« Reply #1 on: June 15, 2016, 03:28:41 AM »
The setcustombykey method assumes that the custom property corresponding to the supplied key already exists; if it doesn't, you will first need to use the addcustominfo method to create it.

MeasureUp

  • Bull Frog
  • Posts: 462
Re: Get an attribute value to dwgprops
« Reply #2 on: June 15, 2016, 09:27:22 PM »
Thanks Lee. It is informative.
But the following code seems to erase all existing keys in "dwgprops". How to avoid this?
Code: [Select]
(if (>= (vla-NumCustomInfo summaryInfo) 1)
(vla-SetCustomByIndex summaryInfo 0 CustomPropertyBranch PropertyBranchValue)
(vla-AddCustomInfo summaryInfo CustomPropertyBranch PropertyBranchValue)
)

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Get an attribute value to dwgprops
« Reply #3 on: June 16, 2016, 03:02:39 AM »
You should look at the order of the 'then' and 'else' expressions. Reverse them (or change the test expression). Or better still just use:
Code: [Select]
(vla-AddCustomInfo summaryInfo CustomPropertyBranch PropertyBranchValue)

MeasureUp

  • Bull Frog
  • Posts: 462
Re: Get an attribute value to dwgprops
« Reply #4 on: June 20, 2016, 02:14:10 AM »
Thanks for your tip. My code is now running perfectly.