cad.net 块裁剪边界反向修剪

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的类,超长的部分...

    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;
            }
        }
    } 

原文地址:https://www.cnblogs.com/JJBox/p/11614714.html

时间: 2024-10-29 17:54:20

cad.net 块裁剪边界反向修剪的相关文章

创建CAD图块,便于粘贴使用

创建CAD图块,便于粘贴使用.在CAD制图设计过程中,会遇到需要重复绘制相同的图形的情况.这个时候若是通过创建CAD图块的设置,在后续制图过程中,遇到需要绘制相同图块的时候,就可粘贴创建的块到当前图形当中,方便又实用.小编今天为大家演示一下具体步骤.演示步骤如下: 步骤一:首先下载安装需要的CAD软件--迅捷CAD编辑器然后运行. 步骤二:切换到"编辑器"菜单选项,开始编辑绘制.我们可以先在绘图区域绘制好需要创建的图块图形. 步骤三:图形绘制完成后选择所绘制的图形,点击工具栏里&quo

CAD根据块名过滤(网页版)

js中使用如下: var ss = mxOcx.NewSelectionSet(); // 创建过滤对象. var spFilte = mxOcx.NewResbuf(); // 把图块对象,当着过滤条件. spFilte.AddStringEx("INSERT", 5020); // 过滤块名 spFilte.AddStringEx("123",2); // 得到图上,所有图块对象. ss.Select2(5, null, null, null, spFilte)

使用FME将CAD中块参照数据转换为shp数据

暴露出需要导出的字段值,首先在数据查看器中看看CAD中各个图层分别有哪些隐含的字段. CAD快参照中含有多个部分,需要将点按照原始编码聚合成一个点. 属性字段创建,并按照属性字段一一对应CAD中的字段. 采用中心点的方式数据可能会有偏差,因此采用数据中的X\Y坐标创建点. 生成shp点数据. 原文地址:https://www.cnblogs.com/chenxinjourney/p/11161976.html

CAD关于块表操作2(com接口网页版)

E   添加块表记录 下面代码,判断块表中是否有指定名称的块表记录,如果没有就增一个块表记录. function AddBlockRrecord(sName,blkOriginPoint) { // 取当前数据库. var curDatabase = mxOcx.GetDatabase(); // 得到块表 var blkTable = curDatabase.GetBlockTable(); // 判断块表是否已经有该名称的块名. if (blkTable.Has(sName)) { var

CAD制图中修剪与延伸的使用技巧

CAD中修剪命令是编辑命令中使用频率非常高的一个命令,延伸命令和修剪的命令效果相反,两个命令在使用过程中可以通过按Shift键相互转换.修剪和延伸通过缩短或拉长图形.删除图形多余部分,使图形与其他图形的边相接.因为有着两个命令,我们在绘制图形时可以不用特别精确控制长度,甚至可以用构造线.射线来代替直线,然后通过修剪和延伸对图形进行休整. 一.修剪和延伸的基本操作 修剪和延伸的基本技巧首先是选择,首先要选择修剪.延伸边界,或称为切割对象,也就是选择作为修剪和延伸的基准的对象,然后就是选择要被修剪或

如何创建CAD外部图块

我们在CAD绘图设计的时候,常常会遇到CAD图块的创建的相关问题,其中创建CAD外部图块就是很常见的问题之一.例如我们在一张图纸绘制的时候使用过的图块,可能在其他图纸绘制的时候也需要重复使用,这时候则需要创建外部图块,也就是永久块.外部图块不依赖于当前图形,可以在任意图形文件中调用并且插入.小编今天就给大家演示一下,如何创建CAD外部图块的具体步骤.演示步骤如下:步骤一:执行"WBLOCK"命令1.首先我们运行迅捷CAD编辑器专业版,在绘图窗口里,我们绘制出一个需要长久使用的图形(这里

CAD快捷键

一.绘图命令 直线:L 用法:输入命令L/回车/鼠标指定第一点/输入数值(也就是指定第二点)/回车(这时直线就画出来了)/回车(结束命令) 射线:RAY 用法:输入命令RAY/回车/鼠标指定射线起点/指定通过点/回车(结束命令) 构造线:XL 用法:输入命令XL/回车/鼠标指定构造线起点/指定通过点/回车(结束命令) 多段线:PL 用法1:同直线命令 用法2:输入命令PL/回车/指定起点/输入W(绘制带有宽度的线)/回车/指定线起点宽度/回车/指定线结束点宽度/回车/输入数值(线的长度值)/回车

CAD绘图大师都在用的46组快捷键,高效绘图必备

学习CAD 是一个需要慢慢积累的过程,千万不要遇到一点小困难就退缩,有困难我们就一起克服它!今天小编也是来帮助大家克服困难的!很多小伙伴学习CAD已经有一段时间了,但是发现自己的绘图效率还是不高,没关系,今天小编就来给大家分享一些常用的快捷键,帮助大家快速绘图! 一.修剪命令 1.TR修剪 首先我们下来说说关于修剪的命令,修剪命令在CAD中还蛮常用到的,那么你知道在CAD中有多少种修剪方式吗? 第一种就是用TR命令修剪啦,输入TR命令之后,连按两次空格,点击要修剪的部分即可剪除! 2.F倒圆角快

计算机图形学 - 线段裁剪 - Liang Barsky算法(梁友栋算法)

算法描述: Liang_Barsky算法的基本出发点是直线的参数方程.给出任意一条直线段,两端点分别为和,令, 则直线的参数方程为: 如果直线上任意一点位于窗口内,则必须满足下列关系式: 上述不等式可以表示为: 其中p和q定义为: 任何一条直线如果平行于某一条裁剪边界,则有,下标k 对应于直线段平行的窗口边界(,并且分别表示裁剪窗口的左.右.下.上边界).如果对于某一个k值,满足,那么直线完全在窗口的外面,可以抛弃.如果,则该直线在它所平行的窗口边界的内部,还需要进一步计算才能确定直线是否在窗口