Jump to content

Select specific named layouts and save them in a folder as a PDF


Manuel_Kunde

Recommended Posts

Hi Guys, I have several layouts when drawing, which also have different names. I want to save in a Lisp all layouts that start with a specific name in a certain folder as PDF.

image.thumb.png.082bdbe27eb820ed93f1b2b64a3afdc7.png

 

I am new in lisp, but i have managed to write a lisp that selects the correct location for me. Unfortunately only all layouts are printed.

 

(defun c:Dokument_Export ()

 

      (command "-EXPORT"

               "PDF"

               "ALLE"

         (strcat (substr (getvar "DWGPREFIX") 1 70) "\\08_Auftragsbestätigung\\"

            (strcat (substr (getvar "DWGNAME") 1 8) "_Zeichnung")

         )

      )

)

 

You have any idea? Thanks in advance.

 

 

Link to comment
Share on other sites

16 hours ago, Manuel_Kunde said:

Hi Guys, I have several layouts when drawing, which also have different names. I want to save in a Lisp all layouts that start with a specific name in a certain folder as PDF.

....

 

Try this way:

(foreach layname (vl-remove-if-not '(lambda (ln)
			(vl-some '(lambda (n)
				(wcmatch ln n))
			  '("Plan*" "PickList" "Debit" "Plakette")
				 ))
		  (layoutlist)
		  )
  (setvar "ctab" layname)
   (command "-EXPORT" "_PDF" "_C" "_N" layname )
  )

HTH

 

  • Like 1
Link to comment
Share on other sites

Hello, thank you for the quick reply, that was already helpful. I have written it that way, but that does not really work yet. Do you have any idea?

 

(defun c:Docexport ()  

(foreach layname (vl-remove-if-not '(lambda (ln)

      (vl-some '(lambda (n)

        (wcmatch ln n))

        '("Plan*" "Plakette")

         ))

      (layoutlist)

      )

  (setvar "ctab" layname)

    (command "-EXPORT" "_PDF" "_C" "_N" layname)

         (strcat (substr (getvar "DWGPREFIX") 1 70) "\\08_Auftragsbestätigung\\"

            (strcat (substr (getvar "DWGNAME") 1 8) "_Zeichnung")

         )

      )

)


 

Link to comment
Share on other sites

1 hour ago, SLW210 said:

You need to wrap your code in tags.

 

Seeing that you have only ever made 2 posts on here.... when you are pasting code into a thread it is best if you 'wrap your code in tags' - if you edit or make a new comment click on the '<>' button (it's with the formatting at the top of the new comment) and paste your code in the pop up box, the result is similar to what pBe did.

  • Like 1
Link to comment
Share on other sites

2 hours ago, Steven P said:

If you use your original "-export" line in the code that pBe posted, what happens?

 

This Code plots all my Layouts in my folder, but i only want the Layouts names Plan* and DIN.

 

(defun c:Docexport ()

  (foreach layname (vl-remove-if-not '(lambda (ln)

        (vl-some '(lambda (n)

          (wcmatch ln n))

          '("Plan*" "DIN")

          ))

        (layoutlist)

        )

    (setvar "ctab" layname)

    (command "-EXPORT"

               "PDF"

               "ALLE"

         (strcat (substr (getvar "DWGPREFIX") 1 70) "\\08_Auftragsbestätigung\\"

            (strcat (substr (getvar "DWGNAME") 1 8) "_Zeichnung")

         )

      )

  )

)

 

 

Edited by Manuel_Kunde
  • Like 1
Link to comment
Share on other sites

(defun c:Docexport ( / pdfName )
  (foreach layname (vl-remove-if-not
		     '(lambda (ln)
			(vl-some '(lambda (n)
				    (wcmatch ln n)
				  )
				 '("Plan*" "Plakette")
			)
		      )
		     (layoutlist)
		   )
    (setvar "ctab" layname)
    (setq pdfName
	   (strcat (getvar "DWGPREFIX") (strcat layname "_Zeichnung.pdf")
	   )
    )
    (if	(findfile pdfName)
      (command "-EXPORT" "_PDF" "_C" "_N" pdfName "Y")
      (command "-EXPORT" "_PDF" "_C" "_N" pdfName)
    )
  )
)

 

The above  should work as expected:

 

I cannot vouched for this though, i'm not sure how this will come out. you specified (getvar 'dwgname) but i dont see the ayout name anywhere

(strcat (substr (getvar "DWGPREFIX") 1 70) "\\08_Auftragsbestätigung\\"
            (strcat (substr (getvar "DWGNAME") 1 8) "_Zeichnung")
         )

 

If you can guarantee that the line above wont fail. then replace the value for pdfName and see if that works for you.

 

HTH

 

How do you add colors to the posted code anyway?  I've been away from this fourm too long that the format is different now 🙂 

 

Edited by pBe
  • Thanks 1
Link to comment
Share on other sites

On 6/28/2021 at 5:07 PM, pBe said:


