Jump to content

Recommended Posts

Posted

How to select blocks by (block)name in the Model Space with VBA?

Posted

Thx,

 

And How to create Acad Selection Sets by block name?

Posted

Creating a filtered selection set of all the BlockReferences of a particular name would look something like this:

 

Sub GetNamedInserts()
  Dim entbref As AcadBlockReference
  Dim TempObjSS As AcadSelectionSet
  Dim intCode(2) As Integer
  Dim varData(2) As Variant
  Dim strName As String
  
     strName = ThisDrawing.Utility.GetString(0, "Enter Block name to select: ")

     SSInit
     Set TempObjSS = ThisDrawing.SelectionSets.Add("TempSSet")
     intCode(0) = 0: varData(0) = "Insert"
     intCode(1) = 67: varData(1) = 0
     intCode(2) = 2: varData(2) = strName
     TempObjSS.Select acSelectionSetAll, , , intCode, varData
     MsgBox "There are " & TempObjSS.Count & " inserts referencing " & strName & " in Modelspace"
End Sub


Sub SSInit()
Dim SSS As AcadSelectionSets
Dim SS As AcadSelectionSet
  Set SSS = ThisDrawing.SelectionSets
     If SSS.Count > 0 Then
        For Each SS In SSS
           If SS.Name = "TempSSet" Then
              SS.Delete
              Exit For
           End If
        Next
     End If
End Sub  

 

 

Also be aware that filter data can also include wildcard characters to allow for broader selection. So, for instance, if the filter was:

 

intCode(2) = 2: varData(2) = strName & "*"

 

and strName was “Block”, then the selection set would include inserts referencing “Block1”, “Block2”, “Block3”, etc.

Posted

Aren't we able to do this with filter or QSELECT?

Posted
Aren't we able to do this with filter or QSELECT?

 

Absolutely.

 

Conceivably, though, a useful VBA routine would process the selection set beyond just returning the count.:)

Posted
Creating a filtered selection set of all the BlockReferences of a particular name would look something like this:

 

Sub GetNamedInserts()
  Dim entbref As AcadBlockReference
  Dim TempObjSS As AcadSelectionSet
  Dim intCode(2) As Integer
  Dim varData(2) As Variant
  Dim strName As String
  
     strName = ThisDrawing.Utility.GetString(0, "Enter Block name to select: ")

     SSInit
     Set TempObjSS = ThisDrawing.SelectionSets.Add("TempSSet")
     intCode(0) = 0: varData(0) = "Insert"
     intCode(1) = 67: varData(1) = 0
     intCode(2) = 2: varData(2) = strName
     TempObjSS.Select acSelectionSetAll, , , intCode, varData
     MsgBox "There are " & TempObjSS.Count & " inserts referencing " & strName & " in Modelspace"
End Sub


Sub SSInit()
Dim SSS As AcadSelectionSets
Dim SS As AcadSelectionSet
  Set SSS = ThisDrawing.SelectionSets
     If SSS.Count > 0 Then
        For Each SS In SSS
           If SS.Name = "TempSSet" Then
              SS.Delete
              Exit For
           End If
        Next
     End If
End Sub  

Also be aware that filter data can also include wildcard characters to allow for broader selection. So, for instance, if the filter was:

 

intCode(2) = 2: varData(2) = strName & "*"

 

and strName was “Block”, then the selection set would include inserts referencing “Block1”, “Block2”, “Block3”, etc.

 

Thx,

 

And how to Zoom to the selected Block in the ModelSpace?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...