LISP to batch publish / plot to the folder of the current dwg in pdf

LISP to batch publish / plot to the folder of the current dwg in pdf

Anonymous
Not applicable
3,813 Views
11 Replies
Message 1 of 12

LISP to batch publish / plot to the folder of the current dwg in pdf

Anonymous
Not applicable

This *is* a new question as far as I can tell. 

I have tried setting autopublish location to .\ but that only works for autopublish, which includes the 2 tabs not to be plotted. I also tried setting default plot location to .\ to no avail.

 

I am new to lisp, have done a little vba before and diesel, but I can't follow the below.

Annotations on lisp answers to forum posts seem scant on this topic 😞

 

As an example, this looks good because it doesn't appear to manually override all the plot settings, and it does tab name for "Model" so theoretically can be modified to also check for "Construction"...

 

Environmental conditions I can think of:

I am running an AutoCAD OEM (latest version, could be 2018 or 2019) (hence the extra ":cadt" in the defun section of below code), but plot commands aren't affected.

I have set up plot layout settings to all layouts which are to be plotted.

I am using monochrome.ctb for pdf plot.

I want to plot A3 PDF in landscape (per plot settings already applied to template).

Plotter is dwg to pdf (for now).

There are 2 tabs in every dwg to NOT plot: "Construction" and "Model". All other tabs are to be plotted.

Destination should be to the exact folder the current dwg is saved in.

 

The result of this code on my machine is it tries to save a pdf of name "_Y" to the local AutoCAD folder, and it also wants me to save changes to the plot settings. And a pdf viewer is unable to open the result, so presumably it saves without file extension. 

 

TIA for any help!

 

(defun c:cadt:user06
	( / cm )
   ;from 	https://www.cadtutor.net/forum/topic/50659-pdf-file-saving-location-need-help/page/2/#comments
   (setq cm (getvar 'CMDECHO))
   (setvar 'CMDECHO 0)
   (command "_.-plot" "_y"
       (if (= 0 (getvar 'TILEMODE)) "Model" (getvar 'CTAB))
       "DWG To PDF.pc3" "ARCH D (36.00 x 24.00 Inches)"
       "_M" "_L" "_N" "_E" "_F" "_C" "_Y" "monochrome.ctb" "_Y"
   )
   (if (= 1 (getvar 'TILEMODE))
       (command "_A")
       (command "_N" "_Y" "_N")
   )
   (command (strcat (getvar 'DWGPREFIX) "PDF files\\" (vl-filename-base (getvar 'DWGNAME))) "_Y")
   (setvar 'CMDECHO cm)
   (princ)
   ;end web code
)
(vl-load-com) (princ)
	))
)

 

 

[Edit]: Attached example DWG.

0 Likes
3,814 Views
11 Replies
Replies (11)
Message 2 of 12

maratovich
Advisor
Advisor

Attach an example of your dwg file with a title block.

---------------------------------------------------------------------
Software development
Automatic creation layouts and viewport. Batch printing drawings from model.
www.kdmsoft.net
0 Likes
Message 3 of 12

Anonymous
Not applicable

Attached to original post, thank you for taking a look.

0 Likes
Message 4 of 12

maratovich
Advisor
Advisor

Example of batch printing is a different file name

 

 

---------------------------------------------------------------------
Software development
Automatic creation layouts and viewport. Batch printing drawings from model.
www.kdmsoft.net
0 Likes
Message 5 of 12

dbhunia
Advisor
Advisor

Check this.... while you do not plot any Model Space

 

(defun c:Test (/ file)
  (setvar "cmdecho" 0)
	(foreach lay_tab (layoutlist)
		(if (not (wcmatch lay_tab "Construction,Model"))
			(progn
				(setvar 'CTab lay_tab)
				(setq file (strcat (getvar 'DWGPREFIX) (substr (setq dwg (getvar 'DWGNAME)) 1 (- (strlen dwg) 4)) "-" (getvar 'ctab)".pdf"))
				(if (findfile file)
				(vl-file-delete file)
				)
				(command "-plot" "yes" "" "DWG TO PDF.PC3" "ISO A3 (297.00 x 420.00 MM)" "_M" "_L" "_N" "_E" "_F" "_C" "y" "monochrome.ctb" "_Y" "_N" "_Y" "_N" file "n" "Y")
			)
		)
	)   
	(setvar "cmdecho" 1)
  (princ)
)

 


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
Message 6 of 12

Anonymous
Not applicable

Wow thank you so much that almost works! I have 2 pdf files for the correct tabs, in the correct location.

All that's left is an invalid xref table in each pdf, meaning I can't open the pdf files.

Do you have any idea how I can fix that?

 

I have seen wcmatch but wouldn't have known how to run through the layout list with it. Great code, I can see what each line does without annotations - thank you!

0 Likes
Message 7 of 12

Anonymous
Not applicable

Thank you for the extremely well-tailored advertisement, your software is very function-rich! If we ever branch out and need more flexibility / functionality, I will be sure to look you up. For now, the lisp below will do the trick.

0 Likes
Message 8 of 12

dbhunia
Advisor
Advisor

Hi @Anonymous  I also unable to get it.......

 

.....

All that's left is an invalid xref table in each pdf, meaning I can't open the pdf files.

.......

 

So do some step by step Test.....

 

First check with the below line ........ directly run from command line......

(command "-plot" "_Y" "" "DWG TO PDF.PC3" "ISO A3 (297.00 x 420.00 MM)" "_M" "_L" "_N" "_E" "_F" "_C" "_Y" "monochrome.ctb" "_Y" "_N" "_Y" "_N" "" "_N" "_Y")

is it generating pdf ..... and can you open it?.......

 

if not ....... then ........ run "-plot" from command line ......... and check it for which options you are gatting pdf & which opens also.

 

use those options ..... 

 

 


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes
Message 9 of 12

Sea-Haven
Mentor
Mentor

This is another example plots a range of layout tabs useful to leave a couple out. I makes a PDF directory under the dwg and uses the layout name. Version 2 makes pdf's then joins them back together to make 1 Pdf of selected layouts.

You can plot a single layout just enter tab number twice. It has a library routine that creates the dialogue entry on the fly can be used in any program.

 

You will need to change the window size settings.

 

 

 

 

 

0 Likes
Message 10 of 12

Anonymous
Not applicable

Thank you for offering the test. I used the command like you said on command line, and the only thing I noticed different was 'what to plot' defaults to Layout (as per Plot dialog box). If I type Layout there, it exits the plot command with no error messages visible.

We have details outside the layout so Extents is probably not the best... Limits also fails.

 

The command completes successfully generating 2Nr PDF, but opening the PDFs still complains of invalid xref table. I have run xref command and checked all xrefs are correctly referenced and loaded (I had to fix them in the originally attached file, but after fixing, closing and opening the program, same error came up). I guess if you unload and detatch the xrefs in the attached dwg, you will also get the same result?

 

Any further suggestions much appreciated!

0 Likes
Message 11 of 12

chvvskishore
Community Visitor
Community Visitor

Hi,

 

Thank you for provide lisp to publish, can you please provide a lisp to create pdf for all layouts available in the drawing file by saving it in drawing file path.

 

0 Likes
Message 12 of 12

Sea-Haven
Mentor
Mentor

Chvvskishore did you look at my post ?

0 Likes