cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Programmatically print file to PDF

MC_9665161
4-Participant

Programmatically print file to PDF

We're thinking of using MathCAD Prime. One of our key requirements is to be able to programmatically print MathCAD Prime files to PDF (i.e. with no user interaction). I know this is possible with MathCAD 15 (you automate printing to PDF from the commandline with MathCAD 15 by adding the "-p" option after the executable and before the filename), but I cannot see how to do it with MathCAD Prime. I've been looking through the API documentation: https://support.ptc.com/help/mathcad/r7.0/en/index.html#page/PTC_Mathcad_Help%2Fmathcad_and_automati.... It says that you can print MathCAD Prime worksheets, but I cannot actually find this documented anywhere.

Please could you let me know how to do this, either from the API or from the commandline?

Thanks for your help!

1 ACCEPTED SOLUTION

Accepted Solutions

I fear about related functionality up to Mathcad 15 (command mathcad.exe -p test.xmcd😞 this is not part of Mathcad Prime functionality

  • CS361245 How to call Mathcad from command to print a specific worksheet

Workaround: API functionality to save as PDF is introduced with Mathcad Prime 6.0

  • CS315481 for more information about how to print a worksheet as PDF through API
  • Details:
    • Use the API method:   IMathcadPrimeWorksheet3::SaveAs(string path)
    • Sample code:

Ptc.MathcadPrime.Automation.ApplicationCreator mathcad = new Ptc.MathcadPrime.Automation.ApplicationCreator();
           IMathcadPrimeWorksheet3 mathcadPrimeWorksheet = mathcad.Open("d:\\test.mcdx") as IMathcadPrimeWorksheet3;
         
           if (mathcadPrimeWorksheet != null)
           {
               mathcadPrimeWorksheet.SaveAs("d:\\test.pdf");
              //Just change the extension of the file here to print to other formats such as RTF.                
               mathcadPrimeWorksheet.Close(SaveOption.spDiscardChanges);
           }

 

  • Note:
    • Saving with PDF format is supported since Mathcad Prime 6.0.
    • Users can use Object Browser from Visual studio to see the list of all Mathcad Prime APIs, by loading the file Ptc.MathcadPrime.Automation.tlb from Mathcad Prime installation directory.
  • Related: CS338281 [Knowledge hub] Customization with Mathcad Prime

View solution in original post

10 REPLIES 10
ppal
17-Peridot
(To:MC_9665161)

I dont know the but perhaps this:

https://community.ptc.com/t5/PTC-Mathcad/Batch-Printing/td-p/209960 may have some answers.

 

https://www.fcoder.com/how-to/printing-video-tutorials

Print Conductor allows you to seamlessly print an unlimited number of CAD drawings including MathCAD, MathCAD Prime and Solid Edge drawings, multi-page DWFX drawings, and more. No CAD software required!

MC_9665161
4-Participant
(To:ppal)

Hi,

 

Thanks for your response.

  • The thread that you mention is for MathCAD 14 & 15, not MathCAD Prime, so it's not very relevant.
    • To automate publishing MathCAD 15 I ended up using the -p option and an old version of PDFCreator to print to a specific location with a specific naming convention. Once the PDF has been generated I then force close MathCAD 15 to get around the problem with the error message.
    • The other suggestion in that thread is AutoIt, which I have tried. It requires the window to be in focus to work and it is very fiddly to get all the codes for the click areas. It is flakey and does not always work. I ended up spending a lot of time building a solution that uses it, only to be disappointed and have to throw it away. I would not recommend it to anyone.
  •  Print Conductor does sound cool, but it seems like it still requires user intervention. If it can be automated then I would love to hear more about it.

 

What I'm really asking, is there a way to automate printing MathCAD Prime? Is there a -p option or is there a scripting language, e.g. VBscript, which you can use to print MathCAD Prime?

I fear about related functionality up to Mathcad 15 (command mathcad.exe -p test.xmcd😞 this is not part of Mathcad Prime functionality

  • CS361245 How to call Mathcad from command to print a specific worksheet

Workaround: API functionality to save as PDF is introduced with Mathcad Prime 6.0

  • CS315481 for more information about how to print a worksheet as PDF through API
  • Details:
    • Use the API method:   IMathcadPrimeWorksheet3::SaveAs(string path)
    • Sample code:

Ptc.MathcadPrime.Automation.ApplicationCreator mathcad = new Ptc.MathcadPrime.Automation.ApplicationCreator();
           IMathcadPrimeWorksheet3 mathcadPrimeWorksheet = mathcad.Open("d:\\test.mcdx") as IMathcadPrimeWorksheet3;
         
           if (mathcadPrimeWorksheet != null)
           {
               mathcadPrimeWorksheet.SaveAs("d:\\test.pdf");
              //Just change the extension of the file here to print to other formats such as RTF.                
               mathcadPrimeWorksheet.Close(SaveOption.spDiscardChanges);
           }

 

  • Note:
    • Saving with PDF format is supported since Mathcad Prime 6.0.
    • Users can use Object Browser from Visual studio to see the list of all Mathcad Prime APIs, by loading the file Ptc.MathcadPrime.Automation.tlb from Mathcad Prime installation directory.
  • Related: CS338281 [Knowledge hub] Customization with Mathcad Prime
MC_9665161
4-Participant
(To:MWunder)

Hi, this is great, thanks! I'm guessing the code example you provided is .NET?

MC_9665161
4-Participant
(To:MWunder)

Thanks for this. Out of curiosity, will it work for MathCAD Express as well?

Hi, sorry for the delay, 

 

1.

as I know the code will run compiled as C# (C Sharp) language code.

And yes, this is also supported by Microsoft's .NET Framework (for example, create a new Console App .NET Framework project).

 

2.

I am not sure about Mathcad Prime Express and API support - I could not find any such statement.

 

I guess a valid reason for that is PTC normally states what is supported, rather than what is not supported.

Another valid reason could be: Mathcad Prime Express is not a different product - it is rather a limited run mode of the full Mathcad Prime product in case a valid license is (even temporary) not available.

And third, since the Express mode is a restriction to specific known features, called Premium features, I cannot imagine that it restricts any customized feature as well (which is nothing but another coding library, but built from customized code by the customer).

 

I hope this helps,

Michael

The API should work with Mathcad Express.

I manage the Creo and PTC Mathcad YouTube channels for PTC, as well as all PTC Mathcad marketing in general.
MC_9665161
4-Participant
(To:DJNewman)

Fantastic, thanks!

MC_9665161
4-Participant
(To:MWunder)

Thanks! I will try it out!

I have a full sub doing this, but in VBA. I don't know if this sub allows providing full code.

Announcements