(defun c:Docexport ( / pdfName )
  (foreach layname (vl-remove-if-not
		     '(lambda (ln)
			(vl-some '(lambda (n)
				    (wcmatch ln n)
				  )
				 '("Plan*" "Plakette")
			)
		      )
		     (layoutlist)
		   )
    (setvar "ctab" layname)
    (setq pdfName
	   (strcat (getvar "DWGPREFIX") (strcat layname "_Zeichnung.pdf")
	   )
    )
    (if	(findfile pdfName)
      (command "-EXPORT" "_PDF" "_C" "_N" pdfName "Y")
      (command "-EXPORT" "_PDF" "_C" "_N" pdfName)
    )
  )
)

 

The above  should work as expected:

 

I cannot vouched for this though, i'm not sure how this will come out. you specified (getvar 'dwgname) but i dont see the ayout name anywhere



(strcat (substr (getvar "DWGPREFIX") 1 70) "\\08_Auftragsbestätigung\\"
            (strcat (substr (getvar "DWGNAME") 1 8) "_Zeichnung")
         )

 

If you can guarantee that the line above wont fail. then replace the value for pdfName and see if that works for you.

 

HTH

 

How do you add colors to the posted code anyway?  I've been away from this fourm too long that the format is different now 🙂 

 

 

 

Hi! Thanks a lot for the help with the code! I made a few more changes to the file location for the export and it works!

 

However, I need all layouts that start with the same name (e.g. "Plan*) in one PDF file, as I often have multiple layouts with the same name beginning. Now the plans are always printed and replaced one by one.

Does anyone have an idea?


Many thanks in advance!

Edited by Manuel_Kunde
Link to comment
Share on other sites

This is because of the -Export Command "Current Layout", which apparently can export only one layout.

Link to comment
Share on other sites

5 hours ago, Manuel_Kunde said:

Hi! Thanks a lot for the help with the code! I made a few more changes to the file location for the export and it works!

 

However, I need all layouts that start with the same name (e.g. "Plan*) in one PDF file, as I often have multiple layouts with the same name beginning. Now the plans are always printed and replaced one by one.

Does anyone have an idea?

 

 

Post your changes then. Let's see what we can do differently to overcome your issue with the name.

I would suggest using publish if you  want multiple page pdfs

 

Edited by pBe
  • Like 1
Link to comment
Share on other sites

If you plot multiple PDF's you can use Ghostscript to join them back into 1, the code I posted I had removed that part. 

 

You just make a list of the pdf's. 

 

;MergePdfs
;Merges multiple pdf (or eps) files into one
;Requires the installation of Ghostscript 

; make a batch file ?
;gs -sDEVICE=pdfwrite \
;    -dNOPAUSE -dBATCH -dSAFER \
;    -sOutputFile=combined.pdf \
;    first.pdf \
;    second.pdf \
;    third.pdf [...]

;Ghostscript (http://www.ghostscript.com/) can be used to combine PDFs.

; Something like this should work: by Roy_043

(defun KGA_String_Join (strLst delim)
(if strLst
(apply
'strcat
(cons
(car strLst)
(mapcar '(lambda (a) (strcat delim a)) (cdr strLst))
)
)
""
)
)

; (CombinePdf 
;  (setq gsexe "C:\\Program Files\\gs\\gs9.19\\bin\\gswin64c.exe")
(setq gsexe "P:\\gs\\gs9.19\\bin\\gswin64c.exe")
; (setq srcFilelst  '("D:\\Tmp\\A.pdf" "D:\\Tmp\\B.pdf"))
; (setq trgfile "C:\\Acadtemp\\Total.pdf")
; )
; Note: Existing trgFile will be overwritten.
(defun CombinePdf (gsExe srcFileLst trgFile)
(startapp 
(strcat
gsExe " "
"-sDEVICE=pdfwrite -dBATCH -dNOPAUSE -dQUIET  "
"-sOutputFile=\"" trgFile "\" "
"\"" (KGA_String_Join srcFileLst "\" \"") "\""
)
)
)

plotA3Pdfrange2.lsp

Link to comment
Share on other sites

On 7/2/2021 at 6:17 PM, pBe said:

 

Post your changes then. Let's see what we can do differently to overcome your issue with the name.

I would suggest using publish if you  want multiple page pdfs

 

 

(defun c:Docexport ( / pdfName )
	(setvar "cmdecho" 0)
	(foreach layname (vl-remove-if-not
						'(lambda (ln)
							(vl-some '(lambda (n)
										(wcmatch ln n)
										)
									'("Plan*")
							)
						)
						(layoutlist)
					)
	(setvar "ctab" layname)
	(setq pdfName
		(stract (substr (getvar "DWGPREFIX") 1 70) "\\09_Produktion DE\\"
		(stract (substr (getvar "DWGNAME") 1 8) "_Zeichnung")
		)
	)
	(if (findfile pdfName)
		(command "-Export" "PDF" "AK" "N" pdfName "J")
		(command "-Export" "PDF" "AK" "N" pdfName)
		)
	)
	(setvar "cmdecho" 1)
)
	

 

This lisp works correct. There is only the problem, that i can export only one Layout with the same name.

Edited by Manuel_Kunde
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...