how to use selectionset in C#

how to use selectionset in C#

Anonymous
Not applicable
5,072 Views
14 Replies
Message 1 of 15

how to use selectionset in C#

Anonymous
Not applicable
Hi, I've done this in VB and it worked, but now the same code in C# and it is not working. please help!
basically, I want to select objects using selectionsets.add:

AcadDocument m_ACADDoc;
......

double []corner1 = new double [3];
double []corner2 = new double [3];
corner1[0] = -100;
corner1[1] = -100;
corner1[2] = 0;
corner2[0] = 100;
corner2[1] = 100;
corner2[2] = 0;

AcadSelectionSet oAcadSSet = m_ACADDoc.SelectionSets.Add("SSET");
object ref_missing = Type.Missing;
oAcadSSet.Select(AcSelect.acSelectionSetCrossing, corner1, corner2, ref_missing, ref_missing);

however, the returned set (oAcadSSet) always contains 0 object.

even if i tried the following (which is copied from internet):
object gpCode = new short[] { 0 };
object dataValue = new object[] { "LINE" };
object groupCode = gpCode;
object DataCode = dataValue;
oAcadSSet.Select(AcSelect.acSelectionSetCrossing, corner1, corner2, groupCode, DataCode);

the set still doesn't contain any object.

Do anyone know how to fix this? thanks!
0 Likes
5,073 Views
14 Replies
Replies (14)
Message 2 of 15

Anonymous
Not applicable

Please post code using Rich Text format or an
attached text file.

 

Joe ...

 


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
Hi,
I've done this in VB and it worked, but now the same code in C# and it is not
working. please help! basically, I want to select objects using
selectionsets.add: AcadDocument m_ACADDoc; ...... double []corner1 = new
double [3]; double []corner2 = new double [3]; corner1[0] = -100; corner1[1] =
-100; corner1[2] = 0; corner2[0] = 100; corner2[1] = 100; corner2[2] = 0;
AcadSelectionSet oAcadSSet = m_ACADDoc.SelectionSets.Add("SSET"); object
ref_missing = Type.Missing; oAcadSSet.Select(AcSelect.acSelectionSetCrossing,
corner1, corner2, ref_missing, ref_missing); however, the returned set
(oAcadSSet) always contains 0 object. even if i tried the following (which is
copied from internet): object gpCode = new short[] { 0 }; object dataValue =
new object[] { "LINE" }; object groupCode = gpCode; object DataCode =
dataValue; oAcadSSet.Select(AcSelect.acSelectionSetCrossing, corner1, corner2,
groupCode, DataCode); the set still doesn't contain any object. Do anyone know
how to fix this? thanks!
0 Likes
Message 3 of 15

Anonymous
Not applicable
Is it better now? from my browser, they look the same.









Hi, I've done this in VB and it worked, but now the same

code in C# and it is not working. please help!



basically, I want to select objects using selectionsets.add:







AcadDocument m_ACADDoc;



......







double []corner1 = new double [3];



double []corner2 = new double [3];



corner1[0] = -100;



corner1[1] = -100;



corner1[2] = 0;



corner2[0] = 100;



corner2[1] = 100;



corner2[2] = 0;







AcadSelectionSet oAcadSSet = m_ACADDoc.SelectionSets.Add("SSET");



object ref_missing = Type.Missing;



oAcadSSet.Select(AcSelect.acSelectionSetCrossing, corner1, corner2,

ref_missing, ref_missing);







however, the returned set (oAcadSSet) always contains 0 object.







even if i tried the following (which is copied from internet):



object gpCode = new short[] { 0 };



object dataValue = new object[] { "LINE" };



object groupCode = gpCode;



object DataCode = dataValue;



oAcadSSet.Select(AcSelect.acSelectionSetCrossing, corner1, corner2, groupCode,

DataCode);







the set still doesn't contain any object.







Do anyone know how to fix this? thanks!


Edited by: YL2000 on Mar 25, 2009 5:09 PM
0 Likes
Message 4 of 15

Anonymous
Not applicable

Did you run your working VB version through a
converter such as the one found in CSharpDevelop
href="http://www.icsharpcode.net/OpenSource/SD/">http://www.icsharpcode.net/OpenSource/SD/
 or
did you hand convert it?

 

If you didn't use a converter, try that and see
what errors and/or warnings there are and work from there or post your VB
version here or you're welcome to email me directly.

 

 

Joe ...

 


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
Is
it better now? from my browser, they look the
same.









Hi, I've done this in VB and it
worked, but now the same

code in C# and it is not working. please
help!



basically, I want to select objects using
selectionsets.add:







AcadDocument
m_ACADDoc;



......







double
[]corner1 = new double [3];



double []corner2 = new double
[3];



corner1[0] = -100;



corner1[1] =
-100;



corner1[2] = 0;



