Ad

Monday, November 07, 2011

Select All Blocks in a Drawing

Occasionally I might want to get all of the blocks in a drawing using .NET. The way I accomplished this was to use the Selection Set sample code provided by Autodesk and then use the Typed value of “INSERT”. The insert is the start portion of the DxfCode for blocks.

    Private Sub GetBlockIdsBySelection()
'' Get the current document editor
Dim acDocEd As Editor = Application.DocumentManager.MdiActiveDocument.Editor
'' Create a TypedValue array to define the filter criteria
Dim acTypValAr(0) As TypedValue
acTypValAr.SetValue(New TypedValue(DxfCode.Start, "INSERT"), 0)
'' Assign the filter criteria to a SelectionFilter object
Dim acSelFtr As SelectionFilter = New SelectionFilter(acTypValAr)
'' Request for objects to be selected in the drawing area
Dim acSSPrompt As PromptSelectionResult
acSSPrompt = acDocEd.GetSelection(acSelFtr)
'' If the prompt status is OK, objects were selected
If acSSPrompt.Status = PromptStatus.OK Then
Dim acSSet As SelectionSet = acSSPrompt.Value
'Application.ShowAlertDialog("Number of objects selected: " & _
' acSSet.Count.ToString())
For Each objId As ObjectId In acSSet.GetObjectIds
m_BlockList.Add(objId)
Next
End If

End Sub



m_BlockList is a collection of ObjectId’s that I use elsewhere in the code. I use a list so I can remove items from the list or add to it later. There isn’t much flexibility adding or removing items from a SelectionSet.

No comments:

LinkWithin

Blog Widget by LinkWithin

Ad