Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

vla-PlotToDevice

9 REPLIES 9
Reply
Message 1 of 10
morgeny
1190 Views, 9 Replies

vla-PlotToDevice

Hello,

 

I am writting an AutoLISP program to plot layout using the page setup currently assigned to it ( plotter DWG to PDF). The reason is because my network connection is very slow and it takes me a lot of time to go through all those dialog boxes if I use the command PLOT. The only thing I want to change is the folder where I'd like to save the PDF file.

 

The following line is for the plotting

 

(vla-PlotToDevice (vla-get-Plot aDoc))

 

Now the PDF is saved in the same folder as the DWG file. How can I change the path where to save the PDF file?

 

 

Thanks a lot!

Xiangyu

 

9 REPLIES 9
Message 2 of 10
dbroad
in reply to: morgeny

Try this:

(vla-get-defaultplottofilepath
(vla-get-output
(vla-get-preferences
(vlax-get-acad-object))))

Architect, Registered NC, VA, SC, & GA.
Message 3 of 10
morgeny
in reply to: dbroad

 

I tried the (vla-get-DefaultPlotToFile path), it returned the same path as (getenv "PlotToFilePath"), which is not the folder where the current DWG file is. It seems that (vla-PlotToDevice) does not use this path to save the output.

 

Thank you,

Xiangyu

Message 4 of 10
dmfrazier
in reply to: morgeny

"How can I change the path where to save the PDF file?"

Is the path "fixed" (absolute), or relative to the dwg file's location?

Message 5 of 10
morgeny
in reply to: dmfrazier

The path is relative to the dwg file's location. Does it make any difference?

 

Thanks!

Xiangyu

Message 6 of 10
dmfrazier
in reply to: morgeny

"Does it make any difference?"

 

Well, yes, of course it does.  (And I think you already know that.)

If the path is fixed, that fixed path would simply be "hard-coded" in your custom AutoLISP program.  Like so:

(setq pltpath "c:\\drawing\\MyPlotFolder\\");if absolute

Since it will be relative to the DWG file's location, you'll have to determine what that is, and then append whatever else you want to that.  Like so:

(setq pltpath (strcat (getvar "DWGPREFIX") "MyPlotFolder\\"));DWGPREFIX includes last backslash

 

I think you can accomplish what you want with a fairly simple LISP that doesn't require much more than a few setqs and then running the plot command.

Message 7 of 10
morgeny
in reply to: dmfrazier

 

(setq pltpath "C:\\Drawings\MyPlotFolder\\")

 

I think I am still confused.

pltpath is not a system variable? Does it have anything to do with vla-PlotToDevice?

 

 

Thanks,

Xiangyu

 

 

 

 

Message 8 of 10
dmfrazier
in reply to: morgeny

"pltpath is not a system variable?"

 

Correct. It is not a "system variable", but it is a variable - a local variable (created by the programmer) used by the LISP program.

 

"Does it have anything to do with vla-PlotToDevice?"

 

Not really (only in an indirect way).

 

I was under the impression you knew more about AutoLISP than you apparently do.

From your first post:

"I am writting an AutoLISP program to plot layout using the page setup currently assigned to it ( plotter DWG to PDF). The reason is because my network connection is very slow and it takes me a lot of time to go through all those dialog boxes if I use the command PLOT. The only thing I want to change is the folder where I'd like to save the PDF file."

 

Based on this, you could simply run the PLOT command within LISP, as if you were running it at the command line, and feed it all the responses it wants.  Some of those responses will be "fixed" (always the same), and some will be "variable" (change based on circumstances).  The fixed ones get hard-coded; the variable ones will use (surprise!) variables.

 

Let's say you run the -PLOT command to plot the current layout based on its existing page setup.  Here is what that would look like on the command line (the defaults will differ based on your circumstances):

 

Command: -plot
Detailed plot configuration? [Yes/No] <No>: N

Enter a layout name or [?] <MyLayout>:

Enter a page setup name <MyPageSetup>:
Enter an output device name or [?] <DWG to PDF.pc3>:

Enter file name <MyDrawing-MyLayout.pdf>:
Save changes to page setup [Yes/No]? <N> N
Proceed with plot [Yes/No] <Y>: Y
Effective plotting area:  33.94 wide by 21.94 high
Effective plotting area:  33.50 wide by 21.50 high

Plotting viewport 2.

Plotting viewport 1.

 

To convert this to LISP simply run the PLOT command and feed it the responses, separated by spaces (which act as <Enter>).  Use "" (two double quotes) to accept the <default>:

(command "PLOT" "N" "" "" "" "" "N" "Y")

 

In this example, it is assumed you want to accept the defaults for layout name, page setup name, device name, and file name.  If you don't want to use the default for any of these, you would have to provide what you want (somehow).

Based on your first post, it looks like you would want to change only the folder (which is addressed by the prompt for file name).  I think the default for the DWG to PDF driver is to append the Layout name to the DWG name to create a name for the PDF, and then save the file in the DWG's folder.  So, if you want to change that, this is where you would substitute a variable.  Instead of the 4th set of double quotes, put in your variable (use a unique name like pltfilename.)  Then your LISP would look like:

(command "PLOT" "N" "" "" "" pltfilename "N" "Y")

 

But in order for your LISP to use the variable, it has to be set to some value.  Since the value doesn't already exist somewhere that we can go get it, we will have to create it, and since it will be a combination of a path and a filename, it will have to be built.

See message #6 where I proposed a way to create the path portion.  This line sets the variable pltpath to a string consisting of the current DWG's path plus an additional folder I called "MyPlotPath".  (You would change this to whatever you prefer to call it.):

(setq pltpath (strcat (getvar "DWGPREFIX") "MyPlotFolder\\"))

 

Now you can use the pltpath variable to build the pltfilename variable:

(setq pltfilename (strcat pltpath filename "-" layname))

 

The setq lines to set the variables have to run before the line that runs the PLOT command, so the entire sequence would be:

(setq pltpath (strcat (getvar "DWGPREFIX") "MyPlotFolder\\"))

(setq pltfilename (strcat pltpath filename "-" layname))

(command "PLOT" "N" "" "" "" pltfilename "N" "Y")

 

Edit:

Forgot to include setting layname variable (assuming you want the layout name to be part of the PDF filename).  Place this line at the beginning:

(setq layname (getvar "CTAB"))

Message 9 of 10
morgeny
in reply to: dmfrazier

Thank you  very much for the reply! It really helps me out, for I started learning AutoLISP just a couple weeks ago. 

 

Thanks,

Xiangyu

Message 10 of 10
dmfrazier
in reply to: morgeny

No problem.  Thank you for bearing with me.

Good luck.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

”Boost