Using "vla-InsertBlock" To Insert a Block With a Single Attribute

Using "vla-InsertBlock" To Insert a Block With a Single Attribute

mgorecki
Collaborator Collaborator
4,428 Views
2 Replies
Message 1 of 3

Using "vla-InsertBlock" To Insert a Block With a Single Attribute

mgorecki
Collaborator
Collaborator

Hello, I found some code that will allow me to insert a block without using the "(command "insert".....) method because that caused the program to crash on some computers.

(vla-InsertBlock (vla-get-modelspace
     (vla-get-activedocument
      (vlax-get-acad-object)))
  (vlax-3d-point overallHorUnitDimLoc) "Note_Symbol" 1 1 1 0 )

The problem is, the block has an attribute but I don't know how to add the attribute to the vla-InsertBlock command (if it's even possible).

Can someone show me how to do this? 

The command I used to use is:

(command "insert" "Note_Symbol" overallHorUnitDimLoc "1" "1" "0" "4") where the "4" was the attribute value.

 

Thanks,

Mark

Accepted solutions (1)
4,429 Views
2 Replies
Replies (2)
Message 2 of 3

_gile
Consultant
Consultant
Accepted solution

Hi,

 

You have to get the Attribute collection of the newly inserted block reference, and as it contains only one attribute just get the first one of the list.

 

(setq block (vla-InsertBlock
              (vla-get-modelspace
                (vla-get-activedocument
                  (vlax-get-acad-object)
                )
              )
              (vlax-3d-point overallHorUnitDimLoc)
              "Note_Symbol"
              1
              1
              1
              0
            )
      )
;; get the block attributes
(setq attributes (vlax-safearray->list (vlax-variant-value (vla-getAttributes block))))
;; get the first attribute of the list to set its "value" (TextString property)
(vla-put-TextString (car attributes) "4")


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 3 of 3

mgorecki
Collaborator
Collaborator

That did the trick.  Thank you very much!

0 Likes