Jump to content

Recommended Posts

Posted

Hello i have a lisp that greates a copy of a dwg. with filename+date en place it in a sub dir History.

 

 

(defun c:sav ( / cpy sub )
   (setq sub "History") ;; Subdirectory
   (cond
       (   (zerop (getvar 'dwgtitled))
           (princ "\nCurrent drawing is unsaved.")
       )
       (   (not (or (findfile (setq sub (strcat (getvar 'dwgprefix) sub))) (vl-mkdir sub)))
           (princ (strcat "\nUnable to create directory " sub))
       )
       (   (progn
               (princ "\nSaving current drawing...")
               (command "_.qsave")
               (not 
                   (vl-file-copy (strcat (getvar 'dwgprefix) (getvar 'dwgname))
                       (setq cpy 
                           (strcat sub "\\"
                               (vl-filename-base (getvar 'dwgname)) "-"
                               (menucmd "m=$(edtime,0,DDMOYYYY)") 
                               (vl-filename-extension (getvar 'dwgname))
                           )
                       )
                   )
               )
           )
           (princ (strcat "\nUnable to copy drawing to " cpy))
       )
       (   (princ (strcat "\nDrawing copied to " cpy)))
   )
   (princ)
)

 

 

And i want to have lisp like previous which plot a pdf with filename+date and place this in the sub map PDF.

 

 

I've tried something, but of course it does not work.

 

 

(defun c:P2P-D ( / cpy sub )
   (setq sub "PDF") ;; Subdirectory
   (cond
       (   (zerop (getvar 'dwgtitled))
           (princ "\nCurrent drawing is unsaved.")
       )
       (   (not (or (findfile (setq sub (strcat (getvar 'dwgprefix) sub))) (vl-mkdir sub)))
           (princ (strcat "\nUnable to create directory " sub))
       )
       (   (progn
               (princ "\nPlot current drawing...")
               (command "-PLOT" "" "" "" "" "" "" "" "" )
               (not 
                   (vl-file-copy (strcat (getvar 'dwgprefix) (getvar 'dwgname))
                       (setq cpy 
                           (strcat sub "\\"
                               (vl-filename-base (getvar 'dwgname)) "-"
                               (menucmd "m=$(edtime,0,DDMOYYYY)") 
                               (vl-filename-extension (getvar 'dwgname))
                           )
                       )
                   )
               )
           )
           (princ (strcat "\nUnable to copy drawing to " cpy))
       )
       (   (princ (strcat "\nDrawing copied to " cpy)))
   )
   (princ)
)

 

 

What am I doing wrong? could someone help me?

 

 

thank you in advance,

PMXcad

Posted

Have a look at this allows the user to pick a text or bock id as part of the pdf out put and saves in a specific directory, you just need to add the date.

 

; plot basins as pdf to k:drive
; plotpdf2 ver 2 with filename and directory as output oct 2011
; Alan H 2016
(PROMPT ".....PRINTING DRAWING TO pdf's....")
(DEFUN PLOTBASIN ( / IDRB DWGNAME LEN NAME PLOTTABLIST obj objtype)
(setvar "cmddia" 0)
(setvar "filedia" 0)
(setq plotabs nil) ; in case run before
;(setq obj (vlax-ename->vla-object (CAR (ENTSEL "\nPick id name"))))
(setq obj (vlax-ename->vla-object (ssname (ssget '(264 16)) 0)))
(setq objtype (vla-get-objectname obj))
(if (= objtype "AcDbBlockReference")
(progn
(foreach att (vlax-invoke obj 'getattributes)
(if (= "ID" (strcase (vla-get-tagstring att)) )
(setq IDRB (vla-get-textstring att)) 
) ; if
) ; for
) ; progn
) ; if block
(if (= objtype "AcDbText")
(SETQ IDRB (VLA-GET-TEXTSTRING obj))
)
(if (or (= objtype "AcDbText")(= objtype "AcDbBlockReference"))
(Princ "correct object") 
(progn
(Alert "Incorrect object picked exiting now")
(exit)
)
)
(setq dwgname (STRCAT "O&M PLAN-" IDRB)) 
(vlax-for lay (vla-get-Layouts (vla-get-activedocument (vlax-get-acad-object)))
(setq layname (vla-get-name lay))  
; same as dwg
;(setq pdfname (strcat (getvar "dwgprefix") dwgname))
; K drive
(setq pdfname (strcat "k:\\mgmt\\Assets\\Drainage\\pdfs\\"   dwgname ))
(setvar "textfill" 1)
(if (/= "Model" layname)
(progn
(setvar "ctab" layname)
(command "pspace")
(COMMAND "-PLOT"  "Y"  "" "dwg to Pdf" "ISO full bleed A4 (210.00 x 297.00 MM)" "m" "LANDSCAPE"  "N"   "W"  
"-6,-6" "289,206" "1=1"  "C"
"y" "Designlasercolour.ctb" "Y" "n" "n" "n" pdfName "N" "y" )
) ; progn
) ; if
(setvar "cmddia" 1)
(setvar "filedia" 1)
(princ)
) ; Vlax-for 
) ; defun

(PLOTBASIN)

Posted

Okay, thanks bigal.

I will try it tomorrow.

 

PMXcad

Posted

Well Bigal, I tried but did not succeed.

I do not know lisp, just scripting.

Could you help me further?

; plot basins as pdf to k:drive
; plotpdf2 ver 2 with filename and directory as output oct 2011
; Alan H 2016
(PROMPT ".....PRINTING DRAWING TO pdf's....")
(DEFUN PLOTBASIN ( / IDRB DWGNAME LEN NAME PLOTTABLIST obj objtype)
(setvar "cmddia" 0)
(setvar "filedia" 0)
(setq plotabs nil) ; in case run before
;(setq obj (vlax-ename->vla-object (CAR (ENTSEL "\nPick id name"))))
(setq obj (vlax-ename->vla-object (ssname (ssget '(264 16)) 0)))
(setq objtype (vla-get-objectname obj))
(if (= objtype "AcDbBlockReference")
(progn
(foreach att (vlax-invoke obj 'getattributes)
(if (= "ID" (strcase (vla-get-tagstring att)) )
(setq IDRB (vla-get-textstring att)) 
) ; if
) ; for
) ; progn
) ; if block
(if (= objtype "AcDbText")
(SETQ IDRB (VLA-GET-TEXTSTRING obj))
)
(if (or (= objtype "AcDbText")(= objtype "AcDbBlockReference"))
(Princ "correct object") 
(progn
(Alert "Incorrect object picked exiting now")
(exit)
)
)
(setq dwgname (STRCAT "O&M PLAN-" IDRB)) 
(vlax-for lay (vla-get-Layouts (vla-get-activedocument (vlax-get-acad-object)))
(setq layname (vla-get-name lay))  
; same as dwg
;(setq pdfname (strcat (getvar "dwgprefix") dwgname))
; K drive
(setq pdfname (strcat "E:\\CAD\\DWG\\PDF\\"   dwgname ))
(setvar "textfill" 1)
(if (/= "Model" layname)
(progn
(setvar "ctab" layname)
(command "pspace")
(COMMAND "-PLOT"  "Y"  "" "" "" "" ""  ""   ""  
"- "" ""  ""
"" "" "" "" "" "" pdfName "" "" )
) ; progn
) ; if
(setvar "cmddia" 1)
(setvar "filedia" 1)
(princ)
) ; Vlax-for 
) ; defun

(PLOTBASIN)

 

 

(defun c:plt2pdf ( / cpy sub )
   (setq sub "PDF") ;; Subdirectory
   (cond
       (   (zerop (getvar 'dwgtitled))
           (princ "\nCurrent drawing is unsaved.")
       )
       (   (not (or (findfile (setq sub (strcat (getvar 'dwgprefix) sub))) (vl-mkdir sub)))
           (princ (strcat "\nUnable to create directory " sub))
       )
       (   (progn
               (princ "\PLot 2 PDF...")
(command "pspace")
(COMMAND "-PLOT"  "Y"  "" "dwg to Pdf" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" cpy "" "" )
                               (not 
                   (vl-file-copy (strcat (getvar 'dwgprefix) (getvar 'dwgname))
                       (setq cpy 
                           (strcat sub "\\"
                               (vl-filename-base (getvar 'dwgname)) "-"
                               (menucmd "m=$(edtime,0,DDMOYYYY)") 
                               (vl-filename-extension (getvar 'dwgname))
                           )
                       )
                   )
               )
           )
           (princ (strcat "\nUnable to plot PDF to " cpy))
       )
       (   (princ (strcat "\nDrawing plot to " cpy)))
   )
   (princ)
)

 

they only saves the dwgname+date to the sub dir.

 

 

thanks in advance

PXcad

Posted

This seems to be two questions make a archive copy of the drawing and make a pdf saving it to a sub directory PDf of wher the drawing lives. You need the two possibly to be seperate amybe do the pdf 1st then the copy. Also look at my code for Plot lots more questions answered to ensure plot is correct every time rather than accepting the deaults "". In the code above I plot all layouts rather than 1.

 

The plain plot pdf to same directory as dwg as an example.

 

 ; plotpdf2 ver 2 with filename and directory as output oct 2011
(PROMPT ".....PRINTING DRAWING TO pdf's....")
(setvar "cmddia" 0)
(setvar "filedia" 0)
(setq plotabs nil) ; in case run before
(setq doc (vla-get-activedocument (vlax-get-acad-object)))
(vlax-for lay (vla-get-Layouts doc)
 (setq plotabs (cons (vla-get-name lay) plotabs))
)
(setq dwgname (GETVAR "dwgname"))
(setq len (strlen dwgname))
(setq dwgname (substr dwgname 1 (- len 4)))
(setq plottablist (acad_strlsort plotabs))
(setq len (length plottablist))
(setq x 0)
(repeat len
 (setq name (nth x plottablist))
 (princ name)
 (setq pdfname (strcat (getvar "dwgprefix") dwgname "-" name))
 (if (/= name "Model")
   (progn
   (setvar "ctab" name)
   (setvar "textfill" 1)
    (COMMAND "-PLOT"  "Y"  "" "dwg to Pdf"
       "Iso full bleed A3 (420.00 x 297.00 MM)" "m" "LANDSCAPE"  "N"   "W"  "-6,-6" "807,560" "1=2"  "C"
       "y" "Designlasercolour.ctb" "Y" "n" "n" "n" pdfName "N" "y"      )
   )
 )
 (setq x (+ x 1))
)
(setvar "cmddia" 1)
(setvar "filedia" 1)
(setq DWGNAME nil
     LEN nil
     NAME nil
     PLOTTABLIST nil) 
(princ)

Posted

Bigal Ok, I got it working. I made a script and it works. And I have a lisp that moves the PDF to sub folder PDF.

How can I combine these two so it plots the PDF en put it direct in the PDF folder?

 

SCRIPT:

(setq CurrDwgName (getvar "dwgname"))
(setq laytab (getvar "ctab"))
(setq Fname (substr CurrDwgName 1 (- (strlen CurrDwgName) 4)))
(setq name (strcat (getvar "DWGPREFIX") Fname "-" laytab "-" (menucmd "M=$(edtime,$(getvar,date),DDMOYYYY)")))
-plot




!name


 

LISP:

(defun c:pdf2sub ( / dir lst sub )
   (if
       (and
           (setq dir (vl-string-right-trim "\\" (vl-string-translate "/" "\\" (getvar 'dwgprefix)))
                 sub (strcat dir "\\pdf")
                 lst (vl-directory-files dir "*.pdf" 1)
           )
           (or (vl-file-directory-p sub)
               (vl-mkdir sub)
           )
       )
       (prompt
           (strcat "\n"
               (itoa
                   (length
                       (vl-remove nil
                           (mapcar
                              '(lambda ( pdf / new )
                                   (if (findfile (setq new (strcat sub "\\" pdf)))
                                       (vl-file-delete new)
                                   )
                                   (vl-file-rename (strcat dir "\\" pdf) new)
                               )
                               lst
                           )
                       )
                   )
               )
               " of "
               (itoa (length lst))
               " bak file(s) moved to " sub
           )
       )
       (prompt "\nNo pdf files found in working directory.")
   )
   (princ)
)

 

thanks in advance

PXcad

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...