CAD insert block with thumbnail under mouse

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

+4
source share
2 answers

Jigging seems to be a way to do a preview. I have three links for you.

The first example of creating a simple jig with polylines - you can expand it to a block.

The second link is similar, but applies to the connection. This applies to the rectangle, but can again be resized to fit the block.

The third link describes another method - the AutoCAD transition graphical interface. You must use AutoCAD 2009 or later to use this method.

The last two links are taken from through an interface where you can find some more examples and is a very good starting point if you have problems, especially for C # coding.

+1
source

You want to use the AcEdJig class. It provides a preview. You will need to write code to collect the insertion and rotation points and to transform the block accordingly.

Here is the first link from my Google search, for example, the usage code.

0
source

Source: https://habr.com/ru/post/1398631/


All Articles