need help to assign Enames to VLA-object

aridzv
edited January 2022 in LISP Codes
Hi.

I have a lisp that I need to assign an object to a VLA-Object (see attached code below) - see in the foreach loop,I'm trainig to assign a VLA object to obj2 variable.

I've read this article and follow the steps there.

I'm getting the Entity name in to the "enam" variable, but I'm failing to assign it to the VLA object.

the error I'm getting is this: ; error : Automation Error. Property [HASATTRIBUTES] not available

I also attached a sample drawing (EXP1.dwg) with 2 inserted blocks that I'm testing this lisp on it.

what I'm doing wrong in the code?

thanks'

Ari.

(defun c:add_SYS_ATT1 ( / ss i blk blks def AttObj obj2 tagname hh count)
(vl-load-com)
(setq tagname "SYSTEM")
(setq hh (atof "36"))
(and
(setq ss (ssget '((0 . "INSERT"))))
(setq i (sslength ss))
(while (> i 0)
(setq blk (cdr (assoc 2 (entget (ssname ss (setq i (1- i)))))))
(if (not (vl-position blk blks))(setq blks (cons blk blks)))
)
)
(foreach blk blks
(Vlax-for obj (setq def (vla-item (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))) blk)))
(setq enam (vlax-vla-object->ename def))
(princ enam)
(setq obj2 (vlax-ename->vla-object enam))
(setq count 0)
(princ obj2)
(
if (= (vla-get-hasattributes obj2) :vlax-true)
(foreach att (vlax-invoke obj2 'getattributes)
(if ( = tagname (strcase (vla-get-tagstring att)))
(setq count (1+ count))
);;close if
);;close foreach
);;close if
(princ count)
(
if (= count 0)
(progn
(setq AttObj
(vla-addattribute def
36
acAttributeModeInvisible
""
(vlax-3D-point 72 84)
"SYSTEM"
""
) ;;close vla-addattribute
) ;;close setq
(vlax-put AttObj 'Alignment acAlignmentmiddle)
(command "_.attsync" "_N" blk)
) ;;close progon
);;close if

);; close foreach
(princ)
)
(vl-load-com) (princ)

Comments

  • Comments also at Cadtutor.
  • @ALANH
    Thanks, I saw it.
    I opened another thread there and got detailed answers.
    I attach here the file containing the revised code with explanations included within it.
    Hope this will help others in the future as it has helped me.
    Ari.