private static string LocaleToCanonicalMediaName(_AcDb.PlotSettingsValidator psv, _AcDb.PlotSettings ps, string mn) { int cnt = 0; foreach (string mediaName in psv.GetCanonicalMediaNameList(ps)) { string localeMediaName = psv.GetLocaleMediaName(ps, cnt); if (string.Compare(mn, localeMediaName, StringComparison.OrdinalIgnoreCase) == 0) { return(mediaName); } cnt = cnt + 1; } return(null); }
private void setLayoutPlotSettings(_Db.Layout lay, string device, string pageSize, string styleSheet) { using (_Db.PlotSettings plotSettings = new _Db.PlotSettings(lay.ModelType)) { plotSettings.CopyFrom(lay); _Db.PlotSettingsValidator validator = _Db.PlotSettingsValidator.Current; StringCollection devices = validator.GetPlotDeviceList(); if (devices.Contains(device)) { validator.SetPlotConfigurationName(plotSettings, device, null); validator.RefreshLists(plotSettings); } else { write("[WARNING] Device not found!"); } StringCollection paperSizes = validator.GetCanonicalMediaNameList(plotSettings); if (paperSizes.Contains(pageSize)) { validator.SetCanonicalMediaName(plotSettings, pageSize); } else { write("[WARNING] Paper not found!"); } StringCollection styleSheets = validator.GetPlotStyleSheetList(); if (styleSheets.Contains(styleSheet)) { validator.SetCurrentStyleSheet(plotSettings, styleSheet); } else { write("[WARNING] Style not found!"); } lay.CopyFrom(plotSettings); } }
private static void SetClosestMediaName(_AcDb.PlotSettingsValidator psv, string device, _AcDb.PlotSettings ps, double pageWidth, double pageHeight, _AcDb.PlotPaperUnit units, bool matchPrintableArea) { psv.SetPlotType(ps, Autodesk.AutoCAD.DatabaseServices.PlotType.Extents); psv.SetPlotPaperUnits(ps, units); psv.SetUseStandardScale(ps, false); psv.SetStdScaleType(ps, _AcDb.StdScaleType.ScaleToFit); psv.SetPlotConfigurationName(ps, device, null); psv.RefreshLists(ps); StringCollection mediaList = psv.GetCanonicalMediaNameList(ps); double smallestOffset = 0.0; string selectedMedia = string.Empty; _AcDb.PlotRotation selectedRot = _AcDb.PlotRotation.Degrees000; foreach (string media in mediaList) { psv.SetCanonicalMediaName(ps, media); psv.SetPlotPaperUnits(ps, units); double mediaPageWidth = ps.PlotPaperSize.X; double mediaPageHeight = ps.PlotPaperSize.Y; if (matchPrintableArea) { mediaPageWidth -= (ps.PlotPaperMargins.MinPoint.X + ps.PlotPaperMargins.MaxPoint.X); mediaPageHeight -= (ps.PlotPaperMargins.MinPoint.Y + ps.PlotPaperMargins.MaxPoint.Y); } _AcDb.PlotRotation rotationType = _AcDb.PlotRotation.Degrees090; //Check that we are not outside the media print area if (mediaPageWidth < pageWidth || mediaPageHeight < pageHeight) { //Check if 90°Rot will fit, otherwise check next media if (mediaPageHeight < pageWidth || mediaPageWidth >= pageHeight) { //Too small, let's check next media continue; } //That's ok 90°Rot will fit rotationType = _AcDb.PlotRotation.Degrees090; } double offset = Math.Abs(mediaPageWidth * mediaPageHeight - pageWidth * pageHeight); if (selectedMedia == string.Empty || offset < smallestOffset) { selectedMedia = media; smallestOffset = offset; selectedRot = rotationType; //Found perfect match so we can quit early if (smallestOffset == 0) { break; } } } psv.SetCanonicalMediaName(ps, selectedMedia); psv.SetPlotRotation(ps, selectedRot); string localMedia = psv.GetLocaleMediaName(ps, selectedMedia); _Editor.WriteMessage("\n - Closest Media: " + localMedia); _Editor.WriteMessage("\n - Offset: " + smallestOffset.ToString()); _Editor.WriteMessage("\n - Rotation: " + selectedRot.ToString()); }