Automate printing Mathcad sheets to PDF

0

I am trying to print all files in certain format (i.e. *.xmcd) in a folder to PDF. I already made AdobePDF my default printer. I want to do this task using powershell but I when I run it I get the an error, which I think has to do something with Mathcad software.

I also added VBScript tag since as I am moving forward with this. I more think about using visual basic for this purpose.

This is the command:

Start-Process -FilePath “internal.company.com\path\to\the\file.xmcd” –Verb Print -PassThru | %{sleep 10;$_} | kill

And the error that I get:

enter image description here

It basically should get the file, start printing and after 10 seconds close the application.

I also tried cygwin and cygstart like below but it gives me an error;

cygstart --print myfile.xmcd

and the error is: Unable to start 's.xmcd': The DDE transaction failed.

First step is to figure out a way to print mathcad sheet using powershell or batch/bash script.

Note: Mathcad sheets have XML format.

Note-2: Out-Print gives a pdf of the xml.

Note-3: cmd.exe /C ASSOC .xmcd gives me .xmcd=Mathcad.

And, cmd.exe /c ftype Mathcad gives me Mathcad="C:\Program Files (x86)\Mathcad\Mathcad 15\mathcad.exe" /dde.

M--

Posted 2017-05-08T14:16:46.597

Reputation: 171

What is the output of the command & cmd.exe /C ASSOC .xmcd? Have you investigated Out-Printer? – lit – 2017-05-08T17:34:23.307

@lit Out-Printer prints the XML format of the file. I think I need to somehow open the file with Mathcad.exe and then print it. – M-- – 2017-05-08T17:47:58.860

@lit I added output of cmd.exe /C ASSOC .xmcd in the question. – M-- – 2017-05-08T17:51:40.057

What is the output of & cmd.exe /c ftype Mathcad? – lit – 2017-05-08T18:02:22.823

@lit Mathcad="C:\Program Files (x86)\Mathcad\Mathcad 15\mathcad.exe" /dde – M-- – 2017-05-08T18:05:33.167

Does the simple example in the Start-Process help work? Start-Process -FilePath "myfile.txt" -WorkingDirectory "C:\PS-Test" -Verb Print – lit – 2017-05-08T18:09:59.490

It does work. but not for the .xmcd file of course. For a text file it does its job with no error. – M-- – 2017-05-08T18:12:33.843

Please try quoting the -Verb. -Verb "Print" – lit – 2017-05-08T18:41:44.610

@lit It does give me the same error. It opens mathcad but the sheet won't load. and no print out. – M-- – 2017-05-08T18:46:08.707

Please try specifying the -FilePath with "\\internal.company.com\path\to..." or with "\\SERVERNAME\SHARENAME\path\to..." or with "D:\path\to...". – lit – 2017-05-08T18:53:54.260

@lit already tried that with different path and etc. – M-- – 2017-05-08T18:55:03.487

My apologies. I will not waste more of your time until I have something in which I have more confidence. – lit – 2017-05-08T19:12:43.060

@lit No worries. Thanks for your time and help. – M-- – 2017-05-08T19:13:37.917

@lit It'd be great if you could take a look at my answer. You may be able to help me with the next step. – M-- – 2017-05-09T21:10:24.770

Answers

0

I found a way to do this;

for %f in (*.xmcd) do "C:\Program Files (x86)\Mathcad\Mathcad 15\mathcad.exe" -p %f

It will prompt the save dialog and you need to hit OK to save it as PDF (or send it to your default printer).

It is wise to not run so many files (10~20 would be good) at the same time as it may causes some errors including licensing but not limited to that.

M--

Posted 2017-05-08T14:16:46.597

Reputation: 171

Glad you found a way. I am not sure why you would want to wait. Does every "print" b mathcad.exe cause a dialog box to appear, or is that from the Adobe PDF printer driver? – lit – 2017-05-09T22:10:42.270

@lit it's from Adob PDF. – M-- – 2017-05-09T22:31:13.820

@lit Indeed it is. But unfortunately we don't have admin access to registry on company's machines. But anyhow, I now know it is possible. Thank you for your help. – M-- – 2017-05-10T00:21:50.247