corner2[0] =
100;



corner2[1] = 100;



corner2[2] =
0;







AcadSelectionSet oAcadSSet =
m_ACADDoc.SelectionSets.Add("SSET");



object ref_missing =
Type.Missing;




oAcadSSet.Select(AcSelect.acSelectionSetCrossing, corner1,
corner2,

ref_missing,
ref_missing);







however, the returned set
(oAcadSSet) always contains 0 object.







even if i
tried the following (which is copied from internet):



object
gpCode = new short[] { 0 };



object dataValue = new object[] {
"LINE" };



object groupCode = gpCode;



object
DataCode =
dataValue;



oAcadSSet.Select(AcSelect.acSelectionSetCrossing,
corner1, corner2,
groupCode,

DataCode);







the set still
doesn't contain any object.







Do anyone know how
to fix this? thanks!


Edited by: YL2000 on Mar 25, 2009 5:09
PM
0 Likes
Message 5 of 15

Anonymous
Not applicable


this is the vb code which works well:



Dim pCorner1(0 to 2) as double

Dim pCorner2(0 to 2) as double

pCorner1[0] = 0

pCorner1[1] = 0

pCorner1[2] = 0

pCorner2[0] = 10

pCorner2[1] = 10

pCorner2[2] = 0


Dim ssetObj As AcadSelectionSet



Set ssetObj = ThisDrawing.SelectionSets.Add("SSET")



mode = acSelectionSetCrossing

ssetObj.Select mode, pCorner1, pCorner2
0 Likes
Message 6 of 15

Anonymous
Not applicable

Can't use a converter .... it's regular VB [my
bad].

 


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">


this
is the vb code which works well:



Dim pCorner1(0 to 2) as double


Dim pCorner2(0 to 2) as double

pCorner1[0] =
0

pCorner1[1] = 0

pCorner1[2] = 0

pCorner2[0] =
10

pCorner2[1] = 10

pCorner2[2] = 0


Dim ssetObj As
AcadSelectionSet



Set ssetObj =
ThisDrawing.SelectionSets.Add("SSET")



mode =
acSelectionSetCrossing

ssetObj.Select mode, pCorner1,
pCorner2
0 Likes
Message 7 of 15

Anonymous
Not applicable

Well, that's not entirely true.


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">


Can't use a converter .... it's regular VB [my
bad].

 


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">


this
is the vb code which works well:



Dim pCorner1(0 to 2) as
double

Dim pCorner2(0 to 2) as double

pCorner1[0] =
0

pCorner1[1] = 0

pCorner1[2] = 0

pCorner2[0] =
10

pCorner2[1] = 10

pCorner2[2] = 0


Dim ssetObj As
AcadSelectionSet



Set ssetObj =
ThisDrawing.SelectionSets.Add("SSET")



mode =
acSelectionSetCrossing

ssetObj.Select mode, pCorner1,
pCorner2
0 Likes
Message 8 of 15

Anonymous
Not applicable

Here is a
size=2>VB.NET version. I'll let you convert to C#.

 

Joe ...

 

    <CommandMethod("SCW")>
_
    Public Shared Sub
SelectAllCrossingWindowExample()
       
'get an editor object
        Dim ed As
Editor =
Application.DocumentManager.MdiActiveDocument.Editor
       
'get the active document
        Dim dwg
As Document = Application.DocumentManager.MdiActiveDocument

 

        'get a
transaction started
        Using ta As
Transaction = dwg.TransactionManager.StartTransaction

 


size=2>           
Try
               
