Beispiel #1
0
        /// <summary>
        /// 剪切矩形区内的图形
        /// </summary>
        /// <param name="cutBox"></param>
        public static void TrimMap(Polyline cutBox)
        {
            //关闭对象捕捉功能避免误删除
            cadApplication.SetSystemVariable("SNAPMODE", 0);
            cadApplication.SetSystemVariable("MODEMACRO", "正在修剪");
            ////获取最小与最大点
            Point3d minPoint = cutBox.GeometricExtents.MinPoint;
            Point3d maxPoint = cutBox.GeometricExtents.MaxPoint;
            ////设置缩放视口
            //设置缩放视口
            //CADTools.RunCommand(true, "Zoom", "e",
            //    new Point3d(minPoint.X - 10, minPoint.Y - 10, 0), new Point3d(maxPoint.X + 10, maxPoint.Y + 10, 0));
            //CADTools.RunCommand(false, "Zoom", "W"
            //    , new Point3d(minPoint.X - 10, minPoint.Y - 10, 0), new Point3d(maxPoint.X + 10, maxPoint.Y + 10, 0));
            //裁剪精度
            Polyline offsetBox = cutBox.GetOffsetCurves(0.2)[0] as Polyline;

            if (offsetBox.Area < cutBox.Area)
            {
                offsetBox = cutBox.GetOffsetCurves(-0.2)[0] as Polyline;
            }
            //裁剪
            for (int i = 0; i < offsetBox.NumberOfVertices; i++)
            {
                Point3d p1 = offsetBox.GetPoint3dAt(i);
                Point3d p2 = new Point3d();
                if (i == offsetBox.NumberOfVertices - 1)
                {
                    p2 = offsetBox.GetPoint3dAt(0);
                }
                else
                {
                    p2 = offsetBox.GetPoint3dAt(i + 1);
                }

                //调用Line命令,由用户结束
                //CADTools.RunCommand(true, "_.line");
                //调用Line命令并结束
                // CADTools.RunCommand(false, "_.line", Point3d.Origin, new Point3d(10, 10, 0));


                //CADTools.RunCommand(false,new ResultTree
                // CADTools.RunCommand(false, params new object[]{});
                //CADTools.RunCommand(true, ".trim"
                //    , cutBox.ObjectId, "", "F", p1, p2, "", "");
            }
            offsetBox.Dispose();
            cadApplication.SetSystemVariable("MODEMACRO", "修剪完成");
        }