Pdf creator

Discussion in 'AutoCAD' started by spencer1971, Jun 10, 2004.

  1. spencer1971

    spencer1971 Guest

    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
     
    spencer1971, Jun 10, 2004
    #1
  2. spencer1971

    T.Willey Guest

    Use "findfile".
    Code:
    (if (setq fname (strcat "C:/My Documents/PLOTFILES/" dname1 "-sched-" sheetno))
    (rename here)
    )
    
    Tim
     
    T.Willey, Jun 10, 2004
    #2
  3. spencer1971

    T.Willey Guest

    Hit the wrong button.

    Code:
    (if (findfile fname)
    (rename here)
    )
    
    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
     
    T.Willey, Jun 10, 2004
    #3
  4. spencer1971

    Matt W Guest

    (if (findfile fname....

    --
    Matt W

    There are 3 kinds of people:
    Those who can count, and those who can't.

    | 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
     
    Matt W, Jun 10, 2004
    #4
  5. spencer1971

    ECCAD Guest

    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
     
    ECCAD, Jun 10, 2004
    #5
  6. spencer1971

    spencer1971 Guest

    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
     
    spencer1971, Jun 11, 2004
    #6
  7. spencer1971

    petervose Guest

    Instead of usind (dos_delete... , why not try (vl-file-delete..... ?
     
    petervose, Jun 11, 2004
    #7
  8. spencer1971

    spencer1971 Guest

    what is the code for using this?
     
    spencer1971, Jun 11, 2004
    #8
  9. spencer1971

    ECCAD Guest

    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
     
    ECCAD, Jun 11, 2004
    #9
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.