bool get_layout_extents(Database db, Teigha.GraphicsSystem.View pView, ref BoundBlock3d bbox) { BlockTable bt = (BlockTable)db.BlockTableId.GetObject(OpenMode.ForRead); BlockTableRecord pSpace = (BlockTableRecord)bt[BlockTableRecord.PaperSpace].GetObject(OpenMode.ForRead); Layout pLayout = (Layout)pSpace.LayoutId.GetObject(OpenMode.ForRead); Extents3d ext = new Extents3d(); if (pLayout.GetViewports().Count > 0) { bool bOverall = true; foreach (ObjectId id in pLayout.GetViewports()) { if (bOverall) { bOverall = false; continue; } Teigha.DatabaseServices.Viewport pVp = (Teigha.DatabaseServices.Viewport)id.GetObject(OpenMode.ForRead); } ext.TransformBy(pView.ViewingMatrix); bbox.Set(ext.MinPoint, ext.MaxPoint); } else { ext = pLayout.Extents; } bbox.Set(ext.MinPoint, ext.MaxPoint); return(ext.MinPoint != ext.MaxPoint); }
private void mainCreationLoop(List <_Area_v2> areas) { foreach (_Area_v2 area in areas) { string name = getAreaName(area); double scale = getAreaScale(area); _Ge.Point3d centerPoint = getAreaCenter(area); _Db.Layout lay = createLayoutandSetActive(name); //setLayoutPlotSettings(lay, "ISO_full_bleed_A3_(297.00_x_420.00_MM)", "monochrome.ctb", "DWG To PDF.pc3"); setLayoutPlotSettings(lay, "PDFCreator", "A3", "monochrome.ctb"); _Db.Viewport vp = layoutViewportGetter(lay); _Db.Extents2d ext = getMaximumExtents(lay); setViewportGeometry(vp, ext, 1.05); setViewportParameters(vp, scale, centerPoint); Dictionary <_Db.Layout, string> layouts = new Dictionary <_Db.Layout, string>(); layouts[lay] = name; plotDriver(layouts); removeLayout(lay); } _c.ed.Regen(); }
private _Db.Viewport layoutViewportGetter(_Db.Layout lay) { _Db.ObjectIdCollection viewIds = lay.GetViewports(); _Db.Viewport vp = null; foreach (_Db.ObjectId id in viewIds) { _Db.Viewport vp2 = _c.trans.GetObject(id, _Db.OpenMode.ForWrite) as _Db.Viewport; if (vp2 != null && vp2.Number == 2) { vp = vp2; break; } } if (vp == null) { _Db.BlockTableRecord btr = _c.trans.GetObject(lay.BlockTableRecordId, _Db.OpenMode.ForWrite) as _Db.BlockTableRecord; vp = new _Db.Viewport(); btr.AppendEntity(vp); _c.trans.AddNewlyCreatedDBObject(vp, true); vp.On = true; vp.GridOn = false; } return(vp); }
private void setViewportGeometry(_Db.Viewport vp, _Db.Extents2d ext, double fac = 1.0) { vp.Width = (ext.MaxPoint.X - ext.MinPoint.X) * fac; vp.Height = (ext.MaxPoint.Y - ext.MinPoint.Y) * fac; _Ge.Point2d gg = _Ge.Point2d.Origin + (ext.MaxPoint - ext.MinPoint) * 0.5; vp.CenterPoint = flatten(gg); }
/// <summary> /// Sets the size of the viewport according to the provided extents. /// </summary> /// <param name="ext">The extents of the viewport on the page.</param> /// <param name="fac">Optional factor to provide padding.</param> public static void ResizeViewport( this _AcDb.Viewport vp, _AcDb.Extents2d ext, double fac = 1.0 ) { vp.Width = (ext.MaxPoint.X - ext.MinPoint.X) * fac; vp.Height = (ext.MaxPoint.Y - ext.MinPoint.Y) * fac; vp.CenterPoint = (_AcGe.Point2d.Origin + (ext.MaxPoint - ext.MinPoint) * 0.5).Pad(); }
/// <summary> /// Sets the view in a viewport to contain the specified model extents. /// </summary> /// <param name="ext">The extents of the content to fit the viewport.</param> /// <param name="fac">Optional factor to provide padding.</param> public static void FitContentToViewport( this _AcDb.Viewport vp, _AcDb.Extents3d ext, double fac = 1.0 ) { // Let's zoom to just larger than the extents vp.ViewCenter = (ext.MinPoint + ((ext.MaxPoint - ext.MinPoint) * 0.5)).Strip(); // Get the dimensions of our view from the database extents var hgt = ext.MaxPoint.Y - ext.MinPoint.Y; var wid = ext.MaxPoint.X - ext.MinPoint.X; // We'll compare with the aspect ratio of the viewport itself // (which is derived from the page size) var aspect = vp.Width / vp.Height; // If our content is wider than the aspect ratio, make sure we // set the proposed height to be larger to accommodate the // content if (wid / hgt > aspect) { hgt = wid / aspect; } // Set the height so we're exactly at the extents vp.ViewHeight = hgt; // Set a custom scale to zoom out slightly (could also // vp.ViewHeight *= 1.1, for instance) vp.CustomScale *= fac; }
/// <summary> /// Applies an action to the specified viewport from this layout. /// Creates a new viewport if none is found withthat number. /// </summary> /// <param name="tr">The transaction to use to open the viewports.</param> /// <param name="vpNum">The number of the target viewport.</param> /// <param name="f">The action to apply to each of the viewports.</param> public static void ApplyToViewport( this _AcDb.Layout lay, _AcDb.Transaction tr, int vpNum, Action <_AcDb.Viewport> f ) { var vpIds = lay.GetViewports(); _AcDb.Viewport vp = null; foreach (_AcDb.ObjectId vpId in vpIds) { var vp2 = tr.GetObject(vpId, _AcDb.OpenMode.ForWrite) as _AcDb.Viewport; if (vp2 != null && vp2.Number == vpNum) { // We have found our viewport, so call the action vp = vp2; break; } } if (vp == null) { // We have not found our viewport, so create one var btr = (_AcDb.BlockTableRecord)tr.GetObject( lay.BlockTableRecordId, _AcDb.OpenMode.ForWrite ); vp = new _AcDb.Viewport(); // Add it to the database btr.AppendEntity(vp); tr.AddNewlyCreatedDBObject(vp, true); // Turn it - and its grid - on vp.On = true; vp.GridOn = true; } // Finally we call our function on it f(vp); }
private void setViewportParameters(_Db.Viewport vp, double scale, _Ge.Point3d center) { vp.ViewCenter = flatten(center); vp.CustomScale = 1 / scale; }