Author Topic: Set plot paper margins with .NET  (Read 3064 times)

0 Members and 1 Guest are viewing this topic.

AngelKostadinov

  • Newt
  • Posts: 30
Set plot paper margins with .NET
« on: September 28, 2016, 04:46:42 AM »
Hello!

I've created a .NET routine that iterates through all files in specified folder and creates pdf files from dwg layouts. The idea is taken from this post: http://through-the-interface.typepad.com/through_the_interface/2007/09/driving-a-basic.html. Everything works fine but 1 thing drives me crazy and that are paper margins.

Lets pretend we are plotting a random layout with Pdf plotter to A0 paper with .NET API. We have to set plot device name and media name:

Code: [Select]
plotSettingsValidator.SetPlotConfigurationName(plotSettings, "Dwg to Pdf.pc3", "ISO_full_bleed_A0_(841.00_x_1189.00_MM)");
Exported Pdf file is on A0 paper but it has bottom and right margins which differs from top and left.
Attachment: MarginsPdf.PNG
Attachment: SAMA-JOGE-A-VCF-EXE-007-PPR-TNX-P00-1180-A2.pdf

I'm wondering how ot set all paper margins to 0. Is there some way ot configure plot paper with .NET, on the same way as it it possible through AutoCAD graphical interface?
Attachment: Margins.PNG

Thanks in advance!

nobody

  • Swamp Rat
  • Posts: 822
  • .net stuff
Re: Set plot paper margins with .NET
« Reply #1 on: October 02, 2016, 02:29:39 AM »
Not sure about .net but could you not just create a PC3 file with the margins set to use that and use it as your printer?

Hello!

I've created a .NET routine that iterates through all files in specified folder and creates pdf files from dwg layouts. The idea is taken from this post: http://through-the-interface.typepad.com/through_the_interface/2007/09/driving-a-basic.html. Everything works fine but 1 thing drives me crazy and that are paper margins.

Lets pretend we are plotting a random layout with Pdf plotter to A0 paper with .NET API. We have to set plot device name and media name:

Code: [Select]
plotSettingsValidator.SetPlotConfigurationName(plotSettings, "Dwg to Pdf.pc3", "ISO_full_bleed_A0_(841.00_x_1189.00_MM)");
Exported Pdf file is on A0 paper but it has bottom and right margins which differs from top and left.
Attachment: MarginsPdf.PNG
Attachment: SAMA-JOGE-A-VCF-EXE-007-PPR-TNX-P00-1180-A2.pdf

I'm wondering how ot set all paper margins to 0. Is there some way ot configure plot paper with .NET, on the same way as it it possible through AutoCAD graphical interface?
Attachment: Margins.PNG

Thanks in advance!

AngelKostadinov

  • Newt
  • Posts: 30
Re: Set plot paper margins with .NET
« Reply #2 on: October 03, 2016, 01:48:32 AM »
This is a good idea, but, I think, it is not possible to create PC3 file trough .NET API. My routine runs on many computers in our company and I couldn't ask every employee to create a new plot device manually.

Thanks for the replay!

n.yuan

  • Bull Frog
  • Posts: 292
Re: Set plot paper margins with .NET
« Reply #3 on: October 03, 2016, 09:29:47 AM »
There is no .NET API available to manipulate PC3 file, as you already are aware of. So, if your plotting app needs a specific paper configuration, you need to manually create a custom PC3 file and distribute to every user's AutoCAD environment where your plotting app is used. My office uses a custom paper setup without its own PC3 file, and its availability is guaranteed by our AutoCAD station/resource setup procedure.

Keith Brown

  • Swamp Rat
  • Posts: 601
Re: Set plot paper margins with .NET
« Reply #4 on: October 03, 2016, 11:19:54 AM »
This is a good idea, but, I think, it is not possible to create PC3 file trough .NET API. My routine runs on many computers in our company and I couldn't ask every employee to create a new plot device manually.

Thanks for the replay!


You can look at this.  It is supposed to be a reference library for opening and modifying AutoDesk® plot files (.pc3, .pmp, .stb, .ctb).
Keith Brown | AutoCAD MEP Blog | RSS Feed
AutoCAD MEP 2014 / Revit MEP 2014 / EastCoast CAD/CAM addon / Visual Studio 2013

AngelKostadinov

  • Newt
  • Posts: 30
Re: Set plot paper margins with .NET
« Reply #5 on: October 04, 2016, 10:26:02 AM »
I found PiaNO and downloaded the source code, but up to now I couldn't find any spare time to play with. I was hoping someone to say something about PMP files. Currently, I dont understand very well what those files are and where they are used. AFAIK those files contain paper settings and they could be attached to a PC3 file. So, is it possible to distribute a PMP file only, filled up with desired paper settings and to attach it to the PC3 file before plotting? Could you, please, explain me what is the relation between both PC3 ama PMP files and is there a .net API that allows attaching and detaching - I couldn't find such in Reflector watching decompiled code.

Last but not least - Thank you very much! :)

BlackBox

  • King Gator
  • Posts: 3745
Re: Set plot paper margins with .NET
« Reply #6 on: October 04, 2016, 02:25:32 PM »
Rather than modifying each-and-every-one of the required plot settings, for each DWG... I find it easier to instead simply import & apply a named Page Setup (previously configured).

