Extracting attributes from block definitions

Discussion in 'AutoCAD' started by stevej, Apr 1, 2005.

  1. stevej

    stevej Guest

    Hello all,

    I want to extract atrributes from all block definitions in a drawing, via ObjectDBX. How would I get a collection of definitions (rather than a collection of blocks) vla-stylee??

    TIA

    Steve
     
    stevej, Apr 1, 2005
    #1
  2. stevej

    stevej Guest

    Sorry,

    Collection of Block REFERENCES, not definitions.
    Then I can extract the attributes via (getattributes)
     
    stevej, Apr 1, 2005
    #2
  3. stevej

    Jürg Menzi Guest

    Hi Steve

    This code should help you:
    Code:
    (defun MeGetAllAtts ( / AttLst CurEnt CurObj CurSet)
    (if (setq CurSet (ssget "X" '((0 . "INSERT") (66 . 1))))
    (while (setq CurEnt (ssname CurSet 0))
    (setq CurObj (vlax-ename->vla-object CurEnt)
    AttLst (cons (MeGetAtts CurObj) AttLst)
    )
    (ssdel CurEnt CurSet)
    )
    )
    AttLst
    )
    ;
    ; == Function MeGetAtts
    ; Reads all attribute values from a block
    ; Arguments [Typ]:
    ;   Obj = Object [VLA-OBJECT]
    ; Return [Typ]:
    ;   > Dotted pair list '(("Tag1" . "Val1")...) [LIST]
    ; Notes:
    ;   None
    ;
    (defun MeGetAtts (Obj)
    (mapcar
    '(lambda (Att)
    (cons
    (vla-get-TagString Att)
    (vla-get-TextString Att)
    )
    )
    (vlax-invoke Obj 'GetAttributes)
    )
    )
    
    Cheers
     
    Jürg Menzi, Apr 1, 2005
    #3
  4. stevej

    Jeff Mishler Guest

    Hi Jürg,
    Note that the OP said they were wanting to use ObjectDBX. Selection sets
    cannot be used in this case.

    Steve,
    Using a method similar to what Jürg posted is the only way. I'd would "For
    Each" the Blocks collection looking for those whose IsLayout property =
    True, then "For Each" through those looking for those BlockRefs of interest.
    From here you should be able to apply what Jürg supplied.
     
    Jeff Mishler, Apr 1, 2005
    #4
  5. stevej

    stevej Guest

    Jurg,

    Unless I'm missing the point, I can't use ssget to extract info from a dbx object? If there is a way that would solve my problem. Failing that is there another way to extract the info?

    Steve
     
    stevej, Apr 1, 2005
    #5
  6. stevej

    Jürg Menzi Guest

    Hi Steve

    Sorry, I overlooked the point with ObjectDbx.
    Thats correct...
    As Jeff pointed out, stepping through the collection(s):
    Code:
    (vlax-for Obj (vla-get-ModelSpace DbxDoc) ;(PaperSpace)
    (if (and
    (= (vla-get-ObjectName Obj) "AcDbBlockReference")
    (vla-get-HasAttributes Obj)
    )
    (setq AttLst (cons (MeGetAtts Obj) AttLst))
    )
    )
    
    Cheers
     
    Jürg Menzi, Apr 1, 2005
    #6
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.