Author Topic: Editor.SelectAll returns objects on frozen layers?  (Read 829 times)

0 Members and 1 Guest are viewing this topic.

Atook

  • Swamp Rat
  • Posts: 997
  • AKA Tim
Editor.SelectAll returns objects on frozen layers?
« on: September 07, 2022, 12:48:48 AM »
I use the following function to get all objectIDs with an appname, the problem is, it's returning objects that are on frozen layers, which is not desireable.
Do I need to iterate through all the entities and check if the entities layer is frozen? Maybe there's a better way to do this with selection filters or another method than .SelectAll?

Code - C#: [Select]
  1. /// <summary>
  2. /// Gets all objectIDs in the drawing with the specified appname written to it's xData.
  3. /// </summary>
  4. /// <param name="appName">Name of the appName to filter for</param>
  5. /// <param name="modelspaceOnly">Only select objects in modelspace</param>
  6. /// <returns></returns>
  7. public static ObjectIdCollection GetAllObjectIDs(string appName, bool modelspaceOnly = true)
  8. {
  9.   ObjectIdCollection result = new ObjectIdCollection();
  10.   TypedValueList filterArray = new TypedValueList()
  11.   {
  12.     new TypedValue((int)DxfCode.ExtendedDataRegAppName, appName)
  13.   };
  14.   if (modelspaceOnly) filterArray.Add(new TypedValue(67, 0));
  15.   SelectionFilter appNameFilter = new SelectionFilter(filterArray);
  16.   PromptSelectionResult psr =
  17.     Active.Editor.SelectAll(appNameFilter);
  18.   if (psr.Status == PromptStatus.OK)
  19.   {
  20.     return new ObjectIdCollection(psr.Value.GetObjectIds());
  21.   }
  22.   return result;
  23. }
  24.  



gile

  • Water Moccasin
  • Posts: 2406
  • Marseille, France
Re: Editor.SelectAll returns objects on frozen layers?
« Reply #1 on: September 07, 2022, 01:55:33 AM »
Hi,

You can get the forzen layer names to use them in your filter.

Example (not tested)
Code - C#: [Select]
  1.         /// <summary>
  2.         /// Gets all objectIDs in the drawing with the specified appname written to it's xData.
  3.         /// </summary>
  4.         /// <param name="appName">Name of the appName to filter for</param>
  5.         /// <param name="modelspaceOnly">Only select objects in modelspace</param>
  6.         /// <returns></returns>
  7.         public static ObjectIdCollection GetAllObjectIDs(string appName, bool modelspaceOnly = true)
  8.         {
  9.             string frozenLayers;
  10.             using (var tr = new OpenCloseTransaction())
  11.             {
  12.                 var layerTable = (LayerTable)tr.GetObject(Active.Database.LayerTableId, OpenMode.ForRead);
  13.                 frozenLayers = string.Join(",",
  14.                     layerTable.Cast<ObjectId>()
  15.                     .Select(id => (LayerTableRecord)tr.GetObject(id, OpenMode.ForRead))
  16.                     .Where(l => l.IsFrozen)
  17.                     .Select(l => l.Name));
  18.                 tr.Commit();
  19.             }
  20.             ObjectIdCollection result = new ObjectIdCollection();
  21.             TypedValueList filterArray = new TypedValueList()
  22.             {
  23.                 new TypedValue((int)DxfCode.ExtendedDataRegAppName, appName)
  24.             };
  25.             if (!string.IsNullOrEmpty(frozenLayers))
  26.             {
  27.                 filterArray.Add(new TypedValue(-4, "<NOT"));
  28.                 filterArray.Add(new TypedValue(8, frozenLayers));
  29.                 filterArray.Add(new TypedValue(-4, "NOT>"));
  30.             }
  31.             if (modelspaceOnly) filterArray.Add(new TypedValue(67, 0));
  32.             SelectionFilter appNameFilter = new SelectionFilter(filterArray);
  33.             PromptSelectionResult psr = Active.Editor.SelectAll(appNameFilter);
  34.             if (psr.Status == PromptStatus.OK)
  35.             {
  36.                 return new ObjectIdCollection(psr.Value.GetObjectIds());
  37.             }
  38.             return result;
  39.         }
Speaking English as a French Frog

Atook

  • Swamp Rat
  • Posts: 997
  • AKA Tim
Re: Editor.SelectAll returns objects on frozen layers?
« Reply #2 on: September 07, 2022, 11:45:23 AM »
Thanks Gile, much more efficient than what I came up with.

It's always a treat reading your code. :)

gile

  • Water Moccasin
  • Posts: 2406
  • Marseille, France
Re: Editor.SelectAll returns objects on frozen layers?
« Reply #3 on: September 07, 2022, 11:48:07 AM »
You're welcome.
Speaking English as a French Frog