Querying for XCLIP information inside AutoCAD using .NET 这里下面观众讨论了
How do I determine if an x-clip boundary is inverted?
看起来Autodesk忘记了通过API公开此设置,或将其包含在DXF输出中. 也许您可以通过调用 SpatialFilter.ClipVolumeIntersectsExtents() 来确定它,它的内容完全在边界之内. 该设置通过 DwgOutFields() 提交给DWG文件管理器,因此,如果所有其他操作均失败,则可以编写一个自定义AcDbDwgFiler来捕获该设置。
首先说明一下,根据以上的帖子,我们会得到一个消息是,桌子并没有封装好cad的块裁剪边界翻转部分.
然后我翻了翻api,在Acad2015版本上面是已经加了一个 SpatialFilter.Inverted 这个函数.
而我们低版本需要的就是重写出一个 Inverted ..
最后要进行刷新.
这样就完成了.
但是要注意下面的函数,它们只是个例子,没有提供撤销回滚的时候要刷新的操作...这个部分大家自己自行制作.
命令主函数部分:
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
public static partial class Command_jjMoveBlockCropBoundary { //选择图块,进行反向裁剪 [CommandMethod("test", CommandFlags.Modal | CommandFlags.UsePickSet | CommandFlags.Redraw | CommandFlags.Session)] public static void test() { Database db = HostApplicationServices.WorkingDatabase;//当前的数据库 Editor ed = Application.DocumentManager.MdiActiveDocument.Editor; var peo = new PromptEntityOptions(Environment.NewLine + "点选图块:") { AllowObjectOnLockedLayer = false, AllowNone = false }; var gt = ed.GetEntity(peo); if (gt.Status != PromptStatus.OK) { return; } using (Application.DocumentManager.MdiActiveDocument.LockDocument())//锁文档 用CommandFlags.Session就要锁,否则eLockViolation { using (Transaction tr = db.TransactionManager.StartTransaction()) { var ent = tr.GetObject(gt.ObjectId, OpenMode.ForRead); if (ent is BlockReference acBlkRef) { SpatialFilter blockBoundaryInfo = BlockBoundaryInfo(acBlkRef, tr);//块裁剪边界信息 if (blockBoundaryInfo != null) { //直接设置为反向 blockBoundaryInfo.UpgradeOpen(); #if false //这个在2015以上版本有,但是下面的操作是通用的 blockBoundaryInfo.Inverted = !blockBoundaryInfo.Inverted; #endif var fa = blockBoundaryInfo.Inverted(out XmDwgFiler xmDwgFiler); blockBoundaryInfo.SetInverted(xmDwgFiler); blockBoundaryInfo.DowngradeOpen(); acBlkRef.UpgradeOpen(); acBlkRef.RecordGraphicsModified(true);//记录图元已修改,这个之前要ent.UpgradeOpen() acBlkRef.DowngradeOpen(); } } tr.Commit(); } } }
判断和设置部分.
/// <summary> /// 边界是否为反向裁剪 /// </summary> /// <param name="spatialFilter">裁剪信息</param> /// <returns></returns> public static bool Inverted(this SpatialFilter spatialFilter, out XmDwgFiler xmDwgFiler) { xmDwgFiler = new XmDwgFiler(); spatialFilter.DwgOut(xmDwgFiler); var f = xmDwgFiler.UInt16List[1]; if (f != 1) { return false; } else { return true; } } /// <summary> /// 设定反向裁剪 /// </summary> /// <param name="spatialFilter">裁剪数据</param> /// <param name="xmDwgFiler">原始数据</param> /// <returns></returns> public static void SetInverted(this SpatialFilter spatialFilter, XmDwgFiler xmDwgFiler) { if (xmDwgFiler.UInt16List[1] == 1) { xmDwgFiler.UInt16List[1] = 0; } else { xmDwgFiler.UInt16List[1] = 1; } spatialFilter.DwgIn(xmDwgFiler); }
继承DwgFiler的类,超长的部分...
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
public class XmDwgFiler : DwgFiler { public FilerType m_FilerType; public ErrorStatus m_FilerStatus; public #if AC2008 int #else long #endif m_Position; //