PDA

View Full Version : ME10 command-line PDF printing


robiman
01-06-2006, 04:46 AM
Hi

I'm trying to automatically generate PDF files from ME10. I got this far: from the command line I can run

me10 -p drawing.mi

and I get a nice little PDF file in the working dir. My problem is that I can only set a fixed filename:

(customize_p.m)
PLOT_DESTINATION DEL_OLD 'x.pdf'
PLOTTER_TYPE 'PDF_GENERIC'

Is there a way to associate the PDF filename to the .mi filename? Some macro or something? I found some info on retrieving filenames in this thread:

http://www.cocreateusers.org/forum/showthread.php?t=5679

But I don't know how to use this information in my case.

Please help
robert

John Scheffel
01-06-2006, 08:40 AM
The attached macro file may help. It contains a macro I wrote which will extract the name of the currently loaded MI file from the full path returned by INQ_ENV. It can optionally remove the file extension (such as ".mi"). After the macro is some code showing how you could use it to set the print output file name to match the loaded MI file name, but replace the .mi extension with .pdf. You can add this code to your customize_p.m file to see if it works (I have not tested it with the -p startup option).

robiman
01-08-2006, 10:13 PM
Thanks John, it works like a charm! I have one more question: is it possible to put this macro in a seperate file, and call it from "customize_p.m"? I tried to do this, but when I call the macro (before PLOT_DESTINATION line, of course):

INPUT 'getfname.m'

I get an error saying that "The macro Amts_file_basename is not defined". I also tried INPUT IMMEDIATE - same result.

John Scheffel
01-09-2006, 01:15 PM
Thanks John, it works like a charm! I have one more question: is it possible to put this macro in a seperate file, and call it from "customize_p.m"? I tried to do this, but when I call the macro (before PLOT_DESTINATION line, of course):

INPUT 'getfname.m'

I get an error saying that "The macro Amts_file_basename is not defined". I also tried INPUT IMMEDIATE - same result.
Using INPUT probably does not work as you think it does. It does not work as I think it should. It may not finish reading the getfname.m file and defining the macro before it goes on to the next line in your customize_p file. This behavior has been the source of a lot of bizarre and hard to debug problems in out startup files.

I think if you use INPUT IMMEDIATE you will need to put it and the following commands within a macro definition then run the macro. I have not used IMMEDITATE much since it won't work with path names containing variables, which is what I mostly use. A bizarre limitation I have never understood.

Henk Stokkel
01-09-2006, 10:16 PM
Robiman,

We use the atached macro to plot a lot of files to pdf. Just make a list of the files to be plotted and go ahead.

Henk

robiman
01-10-2006, 12:59 AM
Thank you Henk, without knowing it you already answered my next question. :) I was going to ask how to retrieve drawing orientation - portrait or landscape. I took a piece of your code to do the job:

DEFINE Plot_mode
EDIT_PART TOP
INQ_ENV 6
LET Plot_sc (INQ 4)
INQ_ENV 7
LET Plot_width (((X_OF ((INQ 102)-(INQ 101)))*Plot_sc)-0.001)
LET Plot_height (((Y_OF ((INQ 102)-(INQ 101)))*Plot_sc)-0.001)

IF (Plot_width>Plot_height)
LET Mode 'A3'
ELSE
LET Mode 'A3P'
END_IF
END_DEFINE

Plot_mode

PLOT_FORMAT (Mode)

Since I'm quite fresh with ME10, I was wondering is this the correct way to retrieve page orientation from ANY .mi file? I run this macro on several test files, and I always got the right orientation.

thanx again
Robert

MichaelA
02-07-2006, 06:27 AM
Robiman, have you been successful in getting your macro to work? I'm interested in doing a similar function, while saving a .mi file in v11.6 I also want to save a PDF file at the same time. I have some of the info but not enough to make it all work. Can you post your macro to share? Thks

robiman
02-09-2006, 03:49 AM
Robiman, have you been successful in getting your macro to work? I'm interested in doing a similar function, while saving a .mi file in v11.6 I also want to save a PDF file at the same time. I have some of the info but not enough to make it all work. Can you post your macro to share? Thks
Yes, PDF generator works flawlessly, at least for our drawings. To sum up what I did: (all of this code goes to customize_p.m)