Dim LowerLeftPointOptions As PromptPointOptions = New PromptPointOptions("Select
first point of
window")
               
Dim LowerLeftPointResult As PromptPointResult =
ed.GetPoint(LowerLeftPointOptions)
               
Dim PromptCornerOptions As PromptCornerOptions = New PromptCornerOptions("Select
opposite point of window",
LowerLeftPointResult.Value)
               
Dim UpperRightPointResult As PromptPointResult =
ed.GetCorner(PromptCornerOptions)

 


size=2>               
'default select all entities crossed within
window
               
Dim PromptSelectionResult As PromptSelectionResult =
ed.SelectCrossingWindow(LowerLeftPointResult.Value,
UpperRightPointResult.Value)

 


size=2>               
If (PromptSelectionResult.Status = PromptStatus.OK)
Then
                   
Dim objIDArray() As
ObjectId
                   
'fill an array with the selected
entities
                   
objIDArray = PromptSelectionResult.Value.GetObjectIds()

 


size=2>                   
Dim objID As ObjectId

 


size=2>                   
For Each objID In
objIDArray
                       
Dim dbObj As
DBObject
                       
'open each entity for
reading
                       
dbObj = ta.GetObject(objID,
OpenMode.ForRead)
                       
'tell user the type of each
entity
                       
ed.WriteMessage(dbObj.GetType.ToString +
vbCrLf)
                   
Next
               
End If

 


size=2>            Catch
ex As
Exception
               
ed.WriteMessage(ex.ToString())

 


size=2>            End
Try
        End
Using
    End Sub

 


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">


Well, that's not entirely true.


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">


Can't use a converter .... it's regular VB [my
bad].

 


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">


this
is the vb code which works well:



Dim pCorner1(0 to 2) as
double

Dim pCorner2(0 to 2) as double

pCorner1[0] =
0

pCorner1[1] = 0

pCorner1[2] = 0

pCorner2[0] =
10

pCorner2[1] = 10

pCorner2[2] = 0


Dim ssetObj
As AcadSelectionSet



Set ssetObj =
ThisDrawing.SelectionSets.Add("SSET")



mode =
acSelectionSetCrossing

ssetObj.Select mode, pCorner1,
pCorner2
0 Likes
Message 9 of 15

Anonymous
Not applicable
I tried, and it seems the converter doesn't fill out the missing parameters which are required by C# and not required by VB.
0 Likes
Message 10 of 15

Anonymous
Not applicable

Did you use the last code I posted [that's actual
VB.NET code]?

 

Joe ...


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
I
tried, and it seems the converter doesn't fill out the missing parameters
which are required by C# and not required by VB.
0 Likes
Message 11 of 15

Anonymous
Not applicable
yes, i tried that. but it didn't seem to be very helpful.
0 Likes
Message 12 of 15

Anonymous
Not applicable

Make sure your acmgd.dll and acdbmgd.dll "Copy
Local" property is set to False.

 

Joe ...

 

 

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

 

public class
SelectionSetExample
{
   
[CommandMethod("SCW")]
    public static void
SelectAllCrossingWindowExample()
   
{
        //get an editor
object
        Editor ed =
Application.DocumentManager.MdiActiveDocument.Editor;
       
//get the active document
        Document
dwg = Application.DocumentManager.MdiActiveDocument;

 

        //get a
transaction started
        using
(Transaction ta =
dwg.TransactionManager.StartTransaction())
       
{


size=2>           
try
           
{
               
PromptPointOptions LowerLeftPointOptions = new PromptPointOptions("Select first
point of
window");
               
PromptPointResult LowerLeftPointResult =
ed.GetPoint(LowerLeftPointOptions);
               
PromptCornerOptions PromptCornerOptions = new PromptCornerOptions("Select
opposite point of window",
LowerLeftPointResult.Value);
               
PromptPointResult UpperRightPointResult =
ed.GetCorner(PromptCornerOptions);

 


size=2>               
//default select all entities crossed within
window
               
PromptSelectionResult PromptSelectionResult =
ed.SelectCrossingWindow(LowerLeftPointResult.Value,
UpperRightPointResult.Value);

 


size=2>               
if ((PromptSelectionResult.Status ==
PromptStatus.OK))
               
{
                   
ObjectId[] objIDArray =
null;
                   
//fill an array with the selected
entities
                   
objIDArray = PromptSelectionResult.Value.GetObjectIds();

 


size=2>                   
ObjectId objID = default(ObjectId);

 


size=2>                   
foreach (ObjectId objID_loopVariable in
objIDArray)
                   
{
                       
objID =
objID_loopVariable;
                       
DBObject dbObj =
null;
                       
//open each entity for
reading
                       
dbObj = ta.GetObject(objID,
OpenMode.ForRead);
                       
//tell user the type of each
entity
                       
ed.WriteMessage(dbObj.GetType().ToString());
                   
}
               
}
           
}

 


size=2>            catch
(System.Exception
ex)
           
{
               
ed.WriteMessage(ex.ToString());


size=2>           
}
        }
   
}
}

 

 


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
yes,
i tried that. but it didn't seem to be very helpful.
0 Likes
Message 13 of 15

Anonymous
Not applicable
In C#, where you do not want to supply an optional parameter, you supply the
constant 'System.Type.Missing'.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2009
Supporting AutoCAD 2000 through 2009

http://www.acadxtabs.com

Introducing AcadXTabs 2010:
http://www.caddzone.com/acadxtabs/AcadXTabs2010.htm


wrote in message news:[email protected]...
I tried, and it seems the converter doesn't fill out the missing parameters
which are required by C# and not required by VB.
0 Likes
Message 14 of 15

Anonymous
Not applicable

Since the SelectCrossingWindow method
is overloaded use the version with just the corner parameters. No need for
optional parameters.

 

Joe ...

 


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
I
tried, and it seems the converter doesn't fill out the missing parameters
which are required by C# and not required by VB.
0 Likes
Message 15 of 15

Anonymous
Not applicable
Thanks, Tony.
the System.Type.Missing is what I used in my first post. it compiled but the function didn't return any valid objects.
0 Likes