Thanks, I've made something that works:
object obj = System.Runtime.InteropServices.Marshal.GetActiveObject("AutoCAD.Application");
AcadApplication acad = (AcadApplication)obj as AcadApplication;
acad.WindowState = AcWindowState.acMax;
AcadDocument adoc = (AcadDocument)acad.ActiveDocument as AcadDocument;
AcadUtility acutil = (AcadUtility)adoc.Utility as AcadUtility;
string prompt1 = null;
double[] pnt;
prompt1 = "Enter block insert point: ";
pnt = acutil.GetPoint(Type.Missing, prompt1);
MessageBox.Show(pnt[0].ToString()); But tell me one more thing please.
I have also written code, which works good from AutoCAD application like:
using acadApp = Autodesk.AutoCAD.ApplicationServices.Application;
Editor ed = acadApp.DocumentManager.MdiActiveDocument.Editor;
Database db = HostApplicationServices.WorkingDatabase;
using (Transaction trans = db.TransactionManager.StartTransaction())
{
...
Matrix3d ucs = ed.CurrentUserCoordinateSystem;
Vector3d normal = new Vector3d(0, 0, 1);
normal = normal.TransformBy(ucs);
Point3d finalRodStart = new Point3d(newStartX, newStartY, 0).TransformBy(ucs);
Point3d finalRodEnd = new Point3d(newEndX, newEndY, 0).TransformBy(ucs);
Line Rod = new Line(finalRodStart, finalRodEnd);
BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead);
BlockTableRecord btr = (BlockTableRecord)trans.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
// get current layer
ObjectId currentLayer = db.Clayer;
// get layer to draw rod
ObjectId drawingLayer = layers.SetDrawingLayer(trans, db, layersEnum.layer.K_ZBR).Id;
Rod.LayerId = (drawingLayer == ObjectId.Null) ? db.Clayer : drawingLayer;
// if set, go back to the previous layer
if (!Properties.Settings.Default.RememberPreviousLayer)
{
db.Clayer = Rod.LayerId;
}
btr.AppendEntity(Rod);
trans.AddNewlyCreatedDBObject(Rod, true);
trans.Commit();
}
Am I able to use this code from WinForm level?
Is there any way to cast running (or start acad) application within Autodesk.AutoCAD.ApplicationServices.Application class?