Hello,
i have test and found a reason. If have the destination dwg the visual style realitic works all fine, but our dwg have visual style 2d-wireframe.
On this style do not correctly refresh entitys. We work with AutoCAD 2017 (it forced by company).
here is an minimalisty code example that works:
@n.yuan (when set MdiActiveDocument brake the active command in soureDocument, set CurrentDocument works).
[CommandMethod("MYTEST", "TEST", CommandFlags.NoMultiple | CommandFlags.Modal | CommandFlags.Session)]
public void pTest()
{
try
{
Boolean run = true;
Document sourceDoc = Application.DocumentManager.MdiActiveDocument;
Editor acEditor = sourceDoc.Editor;
if (Application.DocumentManager.Count == 2)
{
Transaction destTrans = null;
Document destDoc = null;
foreach (Document doc in Application.DocumentManager)
{
if (!doc.Database.FingerprintGuid.Equals(sourceDoc.Database.FingerprintGuid))
{
destDoc = doc;
break;
}
}
if (destDoc != null)
{
PromptPointResult acPromptPointResult;
PromptPointOptions acPromptPointOptions;
acPromptPointOptions = new PromptPointOptions("Please take markerpoint");
acPromptPointOptions.UseBasePoint = false;
ObjectId pLayerId = destDoc.Database.Clayer;
do
{
Point3d start = Point3d.Origin;
acPromptPointResult = acEditor.GetPoint(acPromptPointOptions);
if ((acPromptPointResult.Status == PromptStatus.OK))
{
start = acPromptPointResult.Value;
// line start -1 m to start + 1 m
Point3d newStart = new Point3d(start.X - 1.0, start.Y, start.Z);
Point3d newEnd = new Point3d(start.X + 1.0, start.Y, start.Z);
using (destTrans = destDoc.Database.TransactionManager.StartTransaction())
{
Line newline = new Line(newStart, newEnd);
newline.SetDatabaseDefaults(destDoc.Database);
newline.LayerId = pLayerId;
newline.LinetypeId = SymbolUtilityServices.GetLinetypeByLayerId(destDoc.Database);
BlockTable acBlockTable = (BlockTable)destTrans.GetObject(destDoc.Database.BlockTableId, OpenMode.ForRead, false);
BlockTableRecord acBlockTableRecord = (BlockTableRecord)destTrans.GetObject(destDoc.Database.CurrentSpaceId, OpenMode.ForWrite, false);
acBlockTableRecord.AppendEntity(newline);
destTrans.AddNewlyCreatedDBObject(newline, true);
destTrans.Commit();
// Force FlushGraphics
Application.DocumentManager.CurrentDocument = destDoc;
destDoc.TransactionManager.EnableGraphicsFlush(true);
destDoc.TransactionManager.FlushGraphics();
Autodesk.AutoCAD.Internal.Utils.FlushGraphics();
Application.DocumentManager.CurrentDocument = sourceDoc;
}
}
else
{
acEditor.WriteMessage("\n[CANCEL]\n");
run = false;
}
} while (run);
}
else
acEditor.WriteMessage("\nonly with 2 DWG's!\n");
}
else
acEditor.WriteMessage("\nonly with 2 DWG's!\n");
}
catch (Autodesk.AutoCAD.Runtime.Exception ex) { Log.LogException(ex); }
catch (System.Exception ex) { Log.LogException(ex); }
}
How can i also refresh the 2d-wireframe?
regards Mario