using System;
using System.Runtime.InteropServices;
using System.Reflection;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;
using AcRx = Autodesk.AutoCAD.Runtime;
using AcAp = Autodesk.AutoCAD.ApplicationServices;
using AcDb = Autodesk.AutoCAD.DatabaseServices;
using AcGe = Autodesk.AutoCAD.Geometry;
using AcEd = Autodesk.AutoCAD.EditorInput;
[assembly: CommandClass(typeof(Rivilis.MyCommands))]
namespace Rivilis
{
public class SuppressUpdateDisplay : IDisposable
{
[DllImport("accore.dll", EntryPoint = "?acedIsUpdateDisplayPaused@@YA_NXZ",
CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.I1)]
private static extern bool acedIsUpdateDisplayPaused13();
[DllImport("acad.exe", EntryPoint = "?acedIsUpdateDisplayPaused@@YA_NXZ",
CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.I1)]
private static extern bool acedIsUpdateDisplayPaused12();
[DllImport("accore.dll", EntryPoint = "?acedUpdateDisplay@@YAXXZ",
CallingConvention = CallingConvention.Cdecl)]
private static extern void acedUpdateDisplay13();
[DllImport("acad.exe", EntryPoint = "?acedUpdateDisplay@@YAXXZ",
CallingConvention = CallingConvention.Cdecl)]
private static extern void acedUpdateDisplay12();
[DllImport("accore.dll", EntryPoint = "?acedUpdateDisplayPause@@YAX_N@Z",
CallingConvention = CallingConvention.Cdecl)]
private static extern void acedUpdateDisplayPause13(
[MarshalAs(UnmanagedType.I1)] bool bPaused);
[DllImport("acad.exe", EntryPoint = "?acedUpdateDisplayPause@@YAX_N@Z",
CallingConvention = CallingConvention.Cdecl)]
private static extern void acedUpdateDisplayPause12(
[MarshalAs(UnmanagedType.I1)] bool bPaused);
public static bool acedIsUpdateDisplayPaused()
{
if (Application.Version.Major > 18)
return acedIsUpdateDisplayPaused13();
else
return acedIsUpdateDisplayPaused12();
}
public static void acedUpdateDisplayPause(bool bPaused)
{
if (Application.Version.Major > 18)
acedUpdateDisplayPause13(bPaused);
else
acedUpdateDisplayPause12(bPaused);
}
public static void acedUpdateDisplay()
{
if (Application.Version.Major > 18)
acedUpdateDisplay13();
else
acedUpdateDisplay12();
}
public SuppressUpdateDisplay()
{
bWasPaused = acedIsUpdateDisplayPaused();
acedUpdateDisplayPause(true);
}
public void Dispose()
{
acedUpdateDisplay();
acedUpdateDisplayPause(bWasPaused);
}
private bool bWasPaused;
}
public class MyCommands
{
/// <summary>
/// Пример для проверки использования класса
/// SuppressUpdateDisplay
/// </summary>
[CommandMethod("TestSuppress")]
public void TestSuppress()
{
using (SuppressUpdateDisplay UI = new SuppressUpdateDisplay())
{
AcAp.Document doc = AcAp.Application.DocumentManager.MdiActiveDocument;
AcDb.Database db = doc.Database;
AcGe.Point3d center = (AcGe.Point3d)Application.GetSystemVariable("VIEWCTR");
center = center.TransformBy(doc.Editor.CurrentUserCoordinateSystem);
double radius = (double)Application.GetSystemVariable("VIEWSIZE") * 0.3;
using (AcDb.BlockTableRecord curSpace =
db.CurrentSpaceId.Open(AcDb.OpenMode.ForWrite) as AcDb.BlockTableRecord)
{
using (AcDb.Circle circle = new AcDb.Circle(center, AcGe.Vector3d.ZAxis, radius))
{
circle.SetDatabaseDefaults(db);
curSpace.AppendEntity(circle);
}
}
doc.Editor.GetString("\nНажмите ENTER для появления окружности.");
}
}
[CommandMethod("UpdatePause")]
public void UpdatePause()
{
SuppressUpdateDisplay.acedUpdateDisplayPause(true);
}
[CommandMethod("UpdateNoPause")]
public void UpdateNoPause()
{
SuppressUpdateDisplay.acedUpdateDisplayPause(false);
SuppressUpdateDisplay.acedUpdateDisplay();
}
}
}