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

Pdf creator

8 REPLIES 8
Reply
Message 1 of 9
Anonymous
247 Views, 8 Replies

Pdf creator

I have written this lisp to block out an area of a drawing and create a pdf. Unfortunately it chrashes in the file that it is trying to create is already present,

Can anyone suggest a way to check for the variable fname prior to tyring to write the block,

Also, Is it possible to write an error function into this lisp or does the fact that it jumps from one drawing to another mean that this is not possible.


(Defun c:ext (/ nsheet dname dname1 dpref oldname fname pt1 ss1 echo)
(setq ECHO (GETVAR "CMDECHO"))
(SETVAR "CMDECHO" 0)
(setvar "lispinit" 0)
(setq sheetno (getstring "\nsheet number (if allready converted then delete old files) ?: "))
(setq dname (getvar "dwgname"))
(setq dname1 (substr dname 1 (- (strlen dname) 4)))
(setq dpref (getvar "dwgprefix"))
(setq oldname (strcat dpref dname1))
(setq fname (strcat "C:/My Documents/PLOTFILES/" dname1 "-sched-" sheetno))
(setq pt1 (getpoint "\npick left hand corner of sheet?: "))
(setq ss1 (ssget))
(command "sdi" "1")
(command "-wblock" fname "" pt1 ss1 "")
(command "undo" "1")
(command "qsave")
(command "fileopen" fname)
(command "plot" "y" "" "pdf995" "a4" "m" "p" "n" "e" "f" "0,0" "y" "a3.ctb" "y" "n" "n" "n" "y" "")
(command "fileopen" "y" oldname)
(setvar "lispinit" 1)
(command "sdi" "0")
(SETVAR "CMDECHO" ECHO)
(princ)
)

Many thanks


Spencer
8 REPLIES 8
Message 2 of 9
Anonymous
in reply to: Anonymous

Use "findfile".
[code]
(if (setq fname (strcat "C:/My Documents/PLOTFILES/" dname1 "-sched-" sheetno))
(rename here)
)
[/code]

Tim
Message 3 of 9
Anonymous
in reply to: Anonymous

Hit the wrong button.

[code]
(if (findfile fname)
(rename here)
)
[/code]
That way if the file name exist you have to rename it, if not then it goes ahead and names it and finishes the lisp.

Tim
Message 4 of 9
Anonymous
in reply to: Anonymous

