Hi,
I've a problem with plotting a dwg in modelspace which has blockattributes with justification "Center"
By plotting these the justification appearce to be "Left".
Why is that? Am I missing something?
When I plot this dwg with the normal plot command inside Autocad it plots good.
Geert
Code:
public static void PlotCurrentLayout(string devicename, string plotformat, string plotstyle, double plotscale, bool scaletofit, bool plottofile, string plotfilename, string kindoffile)
{
Application.SetSystemVariable("BACKGROUNDPLOT", 0);
using (Transaction transaction = Active.Document.TransactionManager.StartTransaction())
{
try
{
LayoutManager layoutManager = LayoutManager.Current;
ObjectId layoutObjextID = layoutManager.GetLayoutId(layoutManager.CurrentLayout);
Layout layout = (Layout)transaction.GetObject(layoutObjextID, OpenMode.ForRead);
//get plotinfo from layout
PlotInfo plotInfo = new PlotInfo();
plotInfo.Layout = layoutObjextID;
//get a copy of the plotsettings from layout
PlotSettings plotSettings = new PlotSettings(layout.ModelType);
plotSettings.CopyFrom(layout);
//Update the PlotSettings object
PlotSettingsValidator plotSettingsValidator = PlotSettingsValidator.Current; //plotSettingsValidator.SetDefaultPlotConfig(plotSettings);
plotSettingsValidator.SetPlotConfigurationName(plotSettings, devicename, null);
plotSettingsValidator.RefreshLists(plotSettings);
//define area to plot
plotSettingsValidator.SetPlotType(plotSettings, Autodesk.AutoCAD.DatabaseServices.PlotType.Extents);
string canonicalMediaName = GetCanonicalMediaNameFromPlotFormat(plotformat, plotSettingsValidator, plotSettings);
plotSettingsValidator.SetCanonicalMediaName(plotSettings, canonicalMediaName);
if (scaletofit == true)
{
plotSettingsValidator.SetUseStandardScale(plotSettings, true);
plotSettingsValidator.SetStdScaleType(plotSettings, StdScaleType.ScaleToFit);
}
else
{
plotSettingsValidator.SetUseStandardScale(plotSettings, false);
CustomScale customScale = new CustomScale(1, plotscale);
plotSettingsValidator.SetCustomPrintScale(plotSettings, customScale);
}
plotSettingsValidator.SetPlotPaperUnits(plotSettings, PlotPaperUnit.Millimeters);
plotSettingsValidator.SetPlotCentered(plotSettings, false);
if (plotformat == "A4") { plotSettingsValidator.SetPlotRotation(plotSettings, PlotRotation.Degrees000); } else { plotSettingsValidator.SetPlotRotation(plotSettings, PlotRotation.Degrees090); }
//plotSettingsValidator.SetPlotOrigin(plotSettings, point2D);
plotSettingsValidator.SetCurrentStyleSheet(plotSettings, plotstyle);
//Set the plot info as an override since it will not be saved back to the layout
plotInfo.OverrideSettings = plotSettings;
// Validate the plot info
PlotInfoValidator plotInfoValidator = new PlotInfoValidator();
plotInfoValidator.MediaMatchingPolicy = MatchingPolicy.MatchEnabled;
plotInfoValidator.Validate(plotInfo);
// Check to see if a plot is already in progress
if (PlotFactory.ProcessPlotState == ProcessPlotState.NotPlotting)
{
//Preview Plot
using (PlotEngine previewEngine = PlotFactory.CreatePreviewEngine((int) PreviewEngineFlags.Plot)) {
using (PlotProgressDialog previewProgressDialog = new PlotProgressDialog(true, 1, true)) {
// Start to plot the layout
previewEngine.BeginPlot(previewProgressDialog, null);
// Define the plot output
previewEngine.BeginDocument(plotInfo, Active.Document.Name, null, 1, plottofile, plotfilename);
// Display information about the current plot
previewProgressDialog.set_PlotMsgString(PlotMessageIndex.Status, "Plotting: " + Active.Document.Name + " - " + layout.LayoutName);
// Set the sheet progress range
previewProgressDialog.OnBeginSheet();
previewProgressDialog.LowerSheetProgressRange = 0;
previewProgressDialog.UpperSheetProgressRange = 100;
previewProgressDialog.SheetProgressPos = 0;
// Plot the first sheet/layout
PlotPageInfo plotPageInfo = new PlotPageInfo();
previewEngine.BeginPage(plotPageInfo, plotInfo, true, null);
previewEngine.BeginGenerateGraphics(null);
previewEngine.EndGenerateGraphics(null);
// Finish plotting the sheet/layout
previewEngine.EndPage(null);
previewProgressDialog.SheetProgressPos = 100;
previewProgressDialog.OnEndSheet();
// Finish plotting the document
previewEngine.EndDocument(null);
// Finish the plot
previewProgressDialog.PlotProgressPos = 100;
previewProgressDialog.OnEndPlot();
previewEngine.EndPlot(null)
; }
}
}
}
catch (Exception ex) { System.Diagnostics.Debug.Write(ex); }
}
}
private static string GetCanonicalMediaNameFromPlotFormat(string plotformat, PlotSettingsValidator plotsettingsvalidator, PlotSettings plotsettings)
{
GreefaAutocadPlotMediaNames plotMediaName = (GreefaAutocadPlotMediaNames)Enum.Parse(typeof(GreefaAutocadPlotMediaNames), plotformat);
int MediaEnum = (int)plotMediaName;
//int MediaEnum = GetMediaEnumAsInteger(plotformat);
string localeMediaName = plotsettingsvalidator.GetLocaleMediaName(plotsettings, MediaEnum);
StringCollection canonicalMediaNames = plotsettingsvalidator.GetCanonicalMediaNameList(plotsettings);
int i = 0;
foreach (string mediaName in canonicalMediaNames)
{
if (plotsettingsvalidator.GetLocaleMediaName(plotsettings, i) == localeMediaName) { return mediaName; } i++;
}
return "";
}