Rotem Steiner
Rotem Steiner

Reputation: 79

Can I filter an AutoCAD SelectionSet with the COM api?

I'm writing an external tool for AutoCAD (using the COM api) and I need to filter a SelectionSet, but I cant figure out the correct types for the "FilterType" and "FilterData" parameters.

I know it's outdated but I need to use the COM api and I can't for the life of me find any documentation. Can anyone with a bit more experience help me with this?

These are the problematic lines:

AcadApplication app = Marshal.GetActiveObject(AppID) as AcadApplication;
AcadSelectionSet SelectionSet = app.ActiveDocument.SelectionSets.Add(name);

int[] filterType = new int[1];
object[] filterData = new object[1];

filterType[0] = (int)DxfCode.BlockName;
filterData[0] = "T-siman";

SelectionSet.SelectOnScreen(filterType, filterData);

The last line returns the following exception: System.ArgumentException: 'Invalid argument FilterType in SelectOnScreen'

Upvotes: 1

Views: 751

Answers (1)

Rotem Steiner
Rotem Steiner

Reputation: 79

I kept looking for a solution because I was stuck but then I found THIS QUESTION and noticed this person uses an array of type "short" instead of type "int" for the "FilterType" parameter. Doing this worked for me.

My working code:

AcadApplication app = Marshal.GetActiveObject(AppID) as AcadApplication;
AcadSelectionSet SelectionSet = app.ActiveDocument.SelectionSets.Add(name);

short[] filterType = new short[1];
object[] filterData = new object[1];

filterType[0] = (short)DxfCode.BlockName;
filterData[0] = "T-siman";

SelectionSet.SelectOnScreen(filterType, filterData);

Upvotes: 2

Related Questions