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 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(); }
//[_AcTrx.CommandMethod("CL")] public void CreateLayout() { var doc = _AcAp.Application.DocumentManager.MdiActiveDocument; if (doc == null) { return; } var db = doc.Database; var ed = doc.Editor; var ext = new _AcDb.Extents2d(); using (var tr = db.TransactionManager.StartTransaction()) { // Create and select a new layout tab //var id = _AcDb.LayoutManager.Current.CreateAndMakeLayoutCurrent("NewLayout"); var id = _AcDb.LayoutManager.Current.GetLayoutId("Model"); // Open the created layout var lay = (_AcDb.Layout)tr.GetObject(id, _AcDb.OpenMode.ForWrite); // Make some settings on the layout and get its extents //lay.SetPlotSettings( // //"ISO_full_bleed_2A0_(1189.00_x_1682.00_MM)", // Try this big boy! // "ANSI_B_(11.00_x_17.00_Inches)", // "monochrome.ctb", // "DWF6 ePlot.pc3", // null //); ext = lay.GetMaximumExtents(); lay.ApplyToViewport( tr, 2, vp => { // Size the viewport according to the extents calculated when // we set the PlotSettings (device, page size, etc.) // Use the standard 10% margin around the viewport // (found by measuring pixels on screenshots of Layout1, etc.) vp.ResizeViewport(ext, 0.8); // Adjust the view so that the model contents fit if (ValidDbExtents(db.Extmin, db.Extmax)) { vp.FitContentToViewport(new _AcDb.Extents3d(db.Extmin, db.Extmax), 0.9); } // Finally we lock the view to prevent meddling vp.Locked = true; } ); // Commit the transaction tr.Commit(); } // Zoom so that we can see our new layout, again with a little padding //ed.Command("_.ZOOM", "_E"); //ed.Command("_.ZOOM", ".7X"); ed.Regen(); }
public static void SetPlotSettings(this _AcDb.Layout lay, string device, string mediaName, string styleSheet, double?scaleNumerator, double?scaleDenominator, short?rotation) { using (var ps = new _AcDb.PlotSettings(lay.ModelType)) { ps.CopyFrom(lay); var psv = _AcDb.PlotSettingsValidator.Current; // Set the device if (!string.IsNullOrEmpty(device)) { var devs = psv.GetPlotDeviceList(); if (devs.ContainsIgnoreUc(ref device)) { log.InfoFormat(CultureInfo.CurrentCulture, "Setze Device '{0}' für Layout '{1}'.", device, lay.LayoutName); psv.SetPlotConfigurationName(ps, device, null); psv.RefreshLists(ps); } else { log.WarnFormat(CultureInfo.CurrentCulture, "Device '{0}' existiert nicht!", device); } } // Set the media name/size if (!string.IsNullOrEmpty(mediaName)) { var mns = psv.GetCanonicalMediaNameList(ps); if (mns.ContainsIgnoreUc(ref mediaName)) { log.InfoFormat(CultureInfo.CurrentCulture, "Setze PageSize '{0}' für Layout '{1}'.", mediaName, lay.LayoutName); psv.SetCanonicalMediaName(ps, mediaName); } else { string canonicalMediaName = LocaleToCanonicalMediaName(psv, ps, mediaName); if (!string.IsNullOrEmpty(canonicalMediaName)) { log.InfoFormat(CultureInfo.CurrentCulture, "Setze PageSize '{0}' für Layout '{1}'.", canonicalMediaName, lay.LayoutName); psv.SetCanonicalMediaName(ps, canonicalMediaName); } else { log.WarnFormat(CultureInfo.CurrentCulture, "Size '{0}' existiert nicht!", mediaName); } } } // Set the pen settings if (!string.IsNullOrEmpty(styleSheet)) { var ssl = psv.GetPlotStyleSheetList(); if (ssl.ContainsIgnoreUc(ref styleSheet)) { log.InfoFormat(CultureInfo.CurrentCulture, "Setze StyleSheet '{0}' für Layout '{1}'.", styleSheet, lay.LayoutName); psv.SetCurrentStyleSheet(ps, styleSheet); } else { log.WarnFormat(CultureInfo.CurrentCulture, "Stylesheet '{0}' existiert nicht!", mediaName); } } // Copy the PlotSettings data back to the Layout if (scaleNumerator.HasValue && scaleDenominator.HasValue) { log.InfoFormat(CultureInfo.CurrentCulture, "Setze Scale '{0}:{2}' für Layout '{1}'.", scaleNumerator.Value.ToString(), lay.LayoutName, scaleDenominator.Value.ToString()); _AcDb.CustomScale cs = new _AcDb.CustomScale(scaleNumerator.Value, scaleDenominator.Value); if (ps.PlotPaperUnits != _AcDb.PlotPaperUnit.Millimeters) { psv.SetPlotPaperUnits(ps, _AcDb.PlotPaperUnit.Millimeters); } psv.SetCustomPrintScale(ps, cs); } if (rotation.HasValue && (rotation.Value == 0 || rotation.Value == 90 || rotation.Value == 180 || rotation.Value == 270)) { _AcDb.PlotRotation pRot = _AcDb.PlotRotation.Degrees000; switch (rotation.Value) { case 90: pRot = _AcDb.PlotRotation.Degrees090; break; case 180: pRot = _AcDb.PlotRotation.Degrees180; break; case 270: pRot = _AcDb.PlotRotation.Degrees270; break; case 0: default: break; } log.InfoFormat(CultureInfo.CurrentCulture, "Setze Rotation '{0}' für Layout '{1}'.", pRot.ToString(), lay.LayoutName); psv.SetPlotRotation(ps, pRot); } // plottype hardcoded auf fenster try { if (ps.PlotType != _AcDb.PlotType.Window) { if (ps.PlotWindowArea.ToString() == "((0,0),(0,0))") { _AcDb.Extents2d e2d = new _AcDb.Extents2d(0.0, 0.0, 10.0, 10.0); psv.SetPlotWindowArea(ps, e2d); } psv.SetPlotType(ps, _AcDb.PlotType.Window); } } catch (Exception ex) { log.ErrorFormat(CultureInfo.CurrentCulture, "Fehler beim Setzen von PlotType auf FENSTER! {0}", ex.Message); } var upgraded = false; if (!lay.IsWriteEnabled) { lay.UpgradeOpen(); upgraded = true; } lay.CopyFrom(ps); if (upgraded) { lay.DowngradeOpen(); } } }