cad.net undo返回操作
这是提供给从lisp转移到c#实现undo返回步数的函数.
一个需要引用com的dll调用com的方法,
一个是反射调用内部的方法(内置函数,你不需要引用了,可参考VBA帮助文档).
相关阅读
明经通道guxl的错误处理帖子
Acad上面调用
引用com的dll
引用dll:
Autodesk.AutoCAD.Interop.Common.dll
Autodesk.AutoCAD.Interop.dll
using Acap = Autodesk.AutoCAD.ApplicationServices.Application;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.Interop; //这是acad的com接口
using System.Diagnostics;
namespace JoinBox
{
public static class Com
{
#if NET35
public static AcadDocument Adm { get; } = Acap.DocumentManager.MdiActiveDocument.AcadDocument as AcadDocument;
#else
public static AcadDocument Adm { get; } = Acap.DocumentManager.MdiActiveDocument.GetAcadDocument() as AcadDocument;
#endif
#if !HC2020
public static AcadApplication App { get; } = Acap.AcadApplication as AcadApplication;
#else
public static GcadApplication App { get; } = Acap.AcadApplication as GcadApplication;
#endif
}
}
引用com的dll实现:
需要做到将已经编组的结束并开始新的编组.
这样不会引起嵌套编组.
using Acap = Autodesk.AutoCAD.ApplicationServices.Application;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.Interop;
using System.Diagnostics;
namespace JoinBox
{
// kean谈论到undo撤回的操作
// https://www.keanw.com/2008/09/more-qListet-comm.html
public static partial class CadSystem
{
/// <summary>
/// 命令动作编组
/// </summary>
/// <param name="flag"><see langword="true"/>开始编组|<see langword="false"/>结束编组</param>
public static void Undo(bool flag)
{
try
{
if (!flag)
{
Com.Adm.EndUndoMark();//结束编组
return;
}
if (Getvar("Undoctl") == "8")//存在活动编组
Com.Adm.EndUndoMark(); //结束
Com.Adm.StartUndoMark(); //开始
}
catch (System.Exception e)
{
var msg = $"Undo出错,参数{flag},信息:" + e.Message;
Debug.WriteLine(msg);
Debugger.Break();
UndoVBA(flag);
}
}
/// <summary>
/// 命令动作编组 调用VBA方法
/// </summary>
/// <param name="flag"><see langword="true"/>开始编组|<see langword="false"/>结束编组</param>
public static void UndoVBA(bool flag)
{
object adoc = TypeTool.Get(Com.App, "ActiveDocument");
if (!flag)
{
TypeTool.Set(adoc, "EndUndoMark", null); //结束编组
return;
}
if (Getvar("Undoctl") == "8") //存在活动编组
TypeTool.Set(adoc, "EndUndoMark", null); //结束
TypeTool.Set(adoc, "StartUndoMark", null); //开始
}
}
}
using System.Reflection;
namespace JoinBox {
public static class TypeTool {
/// <summary>
/// 获取方法
/// </summary>
/// <param name="obj">获取的对象</param>
/// <param name="fangfaming">方法名</param>
/// <returns></returns>
public static object Get(object obj, string fangfaming)
{
return obj.GetType().InvokeMember(fangfaming, BindingFlags.GetProperty, null, obj, null);
}
/// <summary>
/// 设置方法的参数
/// </summary>
/// <param name="obj">设置的对象</param>
/// <param name="fangfaming">方法名</param>
/// <param name="args">参数</param>
/// <returns>设置的对象</returns>
public static object Set(object obj, string fangfaming, object[] args)
{
return obj.GetType().InvokeMember(fangfaming, BindingFlags.InvokeMethod, null, obj, args);
}
}
}
其他CAD引入com
浩辰Gcad
引入dll:
gcax.tlb
添加命名空间:
using GrxCAD.GraphicsInterface;
using GcadVbaLib;
中望Zcad
中望上面实现跟Acad似乎一样,名字改改就好了...
可以在 ZWCAD.exe 反射调用.
引入dll:
lnterop.ZWCAD.dll
添加命名空间:
using ZWCAD.Interop;
相关阅读
撤回需要注意事务上面的处理,见cad.net 合并图层错误 ctrl+u出错 !dbenti.cpp@3310:eWasErased错误
(完)