klpocska Posted March 1, 2010 Posted March 1, 2010 How to select blocks by (block)name in the Model Space with VBA? Quote
alanjt Posted March 1, 2010 Posted March 1, 2010 http://www.cadtutor.net/forum/showthread.php?t=25142 Quote
klpocska Posted March 2, 2010 Author Posted March 2, 2010 Thx, And How to create Acad Selection Sets by block name? Quote
SEANT Posted March 2, 2010 Posted March 2, 2010 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. Quote
edwinprakoso Posted March 2, 2010 Posted March 2, 2010 Aren't we able to do this with filter or QSELECT? Quote
SEANT Posted March 2, 2010 Posted March 2, 2010 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. Quote
klpocska Posted March 3, 2010 Author Posted March 3, 2010 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? Quote
SEANT Posted March 4, 2010 Posted March 4, 2010 Post #6 of this thread shows a method of zooming the view to a particular entity, based on that entity's bounding box. http://www.cadtutor.net/forum/showthread.php?t=42967 Quote
Recommended Posts
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.