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 ..
最后要進行刷新.
這樣就完成了.

但是要注意下面的函數,它們只是個例子,沒有提供撤銷回滾的時候要刷新的操作...這個部分大家自己自行制作.
命令主函數部分:
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的類,超長的部分...要注意,我並沒有完美的寫好這個類,它可能不在所有的cad版本上通用,詳情自己去設置....
public class XmDwgFiler : DwgFiler { public FilerType m_FilerType; public ErrorStatus m_FilerStatus; public #if AC2008 int #else long #endif m_Position; //保存數據屬性 public List<IntPtr> AddressList { get; set; } public int AddressListPt = 0; public List<byte[]> BinaryChunkList { get; set; } public int BinaryChunkListPt = 0; public List<bool> BooleanList { get; set; } public int BooleanListPt = 0; public List<byte> ByteList { get; set; } public int ByteListPt = 0; public List<byte[]> BytesList { get; set; } public int BytesListPt = 0; public List<double> DoubleList { get; set; } public int DoubleListPt = 0; public List<Handle> HandleList { get; set; } public int HandleListPt = 0; public List<ObjectId> HardOwnershipIdList { get; set; } public int HardOwnershipIdListPt = 0; public List<ObjectId> HardPointerIdList { get; set; } public int HardPointerIdListPt = 0; public List<short> Int16List { get; set; } public int Int16ListPt = 0; public List<int> Int32List { get; set; } public int Int32ListPt = 0; public List<long> Int64List { get; set; } public int Int64ListPt = 0; public List<Point2d> Point2dList { get; set; } public int Point2dListPt = 0; public List<Point3d> Point3dList { get; set; } public int Point3dListPt = 0; public List<Scale3d> Scale3dList { get; set; } public int Scale3dListPt = 0; public List<ObjectId> SoftOwnershipIdList { get; set; } public int SoftOwnershipIdListPt = 0; public List<ObjectId> SoftPointerIdList { get; set; } public int SoftPointerIdListPt = 0; public List<string> StringList { get; set; } public int StringListPt = 0; public List<ushort> UInt16List { get; set; } public int UInt16ListPt = 0; public List<uint> UInt32List { get; set; } public int UInt32ListPt = 0; public List<ulong> UInt64List { get; set; } public int UInt64ListPt = 0; public List<Vector2d> Vector2dList { get; set; } public int Vector2dListPt = 0; public List<Vector3d> Vector3dList { get; set; } public int Vector3dListPt = 0; //構造函數 public XmDwgFiler() { m_FilerType = FilerType.CopyFiler; m_FilerStatus = ErrorStatus.OK; m_Position = 0; AddressList = new List<IntPtr>(); BinaryChunkList = new List<byte[]>(); BooleanList = new List<bool>(); ByteList = new List<byte>(); BytesList = new List<byte[]>(); DoubleList = new List<double>(); HandleList = new List<Handle>(); HardOwnershipIdList = new List<ObjectId>(); HardPointerIdList = new List<ObjectId>(); Int16List = new List<short>(); Int32List = new List<int>(); Int64List = new List<long>(); Point2dList = new List<Point2d>(); Point3dList = new List<Point3d>(); Scale3dList = new List<Scale3d>(); SoftOwnershipIdList = new List<ObjectId>(); SoftPointerIdList = new List<ObjectId>(); StringList = new List<string>(); UInt16List = new List<ushort>(); UInt32List = new List<uint>(); UInt64List = new List<ulong>(); Vector2dList = new List<Vector2d>(); Vector3dList = new List<Vector3d>(); } public override IntPtr ReadAddress() { if (AddressList.Count() == 0) { return new IntPtr(); } return AddressList[AddressListPt++]; } public override byte[] ReadBinaryChunk() { if (BinaryChunkList.Count() == 0) { return null; } return BinaryChunkList[BinaryChunkListPt++]; } public override bool ReadBoolean() { if (BooleanList.Count() == 0) { return false; } return BooleanList[BooleanListPt++]; } public override byte ReadByte() { if (ByteList.Count() == 0) { return 0; } return ByteList[ByteListPt++]; } public override void ReadBytes(byte[] value) { if (ByteList.Count() == 0) { return; } value = new byte[BytesList[BytesListPt].Length]; BytesList[BytesListPt++].CopyTo(value, 0); } public override double ReadDouble() { if (DoubleList.Count() == 0) { return 0; } return DoubleList[DoubleListPt++]; } public override Handle ReadHandle() { if (HandleList.Count() == 0) { return new Handle(); } return HandleList[HandleListPt++]; } public override ObjectId ReadHardOwnershipId() { if (HardOwnershipIdList.Count() == 0) { return new ObjectId(); } return HardOwnershipIdList[HardOwnershipIdListPt++]; } public override ObjectId ReadHardPointerId() { if (HardPointerIdList.Count() == 0) { return new ObjectId(); } return HardPointerIdList[HardPointerIdListPt++]; } public override short ReadInt16() { if (Int16List.Count() == 0) { return 0; } return Int16List[Int16ListPt++]; } public override int ReadInt32() { if (Int32List.Count() == 0) { return 0; } return Int32List[Int32ListPt++]; } public override Point2d ReadPoint2d() { if (Point2dList.Count() == 0) { return new Point2d(); } return Point2dList[Point2dListPt++]; } public override Point3d ReadPoint3d() { if (Point3dList.Count() == 0) { return new Point3d(); } return Point3dList[Point3dListPt++]; } public override Scale3d ReadScale3d() { if (Scale3dList.Count() == 0) { return new Scale3d(); } return Scale3dList[Scale3dListPt++]; } public override ObjectId ReadSoftOwnershipId() { if (SoftOwnershipIdList.Count() == 0) { return new ObjectId(); } return SoftOwnershipIdList[SoftOwnershipIdListPt++]; } public override ObjectId ReadSoftPointerId() { if (SoftPointerIdList.Count() == 0) { return new ObjectId(); } return SoftPointerIdList[SoftPointerIdListPt++]; } public override string ReadString() { if (StringList.Count() == 0) { return null; } return StringList[StringListPt++]; } public override ushort ReadUInt16() { if (UInt16List.Count() == 0) { return 0; } return UInt16List[UInt16ListPt++]; } public override uint ReadUInt32() { if (UInt32List.Count() == 0) { return 0; } return UInt32List[UInt32ListPt++]; } public override Vector2d ReadVector2d() { if (Vector2dList.Count() == 0) { return new Vector2d(); } return Vector2dList[Vector2dListPt++]; } public override Vector3d ReadVector3d() { if (Vector3dList.Count() == 0) { return new Vector3d(); } return Vector3dList[Vector3dListPt++]; } public override void ResetFilerStatus() { AddressList.Clear(); AddressListPt = 0; BinaryChunkList.Clear(); BinaryChunkListPt = 0; BooleanList.Clear(); BooleanListPt = 0; ByteList.Clear(); ByteListPt = 0; BytesList.Clear(); BytesListPt = 0; DoubleList.Clear(); DoubleListPt = 0; HandleList.Clear(); HandleListPt = 0; HardOwnershipIdList.Clear(); HardOwnershipIdListPt = 0; HardPointerIdList.Clear(); HardPointerIdListPt = 0; Int16List.Clear(); Int16ListPt = 0; Int32List.Clear(); Int32ListPt = 0; Int64List.Clear(); Int64ListPt = 0; Point2dList.Clear(); Point2dListPt = 0; Point3dList.Clear(); Point3dListPt = 0; Scale3dList.Clear(); Scale3dListPt = 0; SoftOwnershipIdList.Clear(); SoftOwnershipIdListPt = 0; SoftPointerIdList.Clear(); SoftPointerIdListPt = 0; StringList.Clear(); StringListPt = 0; UInt16List.Clear(); UInt16ListPt = 0; UInt32List.Clear(); UInt32ListPt = 0; UInt64List.Clear(); UInt64ListPt = 0; Vector2dList.Clear(); Vector2dListPt = 0; Vector3dList.Clear(); Vector3dListPt = 0; m_FilerType = FilerType.CopyFiler; } public override string ToString() { int ptCount = AddressListPt + BinaryChunkListPt + BooleanListPt + ByteListPt + BytesListPt + DoubleListPt + HandleListPt + HardOwnershipIdListPt + HardPointerIdListPt + Int16ListPt + Int32ListPt + Int64ListPt + Point2dListPt + Point3dListPt + Scale3dListPt + SoftOwnershipIdListPt + SoftPointerIdListPt + StringListPt + UInt16ListPt + UInt32ListPt + UInt64ListPt + Vector2dListPt + Vector3dListPt; int ltCount = AddressList.Count() + BinaryChunkList.Count() + BooleanList.Count() + ByteList.Count() + BytesList.Count() + DoubleList.Count() + HandleList.Count() + HardOwnershipIdList.Count() + HardPointerIdList.Count() + Int16List.Count() + Int32List.Count() + Int64List.Count() + Point2dList.Count() + Point3dList.Count() + Scale3dList.Count() + SoftOwnershipIdList.Count() + SoftPointerIdList.Count() + StringList.Count() + UInt16List.Count() + UInt32List.Count() + UInt64List.Count() + Vector2dList.Count() + Vector3dList.Count(); return "\n" + ptCount.ToString() + " DataIn" + "\n" + ltCount.ToString() + " DataOut"; } public override void WriteAddress(IntPtr value) { AddressList.Add(value); } public override void WriteBinaryChunk(byte[] chunk) { BinaryChunkList.Add(chunk); } public override void WriteBoolean(bool value) { BooleanList.Add(value); } public override void WriteByte(byte value) { ByteList.Add(value); } public override void WriteBytes(byte[] value) { BytesList.Add(value); } public override void WriteDouble(double value) { DoubleList.Add(value); } public override void WriteHandle(Handle handle) { HandleList.Add(handle); } public override void WriteHardOwnershipId(ObjectId value) { HardOwnershipIdList.Add(value); } public override void WriteHardPointerId(ObjectId value) { HardPointerIdList.Add(value); } public override void WriteInt16(short value) { Int16List.Add(value); } public override void WriteInt32(int value) { Int32List.Add(value); } public override void WritePoint2d(Point2d value) { Point2dList.Add(value); } public override void WritePoint3d(Point3d value) { Point3dList.Add(value); } public override void WriteScale3d(Scale3d value) { Scale3dList.Add(value); } public override void WriteSoftOwnershipId(ObjectId value) { SoftOwnershipIdList.Add(value); } public override void WriteSoftPointerId(ObjectId value) { SoftPointerIdList.Add(value); } public override void WriteString(string value) { StringList.Add(value); } public override void WriteUInt16(ushort value) { UInt16List.Add(value); } public override void WriteUInt32(uint value) { UInt32List.Add(value); } public override void WriteVector2d(Vector2d value) { Vector2dList.Add(value); } public override void WriteVector3d(Vector3d value) { Vector3dList.Add(value); } public override ErrorStatus FilerStatus { get { return m_FilerStatus; } set { m_FilerStatus = value; } } public override FilerType FilerType { get { return this.m_FilerType; } } #if !AC2008 public override long ReadInt64() { if (Int64List.Count() == 0) { return 0; } return Int64List[Int64ListPt++]; } public override ulong ReadUInt64() { if (UInt64List.Count() == 0) { return 0; } return UInt64List[UInt64ListPt++]; } public override void WriteInt64(long value) { Int64List.Add(value); } public override void WriteUInt64(ulong value) { UInt64List.Add(value); } #endif //https://www.eabim.net//forum.php/?mod=viewthread&tid=169503&extra=page%3D1&page=1& public override void Seek( #if AC2008 int #else long #endif offset, int method) { Editor ed = Application.DocumentManager.MdiActiveDocument.Editor; ed.WriteMessage(MethodInfo.GetCurrentMethod().Name + " = " + " \n "); } public override #if AC2008 int #else long #endif Position { get { return m_Position; } } }
