Stream(ArrayList data, MediaBounds mediaBounds) { data.Add(new Snoop.Data.ClassSeparator(typeof(MediaBounds))); data.Add(new Snoop.Data.Point2d("Lower left printable area", mediaBounds.LowerLeftPrintableArea)); data.Add(new Snoop.Data.Point2d("Page size", mediaBounds.PageSize)); data.Add(new Snoop.Data.Point2d("Upper right printable area", mediaBounds.UpperRightPrintableArea)); }
public void Test() { PlotSettingsValidator psv = PlotSettingsValidator.Current; var Text = new List <string>(); var editor = Acad.DocumentManager.MdiActiveDocument.Editor; System.Collections.Specialized.StringCollection vs = psv.GetPlotDeviceList(); foreach (var st in vs) { editor.WriteMessage(st.ToString() + Environment.NewLine); Text.Add(st.ToString()); } using (PlotSettings ps = new PlotSettings(false)) { foreach (var st in vs) { editor.WriteMessage("Текущий/Selected: " + st.ToString() + Environment.NewLine); Text.Add("Текущий/Selected: " + st.ToString()); if (st.ToString() == "AutoCAD PDF (High Quality Print).pc3") { PlotConfig config = PlotConfigManager.SetCurrentConfig(st.ToString()); PlotInfo info = new PlotInfo(); psv.SetPlotConfigurationName(ps, st.ToString(), null); psv.RefreshLists(ps); System.Collections.Specialized.StringCollection mediaName = psv.GetCanonicalMediaNameList(ps); foreach (var media in mediaName) { editor.WriteMessage("Формат/Media name " + media.ToString() + Environment.NewLine); Text.Add("Формат/Media name " + media.ToString()); MediaBounds bounds = config.GetMediaBounds(media.ToString()); editor.WriteMessage(Math.Round(bounds.PageSize.X).ToString() + Environment.NewLine); editor.WriteMessage(Math.Round(bounds.PageSize.Y).ToString() + Environment.NewLine); editor.WriteMessage(Math.Round(bounds.LowerLeftPrintableArea.X).ToString() + Environment.NewLine); editor.WriteMessage(Math.Round(bounds.UpperRightPrintableArea.Y).ToString() + Environment.NewLine); editor.WriteMessage(Math.Round(bounds.UpperRightPrintableArea.X).ToString() + Environment.NewLine); editor.WriteMessage(Math.Round(bounds.LowerLeftPrintableArea.Y).ToString() + Environment.NewLine); Text.Add(Math.Round(bounds.PageSize.X).ToString()); Text.Add(Math.Round(bounds.PageSize.Y).ToString()); Text.Add(Math.Round(bounds.LowerLeftPrintableArea.X).ToString()); Text.Add(Math.Round(bounds.UpperRightPrintableArea.Y).ToString()); Text.Add(Math.Round(bounds.UpperRightPrintableArea.X).ToString()); Text.Add(Math.Round(bounds.LowerLeftPrintableArea.Y).ToString()); } } } } System.IO.File.WriteAllLines("C:\\users\\dyn1\\desktop\\info.txt", Text); }
// overload no scale factor or set the view - just make the layout public void LayoutAndViewport(Database db, string layoutName, out ObjectId rvpid, string deviceName, string mediaName, out ObjectId id) { // set default values rvpid = new ObjectId(); bool flagVp = false; // flag to create a new floating view port double viewSize = (double)Application.GetSystemVariable("VIEWSIZE"); double height = viewSize; double width = viewSize; Point2d loCenter = new Point2d(); // layout center point Point2d vpLowerCorner = new Point2d(); Point2d vpUpperCorner = new Point2d(); Document doc = Application.DocumentManager.MdiActiveDocument; LayoutManager lm = LayoutManager.Current; id = lm.CreateLayout(layoutName); using (Transaction tr = db.TransactionManager.StartTransaction()) { Layout lo = tr.GetObject(id, OpenMode.ForWrite, false) as Layout; if (lo != null) { lm.CurrentLayout = lo.LayoutName; // make it current! #region do some plotting settings here for the paper size... ObjectId loid = lm.GetLayoutId(lo.LayoutName); PlotInfo pi = new PlotInfo(); pi.Layout = loid; PlotSettings ps = new PlotSettings(false); PlotSettingsValidator psv = PlotSettingsValidator.Current; psv.RefreshLists(ps); psv.SetPlotConfigurationName(ps, deviceName, mediaName); psv.SetPlotType(ps, Autodesk.AutoCAD.DatabaseServices.PlotType.Layout); psv.SetPlotPaperUnits(ps, PlotPaperUnit.Inches); psv.SetUseStandardScale(ps, true); psv.SetStdScaleType(ps, StdScaleType.ScaleToFit); // use this as default pi.OverrideSettings = ps; PlotInfoValidator piv = new PlotInfoValidator(); piv.Validate(pi); lo.CopyFrom(ps); PlotConfig pc = PlotConfigManager.CurrentConfig; // returns data in millimeters... MediaBounds mb = pc.GetMediaBounds(mediaName); Point2d p1 = mb.LowerLeftPrintableArea; Point2d p3 = mb.UpperRightPrintableArea; Point2d p2 = new Point2d(p3.X, p1.Y); Point2d p4 = new Point2d(p1.X, p3.Y); // convert millimeters to inches double mm2inch = 25.4; height = p1.GetDistanceTo(p4) / mm2inch; width = p1.GetDistanceTo(p2) / mm2inch; vpLowerCorner = lo.PlotOrigin; vpUpperCorner = new Point2d(vpLowerCorner.X + width, vpLowerCorner.Y + height); LineSegment2d seg = new LineSegment2d(vpLowerCorner, vpUpperCorner); loCenter = seg.MidPoint; #endregion if (lo.GetViewports().Count == 1) // Viewport was not created by default { // the create by default view ports on new layouts it // is off we need to mark a flag to generate a new one // in another transaction - out of this one flagVp = true; } else if (lo.GetViewports().Count == 2) // create Viewports by default it is on { // extract the last item from the collection // of view ports inside of the layout int i = lo.GetViewports().Count - 1; ObjectId vpId = lo.GetViewports()[i]; if (!vpId.IsNull) { Viewport vp = tr.GetObject(vpId, OpenMode.ForWrite, false) as Viewport; if (vp != null) { vp.Height = height; // change height vp.Width = width; // change width vp.CenterPoint = new Point3d(loCenter.X, loCenter.Y, 0.0); // change center //vp.ColorIndex = 1; // debug // zoom to the Viewport extents Zoom(new Point3d(vpLowerCorner.X, vpLowerCorner.Y, 0.0), new Point3d(vpUpperCorner.X, vpUpperCorner.Y, 0.0), new Point3d(), 1.0); rvpid = vp.ObjectId; // return the output ObjectId to out... } } } } tr.Commit(); } // end of transaction // we need another transaction to create a new paper space floating Viewport if (flagVp) { using (Transaction tr = db.TransactionManager.StartTransaction()) { BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead); BlockTableRecord btr_ps = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.PaperSpace], OpenMode.ForWrite); Viewport vp = new Viewport(); vp.Height = height; // set the height vp.Width = width; // set the width vp.CenterPoint = new Point3d(loCenter.X, loCenter.Y, 0.0); // set the center //vp.ColorIndex = 2; // debug btr_ps.AppendEntity(vp); tr.AddNewlyCreatedDBObject(vp, true); vp.On = true; // make it accessible! // zoom to the Viewport extents Zoom(new Point3d(vpLowerCorner.X, vpLowerCorner.Y, 0.0), new Point3d(vpUpperCorner.X, vpUpperCorner.Y, 0.0), new Point3d(), 1.0); rvpid = vp.ObjectId; // return the ObjectId to the out... tr.Commit(); } // end of transaction } }