引自http://www.objectarx.net/bbs/viewthread.php?tid=1785&extra=page%3D1&page=2
public void TrimMap(Polyline cutBox)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
//关闭对象捕捉功能避免误删除
Application.SetSystemVariable("SNAPMODE", 0);
Application.SetSystemVariable("MODEMACRO", "正在修剪
");
//获取最小与最大点
Point3d minPoint = cutBox.GeometricExtents.MinPoint;
Point3d maxPoint = cutBox.GeometricExtents.MaxPoint;
//设置缩放视口
Tools.RunCommand("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)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
offsetBox = cutBox.GetOffsetCurves(-0.2)[0] as Polyline;
}
//裁剪
for (int i = 0; i < offsetBox.NumberOfVertices; i++)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
Point3d p1 = offsetBox.GetPoint3dAt(i);
Point3d p2 = new Point3d();
if (i == offsetBox.NumberOfVertices - 1)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
p2 = offsetBox.GetPoint3dAt(0);
}
else
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
p2 = offsetBox.GetPoint3dAt(i + 1);
}
Tools.RunCommand("TRIM", cutBox.ObjectId, "", "F", p1, p2, "", "");
}
offsetBox.Dispose();
Application.SetSystemVariable("MODEMACRO", "修剪完成
");
}