.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Plotting to PNG error.

0 REPLIES 0
Reply
Message 1 of 1
jprisbe
503 Views, 0 Replies

Plotting to PNG error.

I've written a .NET dll (C#) that loads a dwg file, runs commands to set _VPOINT, VSSHADOWS, VSMATERIALMODE, DEFAULTLIGHTING, _MaterialMap, _pointlight, _distantlight and then zoom extents.

 

I then plot the file to a 240x240 png file.

 

If I setthe

PlotSettings.ShadePlot to PlotSettingsShadePlotType.Rendered, I get a unhandled exception when calling

PlotEngine.BeginGenerateGraphics;

 

Do I need to set some other PlotSettings value in order to set ShadePlot to Rendered?

It works if I don't use rendered.

 

Code below...

 

public

void PlotPNG240x240(string outputFolder, LogfilelogFile)

{

string fileName = "";

Autodesk.AutoCAD.EditorInput.

Editor ed = null;

 

try

{

AcadApplication app = AcadApp.AcadApplication asAcadApplication;

app.ZoomExtents();

 

Document openDoc = AcadApp.DocumentManager.MdiActiveDocument;

fileName = openDoc.Name;

Autodesk.AutoCAD.ApplicationServices.Documentdwg;

dwg = AcadApp.DocumentManager.MdiActiveDocument;

ed = dwg.Editor;

ed.WriteMessage(string.Format("\nProcessing {0}\n", fileName));

Autodesk.AutoCAD.DatabaseServices.Databasedb;

db = dwg.Database;

Autodesk.AutoCAD.DatabaseServices.TransactionManagertransManager;

Autodesk.AutoCAD.DatabaseServices.Transactiontrans;

transManager = dwg.TransactionManager;

trans = transManager.StartTransaction();

// We'll be plotting the ModelSpace layout

BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead);

 

BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForRead);

 

Layout lo = (Layout)trans.GetObject(btr.LayoutId, OpenMode.ForRead);

 

// We need a PlotInfo object linked to the layout

PlotInfo pi = newPlotInfo();

pi.Layout = btr.LayoutId;

// We need a PlotSettings object based on the layout settings which we then customize

PlotSettings ps = newPlotSettings(lo.ModelType);

ps.CopyFrom(lo);

ps.PlotHidden = true;

 

ps.ShadePlot = PlotSettingsShadePlotType.Rendered;

ps.ShadePlotResLevel = ShadePlotResLevel.Normal;

 

// The PlotSettingsValidator helps create a valid PlotSettings object

PlotSettingsValidator psv = PlotSettingsValidator.Current;

psv.SetPlotType(ps, Autodesk.AutoCAD.DatabaseServices.PlotType.Extents);

psv.SetStdScaleType(ps, StdScaleType.ScaleToFit);

psv.SetUseStandardScale(ps, true);

psv.SetPlotCentered(ps, true);

psv.SetPlotRotation(ps, PlotRotation.Degrees000);

psv.SetPlotConfigurationName(ps, "PublishToFSL240x240 PNG.pc3", null);

psv.RefreshLists(ps);

// must call this before setting current style sheetStringCollectionmedialist = psv.GetCanonicalMediaNameList(ps);

psv.SetCanonicalMediaName(ps, medialist[0]);

// choose the default media

psv.SetCurrentStyleSheet(ps, "Grayscale.ctb");

 

// We need to link the PlotInfo to the PlotSettings and then validate it

pi.OverrideSettings = ps;

PlotInfoValidator piv = newPlotInfoValidator();

piv.MediaMatchingPolicy = MatchingPolicy.MatchEnabled;

piv.Validate(pi);

if (PlotFactory.ProcessPlotState == ProcessPlotState.NotPlotting)

{

PlotEngine pe = PlotFactory.CreatePublishEngine();

 

using(pe)

{

pe.BeginPlot(null, null);

 

// We'll be plotting a single document

pe.BeginDocument(pi, openDoc.Name, null, 1, true, outputFolder + "\\" + Path.GetFileNameWithoutExtension(fileName) + ".png");

 

PlotPageInfo ppi = newPlotPageInfo();

pe.BeginPage(ppi, pi, true, null);

pe.BeginGenerateGraphics(null);

pe.EndGenerateGraphics(null);

 

// Finish the sheet

pe.EndPage(null);

 

// Finish the document

pe.EndDocument(null);

 

// And finish the plot

pe.EndPlot(null);

ppi.Dispose();

}

pe.Destroy();

pe.Dispose();

}

piv.Dispose();

psv.Dispose();

ps.Dispose();

pi.Dispose();

trans.Commit();

trans.Dispose();

transManager.Dispose();

}

catch (Autodesk.AutoCAD.Runtime.ExceptionexAcad)

{

logFile.WriteLine(string.Format("PlotPNG - Error plotting: {0}", Path.GetFileNameWithoutExtension(fileName)));

logFile.WriteLine(string.Format("{0}", exAcad.Message));

 

MessageBox.Show(exAcad.Message, "STCPlotToPNG", MessageBoxButtons.OK, MessageBoxIcon.Error);

}

catch (System.ExceptionexSystem)

{

logFile.WriteLine(string.Format("PlotPNG - Error plotting: {0}", Path.GetFileNameWithoutExtension(fileName)));

logFile.WriteLine(string.Format("{0}", exSystem.Message));

 

MessageBox.Show(exSystem.Message, "STCPlotToPNG", MessageBoxButtons.OK, MessageBoxIcon.Error);

}

finally

{

}

}

0 REPLIES 0

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost