Insert Block event

Insert Block event

grobnik
Collaborator Collaborator
1,279 Views
4 Replies
Message 1 of 5

Insert Block event

grobnik
Collaborator
Collaborator

Hi to everybody,

is there a way by VBA to trap the inserting block event ? I need to trap the event, and later identify the block inserted name for doing some other thing.

 

Thank you

0 Likes
Accepted solutions (2)
1,280 Views
4 Replies
Replies (4)
Message 2 of 5

grobnik
Collaborator
Collaborator

Sorry If AutoReply

I tried this simple code, and I inserted a block with attributes.

 

Private Sub AcadDocument_ObjectAdded(ByVal Object As Object)
    Debug.Print "PIPPI"
End Sub

 

The event has been trapped but I'm not able to evaluate the  Type Of Object inserted, see image below

grobnik_0-1625501995819.png

 

0 Likes
Message 3 of 5

Ed__Jobe
Mentor
Mentor
Accepted solution

 

Private Sub AcadDocument_ObjectAdded(ByVal Object as Object)
    If TypeOf Object Is AcadBlockReference Then
        'Save block.Name or ID, etc.
        Dim blkRef as AcadBlockReference
        Set blkRef = Object
        SaveSetting appname, section, key, blkRef.Name
    End If
End Sub

 

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

Message 4 of 5

grobnik
Collaborator
Collaborator

Thank you Ed,

could you help me understanding the reasons because in my previous code the object count was zero, and now it's trapped ?

Thank you

0 Likes
Message 5 of 5

Ed__Jobe
Mentor
Mentor
Accepted solution

It's simply that when you took your screenshot, the object type was a dictionary, not a blockref. This event is going to fire for every single object that gets added to the database, not just graphical entities.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature