Message 1 of 1
Plot Preview from Database
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I want plot preview not open dwg file, I meet three questions, I need help ,thank you everyone. this is very important for me,help please.
questions:
1.first plot not right;
2.close preview, Layout note the one before preview;
3.preview again ,it's right.
public class Startup
{
[CommandMethod("PlotPreView")]
public void PlotPreView()
{
Document acDoc = Application.DocumentManager.MdiActiveDocument;
var acEdit = acDoc.Editor;
using (DocumentLock acLckDoc = acDoc.LockDocument())
{
var acDbSave = HostApplicationServices.WorkingDatabase;
using (Database acDb = new Database(false, false))
{
var localFile = "E:\\plotprevie.dwg";
acDb.ReadDwgFile(localFile, FileOpenMode.OpenForReadAndAllShare, false, null);
acDb.CloseInput(true);
using (Transaction acTrans = acDb.TransactionManager.StartTransaction())
{
HostApplicationServices.WorkingDatabase = acDb;
LayoutManager acLayoutMgr = LayoutManager.Current;
// 1D4 64B
string handle = "1D4";
long lng = Convert.ToInt64(handle, 16);
ObjectId objectId = acDb.GetObjectId(false, new Handle(lng), 0);
if (objectId == null) return;
BlockReference acBrf = acTrans.GetObject(objectId, OpenMode.ForRead) as BlockReference;
if (acBrf == null) return;
BlockTableRecord acBlkTblRec = acTrans.GetObject(acBrf.OwnerId, OpenMode.ForRead) as BlockTableRecord;
Layout acLayout = acBlkTblRec.LayoutId.GetObject(OpenMode.ForWrite) as Layout;
acLayoutMgr.CurrentLayout = acLayout.LayoutName;
acLayoutMgr.SetCurrentLayoutId(acLayout.ObjectId);
acEdit.WriteMessage(acLayoutMgr.CurrentLayout + "3\n");
using (PlotInfo acPlInfo = new PlotInfo())
{
acPlInfo.Layout = acLayout.ObjectId;
// Get a copy of the PlotSettings from the layout
using (PlotSettings acPlSet = new PlotSettings(acLayout.ModelType))
{
acPlSet.CopyFrom(acLayout);
// Update the PlotSettings object
PlotSettingsValidator acPlSetVdr = PlotSettingsValidator.Current;
// Set the plot type
acPlSetVdr.SetPlotType(acPlSet, Autodesk.AutoCAD.DatabaseServices.PlotType.Extents);
// Set the plot scale
acPlSetVdr.SetUseStandardScale(acPlSet, true);
acPlSetVdr.SetStdScaleType(acPlSet, StdScaleType.ScaleToFit);
// Center the plot
acPlSetVdr.SetPlotCentered(acPlSet, true);
// Set the plot device to use
acPlSetVdr.SetPlotConfigurationName(acPlSet, "DWF6 ePlot.pc3", "ANSI_A_(8.50_x_11.00_Inches)");
// Set the plot info as an override since it will
// not be saved back to the layout
acPlInfo.OverrideSettings = acPlSet;
// Validate the plot info
using (PlotInfoValidator acPlInfoVdr = new PlotInfoValidator())
{
acPlInfoVdr.MediaMatchingPolicy = MatchingPolicy.MatchEnabled;
acPlInfoVdr.Validate(acPlInfo);
// Check to see if a plot is already in progress
if (PlotFactory.ProcessPlotState == ProcessPlotState.NotPlotting)
{
using (PlotEngine acPlEng = PlotFactory.CreatePreviewEngine((int)PreviewEngineFlags.Plot))
{
// Track the plot progress with a Progress dialog
using (PlotProgressDialog acPlProgDlg = new PlotProgressDialog(true, 1, true))
{
using ((acPlProgDlg))
{
// Define the status messages to display
// when plotting starts
acPlProgDlg.set_PlotMsgString(PlotMessageIndex.DialogTitle, "Plot Progress");
acPlProgDlg.set_PlotMsgString(PlotMessageIndex.CancelJobButtonMessage, "Cancel Job");
acPlProgDlg.set_PlotMsgString(PlotMessageIndex.CancelSheetButtonMessage, "Cancel Sheet");
acPlProgDlg.set_PlotMsgString(PlotMessageIndex.SheetSetProgressCaption, "Sheet Set Progress");
acPlProgDlg.set_PlotMsgString(PlotMessageIndex.SheetProgressCaption, "Sheet Progress");
// Set the plot progress range
acPlProgDlg.LowerPlotProgressRange = 0;
acPlProgDlg.UpperPlotProgressRange = 100;
acPlProgDlg.PlotProgressPos = 0;
// Display the Progress dialog
acPlProgDlg.OnBeginPlot();
acPlProgDlg.IsVisible = true;
// Start to plot the layout
acPlEng.BeginPlot(acPlProgDlg, null);
// Define the plot output
acPlEng.BeginDocument(acPlInfo, acDb.Filename, null, 1, false, null);
// Display information about the current plot
acPlProgDlg.set_PlotMsgString(PlotMessageIndex.Status, "Plotting: " + acDb.Filename + " - " + acLayout.LayoutName);
// Set the sheet progress range
acPlProgDlg.OnBeginSheet();
acPlProgDlg.LowerSheetProgressRange = 0;
acPlProgDlg.UpperSheetProgressRange = 100;
acPlProgDlg.SheetProgressPos = 0;
// Plot the first sheet/layout
using (PlotPageInfo acPlPageInfo = new PlotPageInfo())
{
acPlEng.BeginPage(acPlPageInfo, acPlInfo, true, null);
}
acPlEng.BeginGenerateGraphics(null);
acPlEng.EndGenerateGraphics(null);
// Finish plotting the sheet/layout
acPlEng.EndPage(null);
acPlProgDlg.SheetProgressPos = 100;
acPlProgDlg.OnEndSheet();
// Finish plotting the document
acPlEng.EndDocument(null);
// Finish the plot
acPlProgDlg.PlotProgressPos = 100;
acPlProgDlg.OnEndPlot();
acPlEng.EndPlot(null);
}
}
}
}
}
}
}
HostApplicationServices.WorkingDatabase = acDbSave;
}
}
}
}
}