创建了Sheet,并将设计成果参考进来,如何只显示图框内的内容

创建了Sheet,并将设计成果参考进来,如何只显示图框内的内容,超出图框的内容自动隐藏,就像CAD的布局那样。

Parents Reply Children
  • 您需要的这个功能在MS中叫做参考的剪切。可以先获取图框范围坐标点,然后调用DgnAttachment下的SetClipPoints



    Answer Verified By: lingwei liu 

  • 研究了一段时间,总算搞清楚了,裁剪的坐标是需要根据RefOrigin来设置的。感谢符老师,以下代码亲测通过,供大家参考。

    DgnDocumentMoniker moniker = DgnDocumentMoniker.CreateFromFileName(dgnFile.GetFileName(), null);
                DgnAttachment attachment = sheetDgnModel.CreateDgnAttachment(moniker, DRAWING_NAME);
    
                double x0, y0, x1, y1;
                if (attachment != null)
                {
                    attachment.StoredScale = 1 / SheetScale;
                    DTransform3d transform = DTransform3d.FromTranslation(new DPoint3d(centerPoint.X, centerPoint.Y, 0.0) * uor);//3、再平移回去
                    transform = transform * DTransform3d.Rotation(2, Angle.FromRadians(centerVector.Azimuth > Math.PI ? -Math.PI * 3 / 2 + centerVector.Azimuth : -Math.PI / 2 + centerVector.Azimuth));//2、再旋转
                    transform = transform * DTransform3d.FromTranslation(new DPoint3d(-centerPoint.X, -centerPoint.Y, 0.0) * uor);//1、先平移到图纸中心
    
                    //旋转和平移绘图到图纸指定位置
                    attachment.SetMasterOrigin(new DPoint3d(blockWidth / 2 + sheetMargin, blockHeight / 2 + sheetMargin, 0.0) * uor);
                    attachment.SetRefOrigin(new DPoint3d(centerPoint.X, centerPoint.Y, 0.0) * uor);
                    DMatrix3d rotateMatrix = transform.Matrix;
                    attachment.SetRotMatrix(rotateMatrix);
    
                    //设置裁剪区,此中心是以RefOrigin为原点的范围
                    x0 = -blockWidth / 2;
                    y0 = -blockHeight / 2;
                    x1 = x0 + blockWidth;
                    y1 = y0 + blockHeight;
                    DPoint2d[] clipPoints = new DPoint2d[] {
                        new DPoint2d(x0, y0) * uor,
                        new DPoint2d(x1, y0) * uor,
                        new DPoint2d(x1, y1) * uor,
                        new DPoint2d(x0, y1) * uor};
                    attachment.SetClipPoints(clipPoints);
                    attachment.Rewrite(true, true);
                    attachment.WriteToModel(true);
                }