.NET
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Filter Dynblockre ferences in selection
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hi
I have a problem with selecting all references to a specific dynamic block. When I use the filter below only block “D2” is selected, which is not a dynamic block, Block "Bulb120227” which is a dyn block is not
Dim values() As TypedValue = { _
New TypedValue(0, "INSERT"), _
New TypedValue(-4, "<OR"), _
New TypedValue(2, "D2"), _
New TypedValue(2, "Bulb120227"), _
New TypedValue(-4, "OR>") _
}
How should the filter be done to filter out the dyn block that I want several block should be filtered out in one selection.
If it is possible to achieve with just a filter at all?
With regards to you All
HansP
Re: Filter Dynblockre ferences in selection
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hi,
If the block is dynamic, you need to check against the effectivename of the block:
Public Shared Function GetEffectiveName(ByVal blkref As BlockReference, ByVal acTrans As transaction) As String
Dim btr As BlockTableRecord
btr = acTrans.GetObject(blkref.DynamicBlockTableRecord, OpenMode.ForRead)
Return btr.Name
End FunctionGaston Nunez
Re: Filter Dynblockre ferences in selection
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hi
I will try to explain what I am trying to accomplish
What I want is a command that selects all dynamic block references in a drawing
To do this my strategy is as follows
Stepping through the block collection finding all dynamic block definitions and their name
making the list on the format
Dim values() AsTypedValue = { _
NewTypedValue(0, "INSERT"), _
NewTypedValue(-4, "<OR"), _
NewTypedValue(2, "D2"), _
NewTypedValue(2, "H-Balk101026"), _
|
|
|
NewTypedValue(2, "H-Balk101036"), _
NewTypedValue(-4, "OR>") _
}
Then making the filtered selection
Dim sfilter As New SelectionFilter(values)
Dim res As PromptSelectionResult = ed.SelectAll(sfilter)
Doing like this all references to block ”D2”, which are not a dynamic are selected, but references to block "H-Balk101026" which are dynamic are not selected.
I get the same result if the filterlist are “hardcoded” or if program are building it.
With the list below, all blockreferences are selected dynamic and static
Dim values() AsTypedValue = { _
NewTypedValue(0, "INSERT"), _
}
How should the filter be sett upp, or the selection be done please HELP
HansP
Re: Filter Dynblockre ferences in selection
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Look at BlockTableRecord.GetBlockReferenceIds
and
BlockTableRecord.GetAnonymousBlockIds
Re: Filter Dynblockre ferences in selection
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hi,
I think you can't filter a priori by blockname, as the dynamic block goes anonimous if some of their dynamic properties is activated, so you must filter for generic, check if is dynamic, and then get the effective name like this:
Public Function CDBLx() As 'Something
Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
Dim acCurDb As Database = acDoc.Database
Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Edit or
Dim BlkList As New List(Of String)
BlkList.Add("BLK1")
BlkList.Add("BLK2")
BlkList.Add("BLK3")
Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
Dim acTypValAr(0) As TypedValue
acTypValAr.SetValue(New TypedValue(DxfCode.Start, "INSERT"), 0)
Dim acSelFtr As SelectionFilter = New SelectionFilter(acTypValAr)
Dim acSSPrompt As PromptSelectionResult
acSSPrompt = ed.SelectAll(acSelFtr)
If acSSPrompt.Status = PromptStatus.OK Then
Dim acSSet As SelectionSet = acSSPrompt.Value
For Each acSSObj As SelectedObject In acSSet
Dim blk As BlockReference = acSSObj.ObjectId.GetObject(OpenMode.ForRead)
If blk.IsDynamicBlock Then
If BlkList.Contains(GetEffectiveName(blk, acTrans).ToUpper) Then
'Do Something here...
End If
End If
Next
End If
End Using
Return 'Something...
End FunctionGaston Nunez
Re: Filter Dynblockre ferences in selection
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Was talking about using GetBlockReferenceIds() for BlockReferences that have not been modified by a dynamic properties and use GetAnonymousBlockIds to get the anonymous blocks created.
Quote from docs
BlockTableRecord.GetAnonymousBlockIds
Retrieves a collection populated with the ObjectIds of the anonymous blocks created from the dynamic block definition.
Also if you have collection of BlockReferences and want to to filter for if created from a Dynamic Block you could just get the Dynamic's BlockTableRecord ObjectId and remove the ones that its BlockReference.DynamicBlockTableRecord does not match
Re: Filter Dynblockre ferences in selection
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hi
Thank you all for getting back to me.
It seems that the filter can’t handle anonymous, names type “*Uxx”
To get around this. Here is my solution to accomplice my needs
<CommandMethod("HMDR", CommandFlags.Session)> _
Public Sub How_Many_dynamic_References()
Dim dyn_blockOBJ() As String
Dim n, nn As Integer
nn = 0
For n = 0 To ThisDrawing.Blocks.Count - 1
Dim blockObj As AcadBlock
If Not ThisDrawing.Blocks.Item(n).IsDynamicBlock Then
blockObj = ThisDrawing.Blocks.Item(n)
ReDim Preserve dyn_blockOBJ(nn)
dyn_blockOBJ(nn) = blockObj.Name
nn = nn + 1
End If
Next
Dim values(2) As TypedValue
values(0) = New TypedValue(DxfCode.Start, "INSERT")
values(1) = New TypedValue(-4, "<NOT")
values(2) = New TypedValue(-4, "<OR")
n = 2
For Each itn As String In dyn_blockOBJ
n = n + 1
ReDim Preserve values(n)
values(n) = New TypedValue(DxfCode.BlockName, itn)
Next
n = n + 1
ReDim Preserve values(n)
values(n) = New TypedValue(-4, "OR>")
n = n + 1
ReDim Preserve values(n)
values(n) = New TypedValue(-4, "NOT>")
MsgBox(values.Count)
Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Edit or
Dim sfilter As New SelectionFilter(values)
Dim res As PromptSelectionResult = ed.SelectAll(sfilter)
If Not res.Status = PromptStatus.OK Then Return
Dim SS As Autodesk.AutoCAD.EditorInput.SelectionSet = res.Value
Dim idarray As ObjectId() = SS.GetObjectIds()
If idarray.Count <> 1 Then Return
'MsgBox("OK")
End Sub
When I use the code in a project started with Template provided by Autodesk the lines
MsgBox(values.Count) And If idarray.Count <> 1 Then Return
Returns an error saying that Error 'Count' is not a member of 'System.Array'
If I use a project started as a Dll importing all references and namespaces I do not get this error All references and imports are identical in both Projects
Can anybody explain this
/HansP
Re: Filter Dynblockre ferences in selection
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hi,
>> Count' is not a member of 'System.Array
Try this instead:
if idarray.GetLength(0) ...
- alfred -
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
