日期:2014-05-17 浏览次数:20848 次
public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements ) { UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Document doc = uidoc.Document; View view = doc.ActiveView; UIView uiview = null; IList<UIView> uiviews = uidoc.GetOpenUIViews(); foreach( UIView uv in uiviews ) { if( uv.ViewId.Equals( view.Id ) ) { uiview = uv; break; } } Rectangle rect = uiview.GetWindowRectangle(); IList<XYZ> corners = uiview.GetZoomCorners(); XYZ p = corners[0]; XYZ q = corners[1]; string msg = string.Format( "UIView Windows rectangle: {0}; zoom corners: {1}-{2}; click Close to zoom in by 10%.", RectangleString( rect ), PointString( p ), PointString( q ) ); TaskDialog.Show( "WinCoords", msg ); // Calculate new zoom corners to // zoom in by 10%, i.e. the two corners // end up at 0.45 of their previous // distance to the centre point. XYZ v = q - p; XYZ center = p + 0.5 * v; v *= 0.45; p = center - v; q = center + v; uiview.ZoomAndCenterRectangle( p, q ); return Result.Succeeded; }
/// <summary> /// 返回一个表示矩形区域的字符串,格式是(左上角)-(右下角) /// 窗口坐标系的 Y 方向是相反方向 /// </summary> static string RectangleString( Rectangle r ) { return string.Format( "({0},{1})-({2},{3})", r.Left, r.Top, r.Right, r.Bottom ); }