TheSwamp

Code Red => .NET => Topic started by: Atook on October 14, 2019, 05:38:54 PM

Title: Filter BlockTableRecords by xdata without iterating?
Post by: Atook on October 14, 2019, 05:38:54 PM
Is it possible to get all the BlockTableRecords in a drawing that contain certain xdata without iterating through the blocktable? Similar to filtering a selectionset by xdata. Right now I'm doing the iteration thing with this: (forgive the unincluded code)

Code - C#: [Select]
  1. public static ObjectIdCollection BlockDefsWithXData(string appName)
  2. {
  3.   ObjectIdCollection result = new ObjectIdCollection();
  4.   using (Transaction tr = Active.Document.TransactionManager.StartTransaction())
  5.   {
  6.     BlockTable bt = (BlockTable)tr.GetObject(Active.Database.BlockTableId, OpenMode.ForRead);
  7.     foreach (ObjectId id in bt)
  8.     {
  9.       if (XData.HasAppName(id, appName)) // see if it's got the appname
  10.       {
  11.         result.Add(id);
  12.       }
  13.     }
  14.     tr.Commit();
  15.   }
  16.   return result;
  17. }
Title: Re: Filter BlockTableRecords by xdata without iterating?
Post by: MickD on October 14, 2019, 07:11:22 PM
Not that I'm aware of, even if you could the application would do the iteration anyway and would only be marginally (read that as not noticeably) faster anyway.

If you are working with the current db in the editor you could perhaps use a SelectionSet with PromptSelectionOptions.SelectEverythingInAperture to select all with a filter?

I'd assume that the iteration would be quicker though as you're not dealing with the Editor and SelectionSet code layers.
Title: Re: Filter BlockTableRecords by xdata without iterating?
Post by: gile on October 15, 2019, 12:51:24 AM
Hi,

I made some tests sometimes ago and it appears that using Editor.SelectAll with a selection filter is not faster than iterating through the model and paper spaces, it is even a little slower when opening the entities is not required (i.e. only filtering entity types by ObjectId.ObjectClass).
Title: Re: Filter BlockTableRecords by xdata without iterating?
Post by: Atook on October 15, 2019, 07:50:05 AM
Hi,

I made some tests sometimes ago and it appears that using Editor.SelectAll with a selection filter is not faster than iterating through the model and paper spaces, it is even a little slower when opening the entities is not required (i.e. only filtering entity types by ObjectId.ObjectClass).

Thanks Gile, that's really good information.

Looks like I'll stick to iterating through the blocktable.
Title: Re: Filter BlockTableRecords by xdata without iterating?
Post by: Atook on October 15, 2019, 07:55:00 AM
..If you are working with the current db in the editor you could perhaps use a SelectionSet with PromptSelectionOptions.SelectEverythingInAperture to select all with a filter?

I'd assume that the iteration would be quicker though as you're not dealing with the Editor and SelectionSet code layers.

Thanks for the reply MickD. A SelectionSet wouldn't work, because I'm looking for BlockDefinitions, not BlockReferences. Between your post and Gile's it seems that iteration is the way to go.
Title: Re: Filter BlockTableRecords by xdata without iterating?
Post by: MickD on October 15, 2019, 08:28:19 PM
..If you are working with the current db in the editor you could perhaps use a SelectionSet with PromptSelectionOptions.SelectEverythingInAperture to select all with a filter?

I'd assume that the iteration would be quicker though as you're not dealing with the Editor and SelectionSet code layers.

Thanks for the reply MickD. A SelectionSet wouldn't work, because I'm looking for BlockDefinitions, not BlockReferences. Between your post and Gile's it seems that iteration is the way to go.

no prob's :)