I need to insert an external DWG into an AutoCAD drawing through a C # plugin. I need to “ask” the user about the insertion point and rotation of the inserted block. Until now, I have always used the lisp function, which calls the "._- insert" command, which gives a thumbnail of the block under the mouse, allows the user to click on the drawing to set the insertion point, and from that point allows the user to click again to set the rotation. Now I want to avoid using lisp or using the low-level API for AutoCAD because I need a solution that runs in various CAD environments. I found something like this:
public static void InsertDwg(string dwgName) { CADAPI.ApplicationServices.Document doc = CADAPI.ApplicationServices.Application.DocumentManager.MdiActiveDocument; CADDB.Database db = doc.Database; CADAPI.EditorInput.Editor ed = doc.Editor; CADDB.ObjectId ObjId; using (CADDB.Transaction trx = db.TransactionManager.StartTransaction()) { CADDB.BlockTable bt = db.BlockTableId.GetObject(CADDB.OpenMode.ForRead) as CADDB.BlockTable; CADDB.BlockTableRecord btrMs = bt[CADDB.BlockTableRecord.ModelSpace].GetObject(CADDB.OpenMode.ForWrite) as CADDB.BlockTableRecord; using (CADDB.Database dbInsert = new CADDB.Database(false, true)) { dbInsert.ReadDwgFile(dwgName, CADDB.FileOpenMode.OpenForReadAndAllShare, true, string.Empty); ObjId = db.Insert(Path.GetFileNameWithoutExtension(dwgName), dbInsert, true); } CADAPI.EditorInput.PromptPointOptions ppo = new CADAPI.EditorInput.PromptPointOptions("\nInsertion Point"); CADAPI.EditorInput.PromptAngleOptions ppa = new CADAPI.EditorInput.PromptAngleOptions("\nInsert Rotation"); CADAPI.EditorInput.PromptPointResult ppr; ppr = ed.GetPoint(ppo); CADAPI.EditorInput.PromptDoubleResult ppd = ed.GetAngle(ppa); if (ppr.Status == CADAPI.EditorInput.PromptStatus.OK) { CADGEOM.Point3d insertPt = ppr.Value; CADDB.BlockReference bref = new CADDB.BlockReference(insertPt, ObjId); btrMs.AppendEntity(bref); trx.AddNewlyCreatedDBObject(bref, true); trx.Commit(); } } }
But I have two problems: The main thing is that there is no preview under the arm. Secondly, the user needs to click 3 times instead of 2 to set the insertion point and rotation.
Is there a way that some SendCommand is not using and all this? TIA
source share