(if (findfile fname.... -- Matt W There are 3 kinds of people: Those who can count, and those who can't. "spencer1971" wrote in message news:23687418.1086884657291.JavaMail.jive@jiveforum1.autodesk.com... | I have written this lisp to block out an area of a drawing and create a pdf. Unfortunately it chrashes in the file that it is trying to create is already present, | | Can anyone suggest a way to check for the variable fname prior to tyring to write the block, | | Also, Is it possible to write an error function into this lisp or does the fact that it jumps from one drawing to another mean that this is not possible. | | | (Defun c:ext (/ nsheet dname dname1 dpref oldname fname pt1 ss1 echo) | (setq ECHO (GETVAR "CMDECHO")) | (SETVAR "CMDECHO" 0) | (setvar "lispinit" 0) | (setq sheetno (getstring "\nsheet number (if allready converted then delete old files) ?: ")) | (setq dname (getvar "dwgname")) | (setq dname1 (substr dname 1 (- (strlen dname) 4))) | (setq dpref (getvar "dwgprefix")) | (setq oldname (strcat dpref dname1)) | (setq fname (strcat "C:/My Documents/PLOTFILES/" dname1 "-sched-" sheetno)) | (setq pt1 (getpoint "\npick left hand corner of sheet?: ")) | (setq ss1 (ssget)) | (command "sdi" "1") | (command "-wblock" fname "" pt1 ss1 "") | (command "undo" "1") | (command "qsave") | (command "fileopen" fname) | (command "plot" "y" "" "pdf995" "a4" "m" "p" "n" "e" "f" "0,0" "y" "a3.ctb" "y" "n" "n" "n" "y" "") | (command "fileopen" "y" oldname) | (setvar "lispinit" 1) | (command "sdi" "0") | (SETVAR "CMDECHO" ECHO) | (princ) | ) | | Many thanks | | | Spencer
Message 5 of 9
Anonymous
in reply to: Anonymous

This should get you closer..

(Defun c:ext (/ nsheet dname dname1 dpref oldname fname pt1 ss1 echo chk_pdf chk_dwg)
(defun myerror (sxx)
(if (= sxx nil)
(setq sxx "console break")
); end if
(if (not (member sxx '("console break" "Function cancelled")))
(princ (strcat "\nError: " sxx))
); end if
(if (= (member sxx '("console break" "Function cancelled")))
(progn
(prompt "\nError: Break...")
(setvar "MENUECHO" 0)
(setvar "HIGHLIGHT" 1)
(setvar "SORTENTS" 1)
(setvar "ATTDIA" 0); No Attribute Dialog Boxes, please
(setvar "ATTREQ" 1); Attributes Required
(setvar "OSMODE" 0); No OSNAP modes
(setvar "CMDDIA" 1); Plot command dialog on
); end progn
); end if
(setvar "CMDECHO" 0)
(setq sxx nil)
(princ)
); end function err
(setq olderr *error* *error* myerror)
;;
(setq ECHO (GETVAR "CMDECHO"))
(SETVAR "CMDECHO" 0)
(setvar "lispinit" 0)
(setq sheetno (getstring "\nsheet number (if allready converted then delete old files) ?: "))
(setq dname (getvar "dwgname"))
(setq dname1 (substr dname 1 (- (strlen dname) 4)))
(setq dpref (getvar "dwgprefix"))
(setq oldname (strcat dpref dname1))
(setq fname (strcat "C:/My Documents/PLOTFILES/" dname1 "-sched-" sheetno))
(setq pt1 (getpoint "\npick left hand corner of sheet?: "))
(setq ss1 (ssget))
(command "sdi" "1")
;;
;; Check for drawing block existance.
;;
(setq chk_dwg (strcat fname ".dwg"))
(if (findfile chk_dwg)
(dos_delete chk_dwg)
); end if
;;
(command "-wblock" fname "" pt1 ss1 "")
(command "undo" "1")
(command "qsave")
(command "fileopen" fname)
;;
;; Check if .pdf exists..
;;
(setq chk_pdf (strcat fname ".pdf"))
(if (findfile chk_pdf)
(dos_delete chk_pdf)
); end if
;;
(command "plot" "y" "" "pdf995" "a4" "m" "p" "n" "e" "f" "0,0" "y" "a3.ctb" "y" "n" "n" "n" "y" "")
(command "fileopen" "y" oldname)
(setvar "lispinit" 1)
(command "sdi" "0")
(SETVAR "CMDECHO" ECHO)
(princ)
)

Bob
Message 6 of 9
Anonymous
in reply to: Anonymous

Thank you for your responses.

I did not have doslib loaded and so I couldn't get the thing to work,

I have it now..

Spencer
Message 7 of 9
petervose
in reply to: Anonymous

Instead of usind (dos_delete... , why not try (vl-file-delete..... ?
Message 8 of 9
Anonymous
in reply to: Anonymous

what is the code for using this?
Message 9 of 9
Anonymous
in reply to: Anonymous

Using (vl-file-delete..

(Defun c:ext (/ nsheet dname dname1 dpref oldname fname pt1 ss1 echo chk_pdf chk_dwg)
(vl-load-com); Load VL common functions..
(defun myerror (sxx)
(if (= sxx nil)
(setq sxx "console break")
); end if
(if (not (member sxx '("console break" "Function cancelled")))
(princ (strcat "\nError: " sxx))
); end if
(if (= (member sxx '("console break" "Function cancelled")))
(progn
(prompt "\nError: Break...")
(setvar "MENUECHO" 0)
(setvar "HIGHLIGHT" 1)
(setvar "SORTENTS" 1)
(setvar "ATTDIA" 0); No Attribute Dialog Boxes, please
(setvar "ATTREQ" 1); Attributes Required
(setvar "OSMODE" 0); No OSNAP modes
(setvar "CMDDIA" 1); Plot command dialog on
); end progn
); end if
(setvar "CMDECHO" 0)
(setq sxx nil)
(princ)
); end function err
(setq olderr *error* *error* myerror)
;;
(setq ECHO (GETVAR "CMDECHO"))
(SETVAR "CMDECHO" 0)
(setvar "lispinit" 0)
(setq sheetno (getstring "\nsheet number (if allready converted then delete old files) ?: "))
(setq dname (getvar "dwgname"))
(setq dname1 (substr dname 1 (- (strlen dname) 4)))
(setq dpref (getvar "dwgprefix"))
(setq oldname (strcat dpref dname1))
(setq fname (strcat "C:/My Documents/PLOTFILES/" dname1 "-sched-" sheetno))
(setq pt1 (getpoint "\npick left hand corner of sheet?: "))
(setq ss1 (ssget))
(command "sdi" "1")
;;
;; Check for drawing block existance.
;;
(setq chk_dwg (strcat fname ".dwg"))
(if (findfile chk_dwg)
(vl-file-delete chk_dwg)
); end if
;;
(command "-wblock" fname "" pt1 ss1 "")
(command "undo" "1")
(command "qsave")
(command "fileopen" fname)
;;
;; Check if .pdf exists..
;;
(setq chk_pdf (strcat fname ".pdf"))
(if (findfile chk_pdf)
(vl-file-delete chk_pdf)
); end if
;;
(command "plot" "y" "" "pdf995" "a4" "m" "p" "n" "e" "f" "0,0" "y" "a3.ctb" "y" "n" "n" "n" "y" "")
(command "fileopen" "y" oldname)
(setvar "lispinit" 1)
(command "sdi" "0")
(SETVAR "CMDECHO" ECHO)
(princ)
)

Bob

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

Post to forums  

Autodesk Design & Make Report

”Boost