[DllImport("accore.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern int acedRedraw(IntPtr name, int mode);
[CommandMethod("MyRedraw")]
public void MyRedraw()
{
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
doc.ViewChanged += doc_ViewChanged;
drawVecs();
Application.Idle += Application_Idle;
ed.GetPoint("\nДля выхода укажите точку: ");
Application.Idle -= Application_Idle;
doc.ViewChanged -= doc_ViewChanged;
acedRedraw(IntPtr.Zero, 1);
}
void drawVecs()
{
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
// ed.UpdateScreen();
Point3d center3d = (Point3d)Application.GetSystemVariable("VIEWCTR");
double height = (double)Application.GetSystemVariable("VIEWSIZE");
Point2d screensize = (Point2d)Application.GetSystemVariable("SCREENSIZE");
double aspect = screensize.X / screensize.Y;
double width = height * aspect;
Point3d leftUp = new Point3d(center3d.X - width * 0.4, center3d.Y + height * 0.4, 0);
Point3d leftDown = new Point3d(center3d.X - width * 0.4, center3d.Y - height * 0.4, 0);
Point3d rightUp = new Point3d(center3d.X + width * 0.4, center3d.Y + height * 0.4, 0);
Point3d rightDown = new Point3d(center3d.X + width * 0.4, center3d.Y - height * 0.4, 0);
acedRedraw(IntPtr.Zero, 1);
ed.DrawVector(leftDown, leftUp, 2, false);
ed.DrawVector(leftUp, rightUp, 2, false);
ed.DrawVector(rightUp, rightDown, 2, false);
ed.DrawVector(rightDown, leftDown, 2, false);
ed.DrawVector(leftUp, rightDown, 2, false);
ed.DrawVector(leftDown, rightUp, 2, false);
}
bool redraw = false;
void Application_Idle(object sender, EventArgs e)
{
if (redraw)
{
drawVecs();
redraw = false;
}
}
void doc_ViewChanged(object sender, EventArgs e)
{
redraw = true;
}