lewis770227 Posted August 5, 2011 Share Posted August 5, 2011 How can I do a filter for BlockReference only, I'm using vb .NET. I tried this, but it doesn't work Public Sub FilterSelectionSet() '' Get the current document editor Dim acDocEd As Editor = Application.DocumentManager.MdiActiveDocument.Editor Dim acTypValAr(0) As TypedValue acTypValAr.SetValue(New TypedValue(DxfCode.blockname, "blockreference name"), 0) Dim acSelFtr As SelectionFilter = New SelectionFilter(acTypValAr) Dim acSSPrompt As PromptSelectionResult acSSPrompt = acDocEd.GetSelection(acSelFtr) ----- So this example select the blocks named "blockreference name" but I need another code for all blockreference no matter the name Quote Link to comment Share on other sites More sharing options...
Jeff H Posted August 5, 2011 Share Posted August 5, 2011 To use a SelectionFilter pass in New TypedValue(DxfCode.Start, "INSERT") So using the ediitor you can select all entites [color=black][font=Verdana] <CommandMethod("SelectAllEntites")> _[/font][/color] [font=Verdana][color=black] Sub SelectAllEntites()[/color][/font] [font=Verdana][color=black] Dim doc As Document = Application.DocumentManager.MdiActiveDocument[/color][/font] [font=Verdana][color=black] Dim db As Database = doc.Database[/color][/font] [font=Verdana][color=black] Dim ed As Editor = doc.Editor[/color][/font] [font=Verdana][color=black] Dim ss As SelectionSet = ed.SelectAll().Value[/color][/font] [font=Verdana][color=black] Using trx As Transaction = db.TransactionManager.StartTransaction()[/color][/font] [font=Verdana][color=black] Dim bt As BlockTable = trx.GetObject(db.BlockTableId, OpenMode.ForRead)[/color][/font] [font=Verdana][color=black] For Each selObj As SelectedObject In ss[/color][/font] [font=Verdana][color=black] Next[/color][/font] [font=Verdana][color=black] trx.Commit()[/color][/font] [font=Verdana][color=black] End Using[/color][/font] [font=Verdana][color=black] End Sub[/color][/font] Now if you want to get all BlockReferences on a certain layer you can pass in a SelectionFilter <CommandMethod("SelectAllBlockReferencesOnLayer")> _ Sub SelectAllBlockReferencesOnLayer() Dim doc As Document = Application.DocumentManager.MdiActiveDocument Dim db As Database = doc.Database Dim ed As Editor = doc.Editor Dim tv() As TypedValue = {New TypedValue(DxfCode.Start, "INSERT"), New TypedValue(DxfCode.LayerName, "BlockLayer")} Dim selFilter As New SelectionFilter(tv) Dim ss As SelectionSet = ed.SelectAll().Value Using trx As Transaction = db.TransactionManager.StartTransaction() Dim bt As BlockTable = trx.GetObject(db.BlockTableId, OpenMode.ForRead) For Each selObj As SelectedObject In ss Dim bref As BlockReference = trx.GetObject(selObj.ObjectId, OpenMode.ForRead) Next trx.Commit() End Using End Sub I need to get going and will explain these later but is quicker since you do not have to open the objects and there are some issues like how to handle dymanic blocks but no big deal. itterate ModelSpace <CommandMethod("GetAllModelBlockRefs")> _ Sub GetAllModelBlockRefs() Dim doc As Document = Application.DocumentManager.MdiActiveDocument Dim db As Database = doc.Database Dim ed As Editor = doc.Editor Using trx As Transaction = db.TransactionManager.StartTransaction() Dim bt As BlockTable = trx.GetObject(db.BlockTableId, OpenMode.ForRead) Dim modelBtr As BlockTableRecord = trx.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForRead) For Each id As ObjectId In modelBtr If id.ObjectClass.Name = "AcDbBlockReference" Then ''''''''Do whatever End If Next trx.Commit() End Using End Sub get from all spaces <CommandMethod("GetAllSpaceslBlockRefs")> _ Sub GetAllSpaceslBlockRefs() Dim doc As Document = Application.DocumentManager.MdiActiveDocument Dim db As Database = doc.Database Dim ed As Editor = doc.Editor Using trx As Transaction = db.TransactionManager.StartTransaction() Dim bt As BlockTable = trx.GetObject(db.BlockTableId, OpenMode.ForRead) For Each btrId As ObjectId In bt Dim btr As BlockTableRecord = trx.GetObject(btrId, OpenMode.ForRead) If btr.IsLayout Then For Each id As ObjectId In btr If id.ObjectClass = RXClass.GetClass(GetType(BlockReference)) Then ''''''''Do whatever End If Next End If Next trx.Commit() End Using End Sub Instead of checking in all spaces just go grab references from the the block definitions <CommandMethod("GetAllBlockRefsFromDefinitions")> _ Sub GetAllBlockRefsFromDefinitions() Dim doc As Document = Application.DocumentManager.MdiActiveDocument Dim db As Database = doc.Database Dim ed As Editor = doc.Editor Using trx As Transaction = db.TransactionManager.StartTransaction() Dim bt As BlockTable = trx.GetObject(db.BlockTableId, OpenMode.ForRead) For Each btrId As ObjectId In bt Dim btr As BlockTableRecord = trx.GetObject(btrId, OpenMode.ForRead) If Not btr.IsLayout Then Dim refIds As ObjectIdCollection = btr.GetBlockReferenceIds(True, False) For Each id As ObjectId In refIds Dim bref As BlockReference = trx.GetObject(id, OpenMode.ForRead) Next End If Next trx.Commit() End Using End Sub Quote Link to comment Share on other sites More sharing options...
lewis770227 Posted August 8, 2011 Author Share Posted August 8, 2011 Jeff it was the best reply I had ever received in this forum, so I want to ask you for example in this code: _ Sub SelectAllBlockReferencesOnLayer() Dim doc As Document = Application.DocumentManager.MdiActiveDocument Dim db As Database = doc.Database Dim ed As Editor = doc.Editor Dim tv() As TypedValue = {New TypedValue(DxfCode.Start, "INSERT"), New TypedValue(DxfCode.LayerName, "BlockLayer")} Dim selFilter As New SelectionFilter(tv) Dim ss As SelectionSet = ed.SelectAll().Value Using trx As Transaction = db.TransactionManager.StartTransaction() Dim bt As BlockTable = trx.GetObject(db.BlockTableId, OpenMode.ForRead) For Each selObj As SelectedObject In ss Dim bref As BlockReference = trx.GetObject(selObj.ObjectId, OpenMode.ForRead) Next trx.Commit() End Using End Sub you create a selectionfilter but never use it, I just let the user do a selection using getselection(), and then I create a selectionset with object, in this case certain blockreference, I don't know if creating a filterselection which the name of blockreference and pass this filter to getselection() will work by the way the blockreference are dynamic. Quote Link to comment Share on other sites More sharing options...
Jeff H Posted August 9, 2011 Share Posted August 9, 2011 I think your asking if the blocks are dynamic. If no changes are made then you can grab all ids if it has been changed then you can grab using BlockTableRecord.GetAnonymousBlockIds Quote Link to comment Share on other sites More sharing options...
SLW210 Posted August 9, 2011 Share Posted August 9, 2011 lewis770227, you need to use CODE TAGS. Quote Link to comment Share on other sites More sharing options...
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.