How to open an auto cad file drawing and select all (whatever obj are in the drawing) in c#?

How to open an auto cad file drawing and select all (whatever obj are in the drawing) in c#?

AmanKumar1
Participant Participant
404 Views
2 Replies
Message 1 of 3

How to open an auto cad file drawing and select all (whatever obj are in the drawing) in c#?

AmanKumar1
Participant
Participant

-

0 Likes
405 Views
2 Replies
Replies (2)
Message 3 of 3

AmanKumar1
Participant
Participant

Actually iam new to this autocad .net api 

Can you tell me below code is right ?

 

public void Method()
{
string strFileName = "C:\\Users\\Desktop\\api.dwg";
DocumentCollection DocMgr = Application.DocumentManager;
Document Doc = DocMgr.CurrentDocument;
Database db = Doc.Database;
Editor ed = Doc.Editor;
if (File.Exists(strFileName))
{
DocMgr.Open(strFileName, false);
{
db.ReadDwgFile(strFileName, FileOpenMode.OpenForReadAndWriteNoShare, false, null);
using (Transaction tr = db.TransactionManager.StartTransaction())
{
//create a selection set and select all objects in drawing
PromptSelectionResult psr = ed.SelectAll();
SelectionSet ss = psr.Value;
if (psr.Status==PromptStatus.OK) //if the object is selected
{
foreach(SelectedObject sObj in ss)
{
if (sObj != null)
{

}
}
}
}
}
}
else
{
DocMgr.MdiActiveDocument.Editor.WriteMessage("File " + strFileName +
" does not exist.");
}

}

0 Likes