PDA

View Full Version : vla-getattributes does not pull all the attributes



abdulhuck
2015-08-23, 07:46 AM
Hi all,

I am back to AutoCAD and AUGI after a few years. I am trying to accomplish a task using a small VLisp routine. The problem I am facing is that if the attribute locations are manually moved using the grip, (vla-getattribute function skips the invisible attributes. Here is the code that I am using:



(if (= (vla-get-hasattributes blkobj) :vlax-true)
(progn
(setq atts
(vlax-variant-value
(vla-getattributes blkobj)
)
)
(foreach tag (vlax-safearray->list atts)
(if (= (strcase (vla-get-tagstring tag)) "REF_ID")
(vla-put-TextString tag refId)
)
)
)
)


It works with the same block, if the attribute location is not edited. Has anyone come across this situation? I am using AutoCAD 2012. Many thanks for your help!

Regards
Abdul

Tharwat
2015-08-23, 08:07 AM
Hi,

Actually it should work even if the attribute text string is moved , rotated or whatever , so can you upload a sample drawing showing your goal of the codes ?

abdulhuck
2015-08-23, 09:19 AM
Ok, I have Process drawings which shows the piping and instrumentation; I need to populate the handle of a piping tag block to an invisible attribute of the instrument blocks. A sample drawing is attached for your reference. The complete code is below:



(defun c:refid (/ blksel count numsel blkent blkobjw
atts tag lineId lineObj tagVal lineTag
)
(setq lineid (entget (car (entsel "\nPick reference line number:"))))
(if (and lineId (= (cdr (assoc 2 lineId)) "PPG030"))
(progn
(setq refId (cdr (assoc 5 lineId))) ; RefID is the handle of the line number (eg: 2"-D 39XXX-3XXXX)
(if (= (cdr (assoc 2 lineid)) "PPG030")
(progn
(setq
lineObj (vlax-ename->vla-object (cdr (assoc -1 lineid)))
)
(if (= (vla-get-hasattributes lineObj) :vlax-true)
(progn
(setq atts
(vlax-variant-value
(vla-getattributes lineObj)
)
)
(foreach tag (vlax-safearray->list atts)
(setq tagval (vla-get-textstring tag))
(if lineTag
(setq lineTag (strcat linetag "-" tagval))
(setq lineTag (strcat tagval))
)
)
(setq lineTag (vl-string-right-trim "-" lineTag))
)
)
)
(princ "\nNo valid line reference found!")
)
(princ
(strcat "\nSelect Instruments to link to <" lineTag ">: ")
)
(setq blksel (ssget (list (cons 0 "INSERT"))))
(if blksel
(progn
(setq count 0
numsel (sslength blksel)
)
(while (> numsel count)
(setq blkent (ssname blksel count)
blkobj (vlax-ename->vla-object blkent)
)
(if (= (vla-get-hasattributes blkobj) :vlax-true)
(progn
(setq atts
(vlax-variant-value
(vla-getattributes blkobj)
)
)
(foreach tag (vlax-safearray->list atts) ; All the Instrument blocks have an invisible "REF_ID" attribute; the
(if (= (strcase (vla-get-tagstring tag)) "REF_ID") ; the attribute value shall be handle of block PPG030
(vla-put-TextString tag refId)
)
)
)
)
(setq count (1+ count))
)
)
(princ "\nNo valid blocks found.")
)
)
)
)


The two invisible attributes are not listed in some instrument bubbles even if it is there... if we explode the block the attributes are seen. If I sync the blocks using battman, the routine works fine, but then it will move back all the relocated attributes, so I don't want to do that.
Hope the information is sufficient... thanks for your response!

Regards
Abdul

Tharwat
2015-08-23, 11:21 AM
The program works here and it DOES write the refid value into the invisible attribute that has the tag name ref_id .
If you want to show the value , so you need to set the property of the invisible attribute to YES .

abdulhuck
2015-08-23, 12:55 PM
Thanks Tharwat... for me, it writes in to some block, not to all of them... I don't want to display the value...

Tharwat
2015-08-23, 01:23 PM
have a look at the following video .

Tharwat
2015-08-24, 05:53 AM
Hi,

I have just rewritten the program in another way for you if you are interested of course .



(defun c:refid (/ s en id st vl v ss)
;; Tharwat 24.08.2015 ;;
(princ "\nPick reference line number < PPG030 > :")
(if
(and
(setq s (ssget "_+.:S:E" '((0 . "INSERT") (66 . 1) (2 . "PPG030"))))
(progn
(setq en (ssname s 0)
id (cdr (assoc 5 (entget en)))
st "-"
vl ""
)
(mapcar '(lambda (att)
(if (and (setq v (vla-get-textstring att)) (/= v ""))
(setq vl (strcat vl v st))
)
)
(vlax-invoke (vlax-ename->vla-object en) 'getattributes)
)
(setq vl (vl-string-right-trim "-" vl))
)
(princ (strcat "\nSelect Instruments to link to < " vl " >: ") )
(setq ss (ssget "_:L" '((0 . "INSERT") (66 . 1))))
)
((lambda (i / sn)
(while (setq sn (ssname ss (setq i (1+ i))))
(mapcar
'(lambda (x)
(if (= (strcase (vla-get-tagstring x)) "REF_ID")
(vla-put-textstring x id)
)
)
(vlax-invoke (vlax-ename->vla-object sn) 'getattributes)
)
)
)
-1
)
)
(princ)
) (vl-load-com)