Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Need a help to make a VLA-Object Collections

2 REPLIES 2
Reply
Message 1 of 3
pcmanojkumar
438 Views, 2 Replies

Need a help to make a VLA-Object Collections

Hi all,

 

Any one knows how we can make a Vla-Object Collections. is it possible to add one object by one object to make a collection.

 

Here is my codes.

 

(defun TblkAttBlkFnd (/ HCollAttblocks ACDVlaObjName NameOfAttBlk CmpAttObjLst SgnRefObjs PromptString ExtValAtrib)
    (if (setq HCollAttblocks (ssget "X" '((0 . "INSERT")
           (-4 . "<OR")
                              (2 . "ALXX-TBSD TBLOCK*")
                             (2 . "ALXX-ASDF-TBLK-?")
                             (2 . "ALXX-KEOS-TBLK-?")
                         (-4 . "OR>")))
       )
 (if (= (sslength HCollAttblocks) 1)
     (progn
               (setq ACDVlaObjName (vlax-ename->vla-object (ssname HCollAttblocks 0)) ExtValAtrib '())
        (setq NameOfAttBlk (vla-get-name ACDVlaObjName))
         (if (= (vla-get-hasattributes ACDVlaObjName) :vlax-true)
                (setq CmpAttObjLst (vlax-safearray->list (variant-value (vla-getattributes ACDVlaObjName))))
         )
        (setq AcBlkInDtbase (vla-item (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))) NameOfAttBlk))
  (if AcBlkInDtbase
      (progn
      (setq AcBlkInDtbase (safearray-value (variant-value (vla-getattributes  ACDVlaObjName))) item 0)
      (foreach SgnRefObjs AcBlkInDtbase
   (setq AcBlkInDtbase1 (vla-add SgnRefObjs (1+ item) AcBlkInDtbase1)))))     
           (foreach SgnRefObjs CmpAttObjLst
                    (vlax-for PromptString AcBlkInDtbase
                      (if (= (vla-get-objectname PromptString ) "AcDbAttributeDefinition" )
                         (if (= (vla-get-tagstring SgnRefObjs ) (vla-get-tagstring PromptString))
                          (progn
         (setq ExtValAtrib (append ExtValAtrib (list (list (vla-get-tagstring SgnRefObjs)
                     (vla-get-promptstring PromptString)
                     (vla-get-textstring SgnRefObjs)))))
         )
        )
     )
   )
        )
       )
     )
 )
    )

2 REPLIES 2
Message 2 of 3
pbejse
in reply to: pcmanojkumar


@pcmanojkumar wrote:

Hi all,

 

Any one knows how we can make a Vla-Object Collections. is it possible to add one object by one object to make a collection.

 


What are you trying to "collect"?

Message 3 of 3
dbroad
in reply to: pcmanojkumar

>>is it possible to add one object by one object to make a collection?

 

No.  You must have the collection first and then add objects to the collection.  Like your previous response, the question that should be more obvious in your code is "What is its purpose".  You are obviously looking for a single titleblock in the file and are collecting the attributes.  What do you want to do with them?  Are you trying to change them?, Document them?, create a new Titleblock?.  What makes this code particularly horrible is that you have no comments.  You have also mangled the naming so the names don't really refer to what is being assigned.

 

I hope the following comments help.  After this point, I stopped reading it.

 

HCollAttblocks is not a collection but a selection set.
ACDVlaObjName is not a name but a vla-object. (edit:  Your insert object, your titleblock).
ExtValAtrib is already nil as a local variable and does not need to be reset as '().
NameOfAttBlk is actually a name of the insert. If that object happens to be a dynamic block, it will return the anonymous name. If you want the name of the dynamic block, use vla-get-effectivename.
CmpAttObjList would probably have been easier to obtain by (vlax-invoke ACDVlaObjName 'getattributes). It returns a list rather than a variant.
AcBlkInDtbase (if it exists, which is certain and need not be tested, it will be replaced by a safearray-value of variant-value of the variant returned by getattributes which is similar to what you already have in CmpAttObjList. At that point the variable name doesn't follow.
SngRefObjs: In the foreach, SngRefObjs is an attribute object (one of the list of attributes.) The add method only works if the first argument is a collection (a block object, like modelspace or paperspace or other defined block or another collection like a layer or block collection). (vla-add collection object ....other data unique to the add).


Architect, Registered NC, VA, SC, & GA.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost