Let user specify a path from which files (PDF) will be imported and saved (DWG)

pablo.odriozola
Contributor

Let user specify a path from which files (PDF) will be imported and saved (DWG)

pablo.odriozola
Contributor
Contributor

I have developed a Lisp routine and I now want to run it several times, once per PDF file in a given folder.

The idea is that the user somehow specifies a path and the program does the following as many times as the number of PDF files in that path:

1. Create a new drawing

2. Import the Nth PDF File

3. Run the lisp routine

4. Save the drawing with the name of the PDF file in the given path

5. Back to Step 1

Anyone has any Idea how to achieve this? 

Thanks, Pablo

0 Likes
Reply
298 Views
3 Replies
Replies (3)

Sea-Haven
Mentor
Mentor

Ok 1st part is easy.

 

 

(setq pdfdir (getfiled "Select pdf File" "" "pdf" 16))
(setq pdfpath (vl-filename-directory pdfdir))
(setq files (vl-directory-files pdfpath "*.dwg"))

 

As your wanting to import a pdf then save you will more than likely need to write a script as your saving and closing multiple dwg's. Maybe use Scriptpro or just write your own script using a lisp.

 

 

 

 

 

0 Likes

pablo.odriozola
Contributor
Contributor

Hi Sea-Haven
Thanks for your reply! You're totally right about the need for a script, but I'm guessing the best in this case would be to create a LISP file that generates that script based on the contents of a given folder.
I've found the following lisp that works for a similar use:

(defun c:ucmd (/)
	(setq 	dwgs	(LM:getfiles "" "" "dwg")
		cmd		"_.updco"
		blk		"CALLOUT"
	)

(alert (strcat "This utility will redefine the " blk " block\ndefinition and may break linked attributes")

(foreach dwg dwgs
	(progn
	(setq f (open "%userprofile%/documents/ucmd.scr" "w"))
	(write-line (strcat "_.open \"" dwg "\" " cmd " _.saveas _.2010 \"" dwg "\" _.close") f)
	(close f)
	)
)

(command "_script" "%userprofile%/documents/ucmd.scr")

)

but I can't get my head around the syntax of the following line in order to change it to what I want

 (write-line (strcat "_.open \"" dwg "\" " cmd " _.saveas _.2010 \"" dwg "\" _.close") f)

 I would need it to generate the following line for each pdf in the folder:

_new template.dwt filedia 0 _pdfimport pdf pagenumber insertionpoint scalefactor rotationangle customLISPcall _save dwg 

Where pdf is the path of each pdf file and dwg is a modified version of that path with the .dwg extension instead of the .pdf
Do you know what the syntax would be for writing such a line on the script file?
Thanks in advance!

0 Likes

Sea-Haven
Mentor
Mentor

Try this you have to change the drive and directory for one you have.

 

 

; simple pdf attach for single page pdfs
; then make a new dwg
; By AlanH Oct 2023

(defun pdfin ( / pdfdir pdfpath files filein fileout fo dwgprefix )
(setq pdfdir (getfiled "Select pdf File" "" "pdf" 16))
(setq pdfpath (vl-filename-directory pdfdir))
(setq files (vl-directory-files pdfpath "*.pdf"))
(setq dwgprefix (strcat (getstring "\nEnter Dwg prefix ") "-"))

(setvar 'filedia 0)

(setq fo (open (setq fname "d:\\acadtemp\\mypdfs.scr") "w"))
(foreach filein files
  (setq fileout (strcat "d:\\acadtemp\\pdftest\\" dwgprefix (substr filein 1 (- (strlen filein) 4))))
  (write-line (strcat "pdfattach "  (chr 34) pdfpath "\\" filein (chr 34) ) fo)
  (write-line "1 0,0 1.0 0.0" fo)
  (write-line "saveas 2018" fo)
  (write-line (strcat (chr 34)  fileout (chr 34)) fo)
  (write-line "erase last  " fo)
  (princ (strcat "\n" fileout))
)

(write-line "filedia 1" fo)
(write-line "close No" fo)
(close fo)

(vl-cmdf "script" "D:\\acadtemp\\mypdfs.scr")

(princ)
)
(pdfin)

 

 Just select a pdf from the directory where you have the pdf's it will select all. 

0 Likes