1. The first macro (many thanks to John Scheffel) reads the filename of the drawing, so we can use it later when saving the generated PDF:

DEFINE Atms_extract_basename
PARAMETER Input_path
PARAMETER Remove_extension

LOCAL Input_strlen
LOCAL Slash_posn
LOCAL Dot_posn
LOCAL Substring
LOCAL Path_sep
LOCAL Strlen
LOCAL Basename

{ The direction of the slash can vary depending on how file was loaded }
{ Set the path separator based on which is found in the string. }
IF (POS Input_path '\')
LET Path_sep '\'
ELSE
LET Path_sep '/'
END_IF

{Extract the base name from the full path}
LET Input_strlen (LEN Input_path)
LET Slash_posn (POS Input_path Path_sep)
LET Substring Input_path
LET Strlen (LEN Substring)
LOOP
IF (Slash_posn<>0)
LET Substring (SUBSTR Substring (Slash_posn + 1) (Strlen - 1))
LET Strlen (LEN Substring)
LET Slash_posn (POS Substring Path_sep)
LET Basename Substring
ELSE
LET Basename Substring
END_IF
EXIT_IF (Slash_posn=0)
END_LOOP

IF (Remove_extension)
LET Dot_posn (POS Basename '.')
IF (Dot_Posn<>0) {If no '.' then no extension, just leave as is}
LET Substring Basename
LET Strlen (LEN Substring)
LET Basename ''
LOOP
LET Basename (Basename + (SUBSTR Substring 1 Dot_posn))
LET Substring (SUBSTR Substring (Dot_posn+1) Strlen)
LET Dot_posn (POS Substring '.')
LET Strlen (LEN Substring)
EXIT_IF (Dot_posn=0)
END_LOOP
{Remove the last '.'}
LET Basename (SUBSTR Basename 1 ((LEN Basename)-1))
END_IF
END_IF

LET Atms_file_basename Basename
END_DEFINE {Atms_extract_basename}

2. The next macro (I can't find the original poster - many thanks to him too) retrieves the page orientation, so I can set the paper in the right position (portrait or landscape):

DEFINE Plot_mode
EDIT_PART TOP
INQ_ENV 6
LET Plot_sc (INQ 4)
INQ_ENV 7
LET Plot_width (((X_OF ((INQ 102)-(INQ 101)))*Plot_sc)-0.001)
LET Plot_height (((Y_OF ((INQ 102)-(INQ 101)))*Plot_sc)-0.001)

IF (Plot_width>Plot_height)
LET Mode 'A3'
ELSE
LET Mode 'A3P'
END_IF
END_DEFINE

3. Now all you have to do is to call this two macros:

INQ_ENV 0
LET Current_fullpath (INQ 304)
Atms_extract_basename Current_fullpath 1
PLOT_DESTINATION DEL_OLD (Atms_file_basename+'.pdf')

PLOTTER_TYPE 'PDF_GENERIC'

Plot_mode
PLOT_FORMAT (Mode)

4. You must have paper modes A3 and A3P defined in plotdefs file:

'A3' 'HPGL_GENERIC,HPGL2_GENERIC,HPGL2_RTL_GENERIC,PDF_GENERIC,POSTSCRIPT_GENERIC' 0 0 425 302 'mono,rgb3,rgb24' '150,300' '150,300' 'me10' 'mode2'
'A3P' 'HPGL_GENERIC,HPGL2_GENERIC,HPGL2_RTL_GENERIC,PDF_GENERIC,POSTSCRIPT_GENERIC' 0 0 302 425 'mono,rgb3,rgb24' '150,300' '150,300' 'me10' 'mode2'


5. and finally, from the commandline: me10 -p filename.mi

As you can see, I only use A3 paper size, so if you want to use all sorts of different paper sizes, you will have to modify "Plot_mode" macro to fit your needs.

Now, since this works for printing the PDF, I'm not sure if you can get it to work for saving files in the same way - any ideas from ME10 experts on this subject?