*IF* that sounds beneficial, this old post has a .NET (C#) LispFunction that you can cull.


Cheers
"How we think determines what we do, and what we do determines what we get."

dgorsman

  • Water Moccasin
  • Posts: 2422
Re: Set plot paper margins with .NET
« Reply #7 on: October 04, 2016, 04:05:48 PM »
Rather than modifying each-and-every-one of the required plot settings, for each DWG... I find it easier to instead simply import & apply a named Page Setup (previously configured).

*IF* that sounds beneficial, this old post has a .NET (C#) LispFunction that you can cull.


Cheers

Indeed.  Point it at a pre-configured PC3 in a common network location and everyone is good to go.
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}

AngelKostadinov

  • Newt
  • Posts: 30
Re: Set plot paper margins with .NET
« Reply #8 on: October 05, 2016, 05:00:40 AM »
I created a new PC3 -> Dwg To Pdf 2.PC3 trough AutoCAD graphic interface and modified standart paper sizes in a way that all paper margins equal 0. As you can see from attached picture, AutoCAD automatically associate newly create PC3 file with Dwg To Pdf 2.PMP file.
Here http://forums.autodesk.com/t5/autocad-architecture/what-are-pmp-files/td-p/1719148 he explains that PMP file represent a  File containing custom plotter calibration and custom paper size information associated with plotter configuration file.

So, correct me if I'm wrong, but :
  • AutoCAD doesn't take into counts a PMP file when plot is made from C# code;
  • There is no .NET API that I could use in order to make AutoCAD to use specific PMP file.


Pdfs generated from C# with this new plot device contain default margins again :(.

n.yuan

  • Bull Frog
  • Posts: 292
Re: Set plot paper margins with .NET
« Reply #9 on: October 05, 2016, 09:47:06 AM »

  • AutoCAD doesn't take into counts a PMP file when plot is made from C# code;


Wrong. AutoCAD DOES take into account of PMP file, if the selected plotting device is presented as *.pc3, and the there is a *.pmp for it (e.g. a PMP file named the same as the PC3 file., whether the plotting started as built-in command, or from you custom code (in your plotting code, you need to set the plotting device to a PC3 file, right?).

When you use Autodesk's plotter manager UI to generate a custom plotter configuration (PC3) file (or modify an existing one), besides the generated *.pc3 file, there could also be a *.pmp file (plotter description file) generated when you specify a custom paper (size, margin...).

As I said in my previous reply, my office use a custom PC3 file for a custom paper size, specifically for our custom plotting application I wrote. As long as the *.pc3 file and the corresponding *.pmp file is available to an AutoCAD computer (that is, the 2 files are in the location specified by AutoCAD->Options->Printer Support Path->Printer Configuration File Search Path/Printer Description File Search Path), our custom plotting app does the plotting (to PDF) as expected.

Of course, in our case, we place the PC3/PMP files on a network and all users' AutoCAD's printer support path is pointed to the network location, so there is no need to distribute/install the PC3/PMP file to each computer. In a plotting app, one can have code to check the PC3/PMP availability before custom plotting starts.

AngelKostadinov

  • Newt
  • Posts: 30
Re: Set plot paper margins with .NET
« Reply #10 on: October 06, 2016, 04:53:36 AM »
Quote
AutoCAD DOES take into account of PMP file
- You are absolutely right!!!

The problem was hiding elsewhere, but the result seemed like PMP files was not applyed. In my code, I'm using window plot type, but I'm setting wrong window area. Wondow area is calculated from geometric extents of specific block reference, which represents a drawing frame. There is an invisible object inside drawing frame block, which enlarges the extents of the frame, so real extents differes from visible.

Thank you very much! I'm very pleased from results now!

CADbloke

  • Bull Frog
  • Posts: 321
  • Crash Test Dummy
Re: Set plot paper margins with .NET
« Reply #11 on: July 06, 2020, 09:39:33 PM »
I found a PC3, PMP etc viewer at http://www.noliturbare.com/plot-print/print-ctbs-and-more . The MDI unpacker worked for me. The file format is explained here: http://www.noliturbare.com/more/faq#Q5, quoted here in case it goes away ...

Quote
Format of AutoCAD plotting support files (CTB, STB, PC3, PMP)
These plotting support files use zlib compression. After decompression you get an ASCII file that is more or less human readable.

The compressed file starts with a 59 bytes long header that has nothing to do with this type of compression - it makes these files more or less proprietary. The header contains some identification strings - that is the easy part. Bytes 55-59 stores the length of the compressed section in little endian format. The obscure part is bytes 48..54.

To decompress, this whole header can be skipped. To test this, just crop the first 59 bytes from the file with an editor and use a zlib tool to decompress the decapitated file.

To compress, a header should be added, containing the strings like PIAFILEVERSION... and the numbers have to be written in it. Bytes 55-59 stores the length of the compressed section in little endian format. For example, byte sequence 01 CA 00 00 is hex length 00 00 CA 01 (51713 bytes) starting at byte 60. Bytes 48..54 may be filled with FF FF FF FF FF FF 00. Hint re the bytes 55..59 thankfully received from Graeme.

 I'm also still trying out PiaNO, linked previously in this thread. If you look at PiaSerializer.cs you will see the Serializer code. If you use the unpacker form the 1st link you will see the properties inside the various files you could read and manipulate with PaiNO.