Using getvar dwgname to name plot file

Using getvar dwgname to name plot file

ipi
Advocate Advocate
2,434 Views
13 Replies
Message 1 of 14

Using getvar dwgname to name plot file

ipi
Advocate
Advocate

Hello,

For years I've been using Adobe's PDF plotter, solely because it has the option to use a default filename. I'm in the process of using the built-in DWG to PDF plotter and am trying to auto-populate the PDF filename.

 

I've found on this forum where people have been able to extract just the filename of the drawing (and not the file extension):

 

^C^C_setenv DrawingName;$M=$(substr,$(getvar,dwgname),1,$(-,$(strlen,$(getvar,dwgname)),4));

 

Now, I would like to know how I can insert the extracted filename to automatically name the PDF.

 

Thanks in advance, and apologies if this has been discussed and I've not found the solution yet,

 

David Hassan

IP Illustration
www.ipillustration.com
0 Likes
Accepted solutions (1)
2,435 Views
13 Replies
Replies (13)
Message 2 of 14

cadffm
Consultant
Consultant

DIESEL getenv function?

like this

^C^C^C_setenv;DrawingName;$M=$(substr,$(getvar,dwgname),1,$(-,$(strlen,$(getvar,dwgname)),4));DWGNAME;_.-PLOT;_y;;DWG To PDF.pc3;"ISO A1 (841.00 x 594.00 MM)";_m;_l;_n;_e;_f;_c;_y;monochrome.ctb;_y;_as;$M=$(getenv,DrawingName);_n;_y

 

But what is with the file PATH?

What is if a file with that name already exists?

That are other questions and you need  to think about it.

 

The one DWGNAME; command is important for a update, because if you used SAVEAS before you run the macro,

you get the old name without this or another trick.

Sebastian

0 Likes
Message 3 of 14

steven-g
Mentor
Mentor

Here's a version, to plot from a layout that is already setup with the layout manager to have the paper size decided.

^C^C^C-PLOT;n;;;DWG To PDF.pc3;$M=$(substr,$(getvar,dwgname),1,$(-,$(strlen,$(getvar,dwgname)),4));y;y;y;re;

It makes no difference if the PDF exists or not (if yes it overwrites the old one) there is an extra "y;re;" at the end of the macro to deal with that, which just finishes the macro cleanly.

There are a few unknowns do you plot from model or paperspace? if paper is your layout setup with papersizes etc (otherwise you would need to use the detailed plot version and give paper size as well).

The best way to alter the macro is run it then press F2 to see the command history which will show you if there were unexpected results and just look through the list of prompts and make changes to the macro until it works. If you get an error then post the recent command history and we can point out how to make changes.

0 Likes
Message 4 of 14

cadffm
Consultant
Consultant

@steven-g It would be more simple to post stuff 1:1 from the disk, it's more work to edit own macros/scripts and co to post it here as answer to a question.

You should give users more opportunity to learn, research and solve themselves 😁

Sebastian

0 Likes
Message 5 of 14

pendean
Community Legend
Community Legend

Don't these spaces break your macro?

Capture.PNG

0 Likes
Message 6 of 14

cadffm
Consultant
Consultant

No, "DWG to PDF.pc3" wouldn't accept as valid printername.

Ofcourse, it's simpler to learn or to teach 'If blanks inside, set the string in "" ' but it isn't right for every situation.

 

 

Sebastian

0 Likes
Message 7 of 14

steven-g
Mentor
Mentor

No, which is unusual as spaces do normal count as the equivalent of pressing "enter", and in other cases when a macro comes up to a point where it expects a string then you have to use quotes, I guess LT is smart after all. 🤣

0 Likes
Message 8 of 14

ipi
Advocate
Advocate

Thank you for all the input so far, and apologies for posting without stating all of the parameters.

 

We plot from paper space in all instances.

 

The directory to which the PDF will be saved is always the same i.e., c:\PDF so I will add that manually to the macro.

 

I'm not concerned with overwriting an existing PDF of the same name.

 

 

David Hassan

IP Illustration
www.ipillustration.com
0 Likes
Message 9 of 14

ipi
Advocate
Advocate

PS: From each paper space we have page setups that include all of the printing parameters, so we don't have to use the detailed -PLOT command

David Hassan

IP Illustration
www.ipillustration.com
0 Likes
Message 10 of 14

pendean
Community Legend
Community Legend
Good to know, have not tried it, we use SSM on project files for publishing and controlling layout names output.

0 Likes
Message 11 of 14

ipi
Advocate
Advocate

Thank you steven-g, this gets me 90% of the way there. Nice touch adding the extra "y;re;" at the end of the macro.

 

The remaining 10% is to define the directory the PDFs are saved to. If I just open the drawings without saving them, the PDF is saved to the AutoCAD LT start in location. If the drawing is saved before creating the PDF, the PDF is saved into the folder where the previously opened drawing is located.

 

FWIW, I did specify the directory I want the PDF saved to in Option > Plot and Publish > Plot to File

 

 

 

 

David Hassan

IP Illustration
www.ipillustration.com
0 Likes
Message 12 of 14

steven-g
Mentor
Mentor
Accepted solution

How about adding a "qsave" at the start of the macro. I can't follow why the PDF doesn't print to the drawing folder, whether I open a dwg by double clicking, or open LT first and then open a dwg, the macro puts the PDF in the same folder as the drawing (but then I am only testing a single drawing!).

Or if you are feeling adventurous you could also add a standard path into the macro right before the Diesel call starts, using forward slashes C:/YOURPDFFOLDER/ without quotes (and it is important here to have no spaces in the folder path either). You don't need any extra semicolons either, Diesel will concatenate the path to the filename. But the folder does have to exist it won't create it.

0 Likes
Message 13 of 14

ipi
Advocate
Advocate

Thank you, steven-g! I added the path just before the DIESEL call and it's working just as I had hoped.

 

Adventurously yours,

 

David

David Hassan

IP Illustration
www.ipillustration.com
0 Likes
Message 14 of 14

steven-g
Mentor
Mentor

Good to hear, thanks for letting us know it is working.

0 Likes