.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

SelectAll bug?

2 REPLIES 2
Reply
Message 1 of 3
wesbird
324 Views, 2 Replies

SelectAll bug?

Hi,
When I tried to wrote my first Selection Set function in .Net, I found this:
In my test drawing, there are
2 LWPOLYLINE, on layer 0 and ABC
2 old style Polyline, on layer 0 and ABC
2 Circle on layer 0 and ABC
when I run my test routine which will create selection set wtih different filter, here is what I got:
POLYLINE, LWPOLYLINE+ABC: 1 (wrong, correct is 2)
POLYLINE, LWPOLYLINE: 2 (wrong, correct is 4)
POLYLINE, CIRCLE+ABC: 1 (wrong, correct is 2)
POLYLINE,CIRCLE: 4 (correct)
LWPOLYLINE+ABC: 1 (correct)
LWPOLYLINE: 2 (correct)
Select All: 6

I read some article the bug in conditional filter. To my understanding, it about use -4 in the filter which I did not. If this correct, then what's wrong in my code?

here is the code:
Class.cs

using System;
using System.Collections;
using System.Globalization;

using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Geometry;


namespace SelectAll
{
///
/// Summary description for RSss.
///

///
// public class RSss : SelectionSet
public class RSss
{
public RSss()
{
//
// TODO: Add constructor logic here
//
}

// Select All, w/o filter
//
public static SelectionSet SelectAll()
{
Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;

PromptSelectionResult prSelRes = ed.SelectAll();

if (prSelRes.Status != PromptStatus.OK) return null;

SelectionSet ss = prSelRes.Value;

// ddebug
// ed.WriteMessage("Number in the selection set: {0}", ss.Count);

return ss;
}

// Select All, w/o filter
//
public static SelectionSet SelectAll(TypedValue[] values)
{
Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;

SelectionSet ss = null;
try
{

SelectionFilter filterSS = new SelectionFilter(values);
PromptSelectionResult prSelRes = ed.SelectAll(filterSS);

if (prSelRes.Status != PromptStatus.OK) return null;

ss = prSelRes.Value;
}
catch (System.Exception caught)
{
// ddebug
ed.WriteMessage(caught.Message.ToString());
}

// ddebug
// ed.WriteMessage("SelectAll2-Number in the selection set: {0}", ss.Count);

return ss;
}

}
}


test.cs
using System;

using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.DatabaseServices;

namespace SelectAll
{
///
/// Summary description for test.
///

public class test
{
// SelectAll2
[CommandMethod("SelectAll_TEST")]
public static void SelectAll_Test()
{
Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
TypedValue[] values = new TypedValue[2] {
new TypedValue((int)DxfCode.Start, "POLYLINE, LWPOLYLINE"),
new TypedValue((int)DxfCode.LayerName, "ABC")
};

SelectionSet ss1 = RSss.SelectAll(values);
// ddebug
if (ss1 != null)
ed.WriteMessage("\nPOLYLINE, LWPOLYLINE+ABC: {0}", ss1.Count);

TypedValue[] values2 = new TypedValue[1] {new TypedValue((int)DxfCode.Start, "POLYLINE, LWPOLYLINE")};
SelectionSet ss2 = RSss.SelectAll(values2);
// ddebug
if (ss2 != null)
ed.WriteMessage("\nPOLYLINE, LWPOLYLINE: {0}", ss2.Count);

TypedValue[] values4 = new TypedValue[2] {
new TypedValue((int)DxfCode.Start, "POLYLINE, CIRCLE"),
new TypedValue((int)DxfCode.LayerName, "ABC")
};
SelectionSet ss4 = RSss.SelectAll(values4);
// ddebug
if (ss4 != null)
ed.WriteMessage("\nPOLYLINE, CIRCLE+ABC: {0}", ss4.Count);

TypedValue[] values3 = new TypedValue[1] {new TypedValue((int)DxfCode.Start, "POLYLINE,CIRCLE")};
SelectionSet ss3 = RSss.SelectAll(values3);
// ddebug
if (ss3 != null)
ed.WriteMessage("\nPOLYLINE,CIRCLE: {0}", ss3.Count);

TypedValue[] values6 = new TypedValue[2] {
new TypedValue((int)DxfCode.Start, "LWPOLYLINE"),
new TypedValue((int)DxfCode.LayerName, "ABC")
};
SelectionSet ss6 = RSss.SelectAll(values6);
// ddebug
if (ss6 != null)
ed.WriteMessage("\nLWPOLYLINE+ABC: {0}", ss6.Count);

TypedValue[] values5 = new TypedValue[1] {new TypedValue((int)DxfCode.Start, "LWPOLYLINE") };
SelectionSet ss5 = RSss.SelectAll(values5);
// ddebug
if (ss5 != null)
ed.WriteMessage("\nLWPOLYLINE: {0}", ss5.Count);

SelectionSet ss0 = RSss.SelectAll();
// ddebug
if (ss0 != null)
ed.WriteMessage("\n Select All: {0}", ss0.Count);
}
}
}



Thank you very much
Wes
Windows 10 64 bit, AutoCAD (ACA, Map) 2023
2 REPLIES 2
Message 2 of 3
fantum
in reply to: wesbird

I'm guessing here but you might try removing the spaces from "POLYLINE, LWPOLYLINE", "POLYLINE, LWPOLYLINE", and "POLYLINE, CIRCLE".
Message 3 of 3
wesbird
in reply to: wesbird

I can't believe this is the reason. it works. Thank you very much.



Wes
Windows 10 64 bit, AutoCAD (ACA, Map) 2023

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost