We talked about the count limit of available selection sets in Auto/Visual LISP, AutoCAD .NET API, and AutoCAD ActiveX/COM interfaces respectively before, and found in each API the count limit is 128 or one less sometimes.
We also made an assumption that the 128 count limit applies to the whole AutoCAD session instead of each document/database. We verified the fact in the post about the selection set count limit in AutoLISP.
It’s pretty natural to make a similar assumption that the 128 count limit of all available selection sets applies to all APIs together instead of each particular one such as LISP, COM, and .NET. In this article, we are going to verify this with some simple but functional code again.
[CommandMethod("SelectionSetCountLimitInDotNetComAndLisp", CommandFlags.Modal)]
public void SelectionSetCountLimitInDotNetComAndLisp_Method()
{
Database db = HostApplicationServices.WorkingDatabase;
Document doc = MgdAcApplication.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
AcadApplication comApp = MgdAcApplication.AcadApplication as AcadApplication;
AcadDocument comDoc = comApp.ActiveDocument;
AcadSelectionSets comSSes = comDoc.SelectionSets;
try
{
for (int i = 0; i < 63; i++)
{
SelectionSet ss = ed.SelectAll().Value;
if (ss != null)
ed.WriteMessage("\nThe #{0} SS created by .NET is good and has {1} entities.", i + 1, ss.Count);
else
ed.WriteMessage("\nThe #{0} SS created by .NET is bad!", i + 1);
}
for (int i = 63; i < 126; i++)
{
AcadSelectionSet comSs = comSSes.Add(string.Format("SS{0}", i + 1));
if (comSs != null)
{
comSs.Select(Autodesk.AutoCAD.Interop.Common.AcSelect.acSelectionSetAll);
ed.WriteMessage(string.Format("\nThe #{0} SS created by COM is good and has {1} entities.", i + 1, comSs.Count));
}
else
ed.WriteMessage(string.Format("\nThe #{0} SS created by COM is bad!", i + 1));
}
doc.SendStringToExecute("(setq ss127 (ssget \"X\"))\n", false, false, true);
doc.SendStringToExecute("(setq ss128 (ssget \"X\"))\n", false, false, true);
doc.SendStringToExecute("(setq ss129(ssget \"X\"))\n", false, false, true);
}
catch (System.Exception ex)
{
ed.WriteMessage(Environment.NewLine + ex.ToString());
}
}
In the above short C# code, three different APIs (AutoCAD programming technologies) have been demonstrated, C# .NET, COM Interop, and AutoLISP. The first creates 63 selection sets; the second another 63 ones; and the last tries to create 3 more.
If an AutoCAD session is launched, a new drawing is created, a circle is added to the database, and the command is run, we will see the following output which is as expected.
Regenerating model.
AutoCAD menu utilities loaded.
Command:
Command: c CIRCLE Specify center point for circle or [3P/2P/Ttr (tan tan radius)]:
Specify radius of circle or [Diameter]:
Command: SelectionSetCountLimitInDotNetComAndLisp
The #1 SS created by .NET is good and has 1 entities.
...
The #63 SS created by .NET is good and has 1 entities.
Command:
The #64 SS created by COM is good and has 1 entities.
...
Command:
The #126 SS created by COM is good and has 1 entities.
Command: (setq ss127 (ssget "X"))
<Selection set: c1>
Command: (setq ss128 (ssget "X"))
<Selection set: c3>
Command: (setq ss129(ssget "X"))
; error: exceeded maximum number of selection sets
As can be seen, in all the three AutoCAD APIs as demonstrated here, LISP, COM/ActiveX and .NET, the limit of the total available selection sets is 128. Trying to create the #129 selection set will just fail in AutoLISP. It would be true for any other APIs or even AutoCAD native commands.
Adding the fact that the 128 limit applies to the whole session instead of each document/database, and there are some other AutoCAD APIs/Technologies that can also manipulate selection sets but have not been demonstrated here such as ADS/(Object)ARX, Scripts, Menus, and Diesels, it seems not a bad idea to release any selection sets right after they are done in any APIs, as repeated many times before.
In terms of how to release or free selection sets in ActiveX/COM, .NET and LISP, please refer to earlier posts for details, we will not repeat here. If interested, please go ahead to do similar experiments to the ADS/(Object)ARX or adding it into the test bundle.
The leading edge AutoCAD .NET Addin Wizard (AcadNetAddinWizard) provides project wizards in C#, VB.NET and CLI/Managed C++, and various item wizards such as Event Handlers, Command/LispFunction Definers, and Entity/Draw Jiggers in both C# and VB.NET, to help program AutoCAD addins.
Posted by: |