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

Select a Text from AutoCAD and to Display in C# windows forms

8 REPLIES 8
Reply
Message 1 of 9
Micky_1
3896 Views, 8 Replies

Select a Text from AutoCAD and to Display in C# windows forms

Dear All,

Season greetings to all experts,

 

with respect to above subject,

 

using System.Runtime.InteropServices;

using Autodesk.AutoCAD.Interop;

 

privatevoid button2_Click(object sender, EventArgse)

{

AcadApplication AcadApp = new Autodesk.AutoCAD.Interop.AcadApplication();

 

AcadDocument doc1 = AcadApp.Documents.Open("c:\\test.dwg");

AcadApp.Visible =true;

AcadApp.ZoomExtents();

double[] startPoint = newdouble[3]; 

double[] endPoint = newdouble[3];

startPoint[0] = 0; startPoint[1] = 0; startPoint[2] = 0;

endPoint[0] = 20; endPoint[1] = 20; endPoint[2] = 0;

 

AcadSelectionSet ssetObj = AcadApp.ActiveDocument.SelectionSets.Add("ss1");

 

ssetObj.Select(Autodesk.AutoCAD.Interop.Common.

AcSelect.acSelectionSetCrossingPolygon,startPoint,endPoint,Type.Missing, Type.Missing);

 

}

 

the idea is to select the AutoCAD text by crossingPolygon and then to display the selected text in the C# windows form label1.text.

 

Could you please help for this above request.

 

Thanks in Advance.

 

regards,

Micky.

 

8 REPLIES 8
Message 2 of 9
Balaji_Ram
in reply to: Micky_1

Hi Micky,

 

Greetings to you too 🙂

 

Will a pure .Net API route suit your needs ? You will not need the COM API for this :

 

Here is a sample code :

 

            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed = doc.Editor;

            PromptSelectionOptions pso = new PromptSelectionOptions();
            pso.MessageForAdding = "\nSelect the entities";
            pso.SingleOnly = false;

            PromptSelectionResult psr = ed.GetSelection(pso);

            if (psr.Status != PromptStatus.OK) return;
            SelectionSet ss = psr.Value;

            foreach (SelectedObject selectedObj in ss)
            {
                switch (selectedObj.SelectionMethod)
                {
                    case SelectionMethod.Crossing:
                    {
                        CrossingOrWindowSelectedObject crossingWindSelectedObj = selectedObj as CrossingOrWindowSelectedObject;
                        break;
                    }
                }
            }

 The SelectionMethod enum has other values for Window selection and so on. You can check it out yourself.

 

 



Balaji
Developer Technical Services
Autodesk Developer Network

Message 3 of 9
norman.yuan
in reply to: Balaji_Ram

The OP is obviously doing a stand-alone EXE app that automate AutoCAD (or the OP would not have to have code "new AcadApplication();" , thus cannot use .NET API.

 

To OP:

 

In your Select() method, you only pass in 2 points, which cannot form a polygon, thus, the first argument of the Select() method should be acSelectionSetFence.

 

Since your selecting target is text, it would be better to supply a selection filter (the last 2 arguments of the Select() method).

 

Anyway, assume the Select() method does return a set of AcadEnity, you simply loop through the SelectionSet to retrieve test string, like this:

 

StringBuillder txt=new StringBuilder();

 

foreach (object ent in ssetObj)

{

    AcadText t=ent as AcadText

    if (T!=null)

    {

        txt.Append(t.TextString + "\n");

    }

}

 

//Show the text clollected in message box, or in your form.

MessageBox.Show(t.ToString());

 

Of course, if your selection target alos include MText, then you need to deal with it accordingly.

 

 

 

Message 4 of 9
Micky_1
in reply to: Balaji_Ram

Dear Mr.Balaji,

 

Season Greetings,

 

Thanks for your quick response,

 

I am a beginer for .Net C#, that's why I am struggling a bit.

 

In my codings I have some error in crossingpolygon selection method, rest everything working well.

 

I am in need of 2 things,

 

1. select a Text from AutoCAD by crossingpolygon method,

 

2. store it in a string varible to display in C# windows forms.

 

Could you please help me for this above request,

 

I am trying hard to learn this .Net, I have a big hope that as soon as possible i will be getting a clear understanding of .net.

 

Thanks & regards,

Micky.

Message 5 of 9
Hallex
in reply to: Micky_1

If you're using Interop better yet to define variables explicitly

before you will be pulling them to the method / function

From other hand you confused the selection mode

try this code snip instead and tell us about result after 🙂

{code} 

object miss = Type.Missing;
AcadSelectionSet ssetObj = AcadApp.ActiveDocument.SelectionSets.Add("ss1");
Autodesk.AutoCAD.Interop.Common.AcSelect mode = AcSelect.acSelectionSetCrossing;
ssetObj.Select(mode, startPoint, endPoint, miss, miss);
MessageBox.Show(ssetObj.Count.ToString());{code}

 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Message 6 of 9
Micky_1
in reply to: norman.yuan

Dear Mr. Norman,

 

Season Greetings,

 

thanks for your response,

 

for crossingpolygon selection method I using bottom left corner and top right corner only,

 

Could you please see my reply post to Mr. Balaji, that's my problem and I got struck.

 

Thanks & regards,

Micky.

Message 7 of 9
norman.yuan
in reply to: Micky_1

OK, simply call

 

ssetobj.Select(acSelectionSetWindow, startPoint, endPoint,....)

Message 8 of 9

or rather acSelectionSetCrossing, but not acSelectionSetCrossingPolygon.

Dave O.                                                                  Sig-Logos32.png
Message 9 of 9
Micky_1
in reply to: Hallex

Dear Mr. Hallex,

 

Thanks very much for your kindness & support, the code is working well.

 

where I will get reference or help file for the all the methods?

 

for examples :

 

ssetObj.Select(mode, startPoint, endPoint, miss, miss);

 

[object filter Type = Type.missing] --- where to find examples or help files?

 

[object filter Data = Type.missing]--- where to find examples or help files?

 

for examples :

AcadDocument doc1 = acApp.Documents.Open(textBox1.Text);

In open method,

I have given only the file name, if I wnat to give other two inputs then how?

 

so where I will get reference or help files for all the methods.

 

best regards,

Micky.

 

 

 

 

 

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