- 积分
- 24557
- 明经币
- 个
- 注册时间
- 2004-3-17
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
发表于 2009-10-29 17:25:00
|
显示全部楼层
简单的办法就是调用Zoom命令
或者试下下面的ZoomWindow- public enum UcsCode
- {
- Wcs = 0,
- Ucs,
- MDcs,
- PDcs
- }
- [DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl)]
- private static extern int acedTrans(
- double[] point,
- IntPtr fromResbuf,
- IntPtr toResbuf,
- int displacement,
- double[] result
- );
- public static double[] Trans(double[] point, UcsCode from, UcsCode to)
- {
- ResultBuffer rbfrom = new ResultBuffer(new TypedValue((int)LispDataType.Int16, from));
- ResultBuffer rbto = new ResultBuffer(new TypedValue((int)LispDataType.Int16, to));
- double[] res = new double[2];
- acedTrans(point, rbfrom.UnmanagedObject, rbto.UnmanagedObject, 0, res);
- return res;
- }
- public static Point2d Wcs2Dcs(Point3d point, bool atPaperSpace)
- {
- double[] res =
- Trans(
- point.ToArray(),
- UcsCode.Wcs, atPaperSpace ? UcsCode.PDcs : UcsCode.MDcs);
- return new Point2d(res);
- }
- public void ZoomWindow(Point3d minPoint, Point3d maxPoint)
- {
- Document doc = Application.DocumentManager.MdiActiveDocument;
- Editor ed = doc.Editor;
- ViewTableRecord cvtr = ed.GetCurrentView();
- ViewTableRecord vtr = new ViewTableRecord();
- vtr.CopyFrom(cvtr);
- Point3d[] oldpnts = new Point3d[] { minPoint, maxPoint };
- Point3d[] pnts = new Point3d[8];
- Point2d[] pnt2ds = new Point2d[8];
- for (int i = 0; i < 2; i++)
- {
- for (int j = 0; j < 2; j++)
- {
- for (int k = 0; k < 2; k++)
- {
- int n = i * 4 + j * 2 + k;
- pnts[n] = new Point3d(oldpnts[i][0], oldpnts[j][1], oldpnts[k][2]);
- pnt2ds[n] = Wcs2Dcs(pnts[n], false);
- }
- }
- }
- double xmin, xmax, ymin, ymax;
- xmin = xmax = pnt2ds[0][0];
- ymin = ymax = pnt2ds[0][1];
- for (int i = 1; i < 8; i++)
- {
- xmin = Math.Min(xmin, pnt2ds[i][0]);
- xmax = Math.Max(xmax, pnt2ds[i][0]);
- ymin = Math.Min(ymin, pnt2ds[i][1]);
- ymax = Math.Max(ymax, pnt2ds[i][1]);
- }
- vtr.Width = xmax - xmin;
- vtr.Height = ymax - ymin;
- vtr.CenterPoint = pnt2ds[0] + (pnt2ds[7] - pnt2ds[0]) / 2;
- ed.SetCurrentView(vtr);
- ed.Regen();
- }
|
|