Get file type from plotter before plot?

Get file type from plotter before plot?

ottosson_mathias
Advocate Advocate
584 Views
4 Replies
Message 1 of 5

Get file type from plotter before plot?

ottosson_mathias
Advocate
Advocate

I have two plotters, PublishToWeb JPG.pc3 and PDFXchange 7.pc3. Is it possible to get the file type of the plot before plotting, preferably from the PlotConfigInfo or something similar if possible?

 

I need to be able to set scale unit to pixels if the plotter is outputting jpg and mm/inches if it's a pdf. I don't know beforehand what plotters are available.

 

Thanks!

0 Likes
585 Views
4 Replies
  • plot
Replies (4)
Message 2 of 5

SENL1362
Advisor
Advisor

You can get a list of PlotDevices with:

 

 

PlotConfigManager.RefreshList(RefreshCode.RefreshDevicesList);
string plotDevNames=null;
using (PlotConfigInfoCollection plotDevices= PlotConfigManager.Devices)
{
  if (plotDevices != null && plotDevices.Count > 0)
  {
   plotDevNames = plotDevices.Cast<PlotConfigInfo>()
   .Select(n => n.DeviceName).ToList();
  }
}

 

 

 

And based on the (pc3)Name of the device you can decide to set the Units, Scale etc.

 

 

var lm = LayoutManager.Current;
var psv = PlotSettingsValidator.Current;
using (var tr = db.TransactionManager.StartTransaction())
{
  var layoutName = lm.CurrentLayout;
  var layoutId = lm.GetLayoutId(layoutName);
  var layout = (Layout)tr.GetObject(layoutId, OpenMode.ForRead);
  using (var ps = new PlotSettings(layout.ModelType))
  {
    ps.CopyFrom(layout);
    //Set or Change the PlotDevice
    //psv.SetPlotConfigurationName(ps, pc3Name, null);
    //psv.RefreshLists(ps);
    //or Get the PlotDevice and set Units accordingly
    var pc3Name=ps.PlotConfigurationName;
    var psUnits=(pc3Name.Contains("PDF",StringComparison.OrdinalIgnoreCase) ? PlotPaperUnit.Millimeters : PlotPaperUnit.Pixels;
    psv.SetPlotPaperUnits(ps, psUnits);
    layout.CopyFrom(ps);
  }
  tr.Commit();
}

 

 

PS: you might need this String Extension for the Case Insensitive Compare

public static class StringExtension
{
  public static bool Contains(this string source, string toCheck, StringComparison compType)
  {
    return source != null && toCheck != null && source.IndexOf(toCheck, compType) >= 0;
  }
}
0 Likes
Message 3 of 5

ottosson_mathias
Advocate
Advocate

Thanks but this is not a robust solution. The plotter name does not always contain the type of plotter. Bluebeam does not have pdf in its plotter name for example.

0 Likes
Message 4 of 5

SENL1362
Advisor
Advisor

You are absolutely Right!

But you asked for a solution for the plotters mentioned above.

0 Likes
Message 5 of 5

SENL1362
Advisor
Advisor

When you start the AutoCAD Plot command you'll see PDF options for PDF type drivers.

I don't think we have access to these details from the Net API's.

SENL1362_0-1632203969448.png

 

Have a look at my entry to the post: Add plot custom paper size (07-30-2014).

It shows some C# code to read the contents of PC3 and PMP files. For a PDF type of pc3 you find what you are looking for, as show below.

SENL1362_2-1632204340210.png

 

 

 

 

 

 

0 Likes