admin 发表于 2024-5-4 19:19:06

ObjectArx设置图面视图

void SetView(AcGePoint2d Pt1, AcGePoint2d Pt2, double ex_ratio)
{
        AcGePoint2d CenterPt;
        if ((fabs(Pt1.x - Pt2.x) < 1e-6) || (fabs(Pt1.y - Pt2.y) < 1e-6))
        {
                return;
        }
               
        //确保两个坐标点分别为左上角和右下角
        if (Pt1.x>Pt2.x)
        {
                double tmp;
                tmp = Pt1.x;
                Pt1.x = Pt2.x;
                Pt2.x = tmp;
        }
        if (Pt2.y>Pt1.y)
        {
                double tmp;
                tmp = Pt1.y;
                Pt1.y = Pt2.y;
                Pt2.y = tmp;
        }

        //获取当前DwgView的尺寸
        CRect CADrect;
        acedGetAcadDwgView()->GetClientRect(&CADrect);
        double width, height, ratio;
        ratio = (double)(CADrect.right - CADrect.left) / (double)(CADrect.bottom - CADrect.top);
        if (fabs(ratio) < 1e-6)
        {
                return;
        }
        if ((Pt2.x - Pt1.x) / (Pt1.y - Pt2.y) > ratio)
        {
                width = Pt2.x - Pt1.x;
                height = width / ratio;
        }
        else
        {
                height = Pt1.y - Pt2.y;
                width = height * ratio;
        }

        //设置当前视图中心点
        CenterPt.x = (Pt1.x + Pt2.x) / 2;
        CenterPt.y = (Pt1.y + Pt2.y) / 2;

        //改变当前视图
        AcDbViewTableRecord pVwRec;
        pVwRec.setCenterPoint(CenterPt);
        pVwRec.setWidth(width * ex_ratio);
        pVwRec.setHeight(height * ex_ratio);
        acedSetCurrentView(&pVwRec, NULL);
}
页: [1]
查看完整版本: ObjectArx设置图面视图