You should post your code in READ-ABLE manner (using the "</>" button!) and post the Exception picture SEPARATELY (not covering the code!).
However, from the partially seeable code, I can see you want to use code to open a drawing and call Editor.Command() against this newly opened drawing. However, you did not show how the code is executed (via a CommandMethod, of course) - application context, or document context.
If the code execute in document context (CommandMethod without Session flag set), your code can open a drawing, however, the newly opened drawing will not become MdiActiveDocument, thus the document's Editor is not avaible; on the other hand, if the CommandMethod does has Session flag set (i.e.) the code is executed in application context, then the newly opened document will indeed becomes MdiActiveDocument upon opening, however, Editor.Command() is not allowed to run in application context.
You might want to explain what you need to do with more information/and show more relevant code.
this is my code. I try to open a dwg file and use shortcut commands to trim entity.But I can not use ed.Command().Thank you
[CommandMethod("test1")]
public void Open()
{
try
{
string filename = @"D:\0.dwg";
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.Open(filename, false);
HostApplicationServices.WorkingDatabase = doc.Database;
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument = doc;
Editor ed = doc.Editor;
Database db=doc.Database;
ed.Command("TRIM");
}
catch (System.Exception ex)
{
int a = 5;
}
}