Author Topic: Filter BlockTableRecords by xdata without iterating?  (Read 2529 times)

0 Members and 1 Guest are viewing this topic.

Atook

  • Swamp Rat
  • Posts: 1027
  • AKA Tim
Filter BlockTableRecords by xdata without iterating?
« 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. }

MickD

  • King Gator
  • Posts: 3619
  • (x-in)->[process]->(y-out) ... simples!
Re: Filter BlockTableRecords by xdata without iterating?
« Reply #1 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.
"Short cuts make long delays,' argued Pippin.”
J.R.R. Tolkien

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Filter BlockTableRecords by xdata without iterating?
« Reply #2 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).
Speaking English as a French Frog

Atook

  • Swamp Rat
  • Posts: 1027
  • AKA Tim
Re: Filter BlockTableRecords by xdata without iterating?
« Reply #3 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.
« Last Edit: October 15, 2019, 07:55:26 AM by Atook »

Atook

  • Swamp Rat
  • Posts: 1027
  • AKA Tim
Re: Filter BlockTableRecords by xdata without iterating?
« Reply #4 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.

MickD

  • King Gator
  • Posts: 3619
  • (x-in)->[process]->(y-out) ... simples!
Re: Filter BlockTableRecords by xdata without iterating?
« Reply #5 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 :)
"Short cuts make long delays,' argued Pippin.”
J.R.R. Tolkien