Blocks added directly from tool pallete: Can not retrieve Information

Anonymous

Blocks added directly from tool pallete: Can not retrieve Information

Anonymous
Not applicable

Hello Everyone 

 

I have the following problem: If I add a block directly from an existing tool palette, it will not be added as a block reference and hence  I  cannot access it through vba. 

 

I have tried several methods including filtering selection sets and/or foreach looping  through thisdrawing.blocks etc. 

 

How could I solve this issue? 

 

HB. 

 

0 Likes
Reply
1,002 Views
3 Replies
Replies (3)

ed57gmc
Mentor
Mentor

Are you sure the tool is actually inserting a block? Some tools execute commands, etc. If the tool inserts a block, there is no other object that it would use, it would be an AcadBlockReference. You might want to post your code.

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

0 Likes

Anonymous
Not applicable

Hello Ed, 

Well im inserting blocks from a self made tool pallete in Plant P&ID.  Then I try to access them with the following code and retrieve the insertion point: ( I found the code on the Internet and modified it slightly) 

 

.........................................................................................................................................................

Public Sub test()
Dim sset As AcadSelectionSet
Dim ent As AcadEntity
Dim Book1 As Object
Dim Sheet1 As Object
Dim xlApp As Object
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
Set Book1 = xlApp.Workbooks.Add()
Set Sheet1 = Book1.worksheets(1)
Dim i As Integer

'Select all that are on the dup layer
On Error Resume Next
ThisDrawing.SelectionSets.Item("layer").Delete
On Error GoTo 0
Set sset = ThisDrawing.SelectionSets.Add("layer")
sset.Select acSelectionSetAll

Dim inPt As Variant

i = 1
For Each ent In sset
'Debug.Print ent.IsXRef
' inPt = ent.InsertionPoint
' End If
If TypeOf ent Is AcadBlockReference Then
Dim varAttributes As Variant
varAttributes = ent.GetAttributes


'Debug.Print "hello"
' Debug.Print ent.Name
If InStr(ent.EffectiveName, "$") = 0 Then
inPt = ent.InsertionPoint
Sheet1.Cells(i, 1) = inPt(0)
Sheet1.Cells(i, 2) = inPt(1)
Sheet1.Cells(i, 3) = ent.EffectiveName

Sheet1.Cells(i, 4) = ent.ObjectName

For t = 0 To UBound(varAttributes)
Debug.Print varAttributes(t).TagString
Next


i = i + 1

End If
End If
Next

End Sub

.........................................................................................................................................................

 

If I add a Block directly from my tool pallete I will not get it in the excel list. If however I add the Block as a Blockreference from the Insert tab  then  It will show up and I can get the Insertion Point.

 

 

HB.  

 

 

0 Likes

ed57gmc
Mentor
Mentor

So, you're inserting a block by clicking on a tool from a custom tool palette and then using VBARUN to execute your code? Can you post a dwg with a block that you inserted from your palette?

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

0 Likes