Jump to content

Plotting with serial file name (pdf)


nura235

Recommended Posts

I use to do batch plot with the below lisp and looking here for help.

 

(defun c:Testprint ( /)
   (setq cm (getvar 'CMDECHO))
   (setvar 'CMDECHO 0)
   (setq fd (getvar 'filedia))
   (setvar 'filedia 0)
   
   (setq pdfname(strcat (getvar 'DWGPREFIX)(vl-filename-base (getvar 'DWGNAME))))

       (command "-plot" "Y" "model" "DWG To PDF.pc3" "ISO A4 (210.00 x 297.00 MM)" "Millimeters" "Landscape" "Y" "Window" pause pause "Fit" "0.00, 0.00" "Y" "monochrome.ctb" "Y" "Wireframe" pdfname "N" "Y")
        
   (setvar 'CMDECHO cm)
   (setvar 'filedia fd)
   
        
) 

The above code print pdf file name same as the dwg name from model space.

 

I am looking for pdf file names such as

DWG_FILENAME-1.pdf,

DWG_FILENAME-2.pdf

and so on instead of DWG_FILENAME.pdf

Link to comment
Share on other sites

Try this, otherwise you need to save a global variable and check if it exists and add 1 to it, this is only valid for current session value will go when you close the dwg but this is probably ok as you know what sheet num to plot

 

(if (= sheetnum nil)(setq sheetnum 1)(setq sheetnum (+ sheetnum 1)))

(setq sheetnum (Getint "\nEnter sheet number"))
(setq pdfname(strcat (getvar 'DWGPREFIX)(vl-filename-base (getvar 'DWGNAME)) "-" sheetnum))

Link to comment
Share on other sites

Hi Bigal,

 

I am getting the error by using your code

(_> )
C:TESTPRINT
Command: TESTPRINT
Enter sheet number:1
; error: bad argument type: stringp 1

(defun c:Testprint ( /)
   (setq cm (getvar 'CMDECHO))
   (setvar 'CMDECHO 0)
   (setq fd (getvar 'filedia))
   (setvar 'filedia 0)
   (if (= sheetnum nil)(setq sheetnum 1)(setq sheetnum (+ sheetnum 1)))
   
   (setq sheetnum (Getint "\nEnter sheet number:"))
(setq pdfname(strcat (getvar 'DWGPREFIX)(vl-filename-base (getvar 'DWGNAME)) "-" sheetnum))
       (command "-plot" "Y" "model" "DWG To PDF.pc3" "ISO A4 (210.00 x 297.00 MM)" "Millimeters" "Landscape" "Y" "Window" pause pause "Fit" "0.00, 0.00" "Y" 

"monochrome.ctb" "Y" "Wireframe" pdfname "N" "Y")
        
   (setvar 'CMDECHO cm)
   (setvar 'filedia fd)
   
        
)

Also can you hard code the page number starting from 1, so user do not have to input page number every time. and it will start from page number 1 and go on order until the command get cancelled by user.

 

Try this, otherwise you need to save a global variable and check if it exists and add 1 to it, this is only valid for current session value will go when you close the dwg but this is probably ok as you know what sheet num to plot

 

(if (= sheetnum nil)(setq sheetnum 1)(setq sheetnum (+ sheetnum 1)))

(setq sheetnum (Getint "\nEnter sheet number"))
(setq pdfname(strcat (getvar 'DWGPREFIX)(vl-filename-base (getvar 'DWGNAME)) "-" sheetnum))

Link to comment
Share on other sites

Something like this perhaps.

(defun c:Testprint (/ CM FD P1 P2 PDFNAME)
 (setq cm (getvar 'CMDECHO))
 (setvar 'CMDECHO 0)
 (setq fd (getvar 'filedia))
 (setvar 'filedia 0)
 (if (= sheetnum nil)
   (setq sheetnum 1)
   (setq sheetnum (+ sheetnum 1))
 )
 (while (and (setq p1 (getpoint "\nSpecify first corner <exit> : "))
         (setq p2 (getcorner p1 "\nSpecify opposite corner <exit> : "))
    )
   (progn
     (setq pdfname (strcat (getvar 'DWGPREFIX)
               (vl-filename-base (getvar 'DWGNAME))
               "-"
               (itoa sheetnum)
           )
     )
     (command "-plot"           "Y"           "model"
          "DWG To PDF.pc3"               "ISO A4 (210.00 x 297.00 MM)"
          "Millimeters"   "Landscape"     "Y"
          "Window"           p1           p2
          "Fit"           "0.00, 0.00"    "Y"
          "monochrome.ctb"               "Y"
          "Wireframe"     pdfname           "N"
          "Y"
         )
     (setq sheetnum (+ sheetnum 1))
   )
 )
 (setvar 'CMDECHO cm)
 (setvar 'filedia fd)
 (princ)
)

HTH

Henrique

Link to comment
Share on other sites

Thanks Henrique for your effort.

 

The code provided by you plotting pdf file name in order, but when we cancel and restart again or plot after sometime after few modifications in drawing the command just start the plotting from it just end before.

 

For e.g. we plot 5 different pages from a file and it end at "file-name-5.pdf" and again when we start print those pages it start with "file-name-6.pdf".

 

I think at the end of the scipt the function must nil the sheetnum value. So may be it work.

 

 

Also I trying the fit this code in below code but was not able to. Can you do so, Thanks in Advance.

 

; Batch plot using object in landscape mode a4 sheet
(defun prl ( mnp mxp /)
   (setq cm (getvar 'CMDECHO))
   (setvar 'CMDECHO 0)
   (setq fd (getvar 'filedia))
   (setvar 'filedia 0)
   
   (setq pdfname(strcat (getvar 'DWGPREFIX)(vl-filename-base (getvar 'DWGNAME))))
       (command "-plot" "Y" "model" "DWG To PDF.pc3" "ISO A4 (210.00 x 297.00 MM)" "Millimeters" "Landscape" "Y" "Window" mnp mxp "Fit"
    "0.00, 0.00" "Y" "monochrome.ctb" "Y" "Wireframe" pdfname "N" "Y")
        
   (setvar 'CMDECHO cm)
   (setvar 'filedia fd)
   
        
)

; Batch plot using object in portrait mode a4 sheet
(defun prp ( mnp mxp /)
   (setq cm (getvar 'CMDECHO))
   (setvar 'CMDECHO 0)
   (setq fd (getvar 'filedia))
   (setvar 'filedia 0)
   
   (setq pdfname(strcat (getvar 'DWGPREFIX)(vl-filename-base (getvar 'DWGNAME))))
       (command "-plot" "Y" "model" "DWG To PDF.pc3" "ISO A4 (210.00 x 297.00 MM)" "Millimeters" "Portrait" "N" "Window" mnp mxp "Fit"
    "0.00, 0.00" "Y" "monochrome.ctb" "Y" "Wireframe" pdfname "N" "Y")
        
   (setvar 'CMDECHO cm)
   (setvar 'filedia fd)
   
        
) 
(defun c:pblock (/ ob ss bn mn mx)
     (vl-load-com)
           (if (and (progn
                (initget "B")
          (setq ob (entsel "\nSelect rectangular Block/B for blockname: "))
               (cond 
               ((eq ob "B")
                   (setq bn (getstring "\nEnter rectangular block name: "))
                   )
               ((and (eq (type ob) 'LIST)
              (vlax-method-applicable-p (vlax-ename->vla-object (car ob)) 'getboundingbox))
                     (setq bn (cdr (assoc 2 (entget (car ob))))))))
 (tblsearch "BLOCK" bn)
               bn     
               (setq ss  (ssget "_X" (list '(0 . "INSERT")'(410 . "Model")(cons 2 bn))))
                     )
                   
               
(progn 
         (vla-zoomextents (vlax-get-acad-object))
       (repeat (setq i (sslength ss))
  (vla-getboundingbox (vlax-ename->vla-object (ssname ss (setq i (1- i)))) 'mn'mx)


  (setq mnp (trans (vlax-safearray->list mn) 0 1))
     (setq mxp (trans (vlax-safearray->list mx) 0 1))
     (if (< (car (mapcar '- mxp mnp)) (cadr (mapcar '- mxp mnp)))
       (prp mnp mxp)
       (prl mnp mxp)
     )
                )
         )
         (princ "\nNo Blocks Selected: ")
         )(princ)
     )

Something like this perhaps.

(defun c:Testprint (/ CM FD P1 P2 PDFNAME)
 (setq cm (getvar 'CMDECHO))
 (setvar 'CMDECHO 0)
 (setq fd (getvar 'filedia))
 (setvar 'filedia 0)
 (if (= sheetnum nil)
   (setq sheetnum 1)
   (setq sheetnum (+ sheetnum 1))
 )
 (while (and (setq p1 (getpoint "\nSpecify first corner <exit> : "))
         (setq p2 (getcorner p1 "\nSpecify opposite corner <exit> : "))
    )
   (progn
     (setq pdfname (strcat (getvar 'DWGPREFIX)
               (vl-filename-base (getvar 'DWGNAME))
               "-"
               (itoa sheetnum)
           )
     )
     (command "-plot"           "Y"           "model"
          "DWG To PDF.pc3"               "ISO A4 (210.00 x 297.00 MM)"
          "Millimeters"   "Landscape"     "Y"
          "Window"           p1           p2
          "Fit"           "0.00, 0.00"    "Y"
          "monochrome.ctb"               "Y"
          "Wireframe"     pdfname           "N"
          "Y"
         )
     (setq sheetnum (+ sheetnum 1))
   )
 )
 (setvar 'CMDECHO cm)
 (setvar 'filedia fd)
 (princ)
)

HTH

Henrique

Link to comment
Share on other sites

Hi nura235,

something like this?

; Batch plot using object in landscape mode a4 sheet
(defun prl ( mnp mxp name /)
   (setq cm (getvar 'CMDECHO))
   (setvar 'CMDECHO 0)
   (setq fd (getvar 'filedia))
   (setvar 'filedia 0)
   
   (setq pdfname (strcat (getvar 'DWGPREFIX) (vl-filename-base (getvar 'DWGNAME)) "-" (itoa *name-#*)))
       (command "-plot" "Y" "model" "DWG To PDF.pc3" "ISO A4 (210.00 x 297.00 MM)" "Millimeters" "Landscape" "Y" "Window" mnp mxp "Fit"
    "0.00, 0.00" "Y" "monochrome.ctb" "Y" "Wireframe" pdfname "N" "Y")
        
   (setvar 'CMDECHO cm)
   (setvar 'filedia fd)       
)

; Batch plot using object in portrait mode a4 sheet
(defun prp ( mnp mxp name /)
   (setq cm (getvar 'CMDECHO))
   (setvar 'CMDECHO 0)
   (setq fd (getvar 'filedia))
   (setvar 'filedia 0)
   
   (setq pdfname (strcat (getvar 'DWGPREFIX) (vl-filename-base (getvar 'DWGNAME)) "-" (itoa *name-#*)))
       (command "-plot" "Y" "model" "DWG To PDF.pc3" "ISO A4 (210.00 x 297.00 MM)" "Millimeters" "Portrait" "N" "Window" mnp mxp "Fit"
    "0.00, 0.00" "Y" "monochrome.ctb" "Y" "Wireframe" pdfname "N" "Y")
        
   (setvar 'CMDECHO cm)
   (setvar 'filedia fd)       
)

(defun c:pblock (/ ob ss bn mn mx tmpN)
     (vl-load-com)
           (if (and (progn
                (initget "B")
          (setq ob (entsel "\nSelect rectangular Block/B for blockname: "))
               (cond 
               ((eq ob "B")
                   (setq bn (getstring "\nEnter rectangular block name: "))
                   )
               ((and (eq (type ob) 'LIST)
	      (vlax-method-applicable-p (vlax-ename->vla-object (car ob)) 'getboundingbox))
                     (setq bn (cdr (assoc 2 (entget (car ob))))))))
	     (tblsearch "BLOCK" bn)
	     bn
	     (setq ss  (ssget "_X" (list '(0 . "INSERT")'(410 . "Model")(cons 2 bn))))
                     )

      (progn
	  (if (or (not *name-#*) (/= (type *name-#*) 'INT)) (setq *name-#* 1))
	(initget 6)
	(setq tmpN (getint (strcat "\nEnter sheet number <" (itoa *name-#*)" >: ")))
	(if (/= tmpN nil) (setq *name-#* tmpN))
	
	(vla-zoomextents (vlax-get-acad-object))
	(repeat (setq i (sslength ss))
	  (vla-getboundingbox (vlax-ename->vla-object (ssname ss (setq i (1- i)))) 'mn'mx)
	  (setq mnp (trans (vlax-safearray->list mn) 0 1))
	  (setq mxp (trans (vlax-safearray->list mx) 0 1))
	  (if (< (car (mapcar '- mxp mnp)) (cadr (mapcar '- mxp mnp)))
	    (prp mnp mxp *name-#*)
	    (prl mnp mxp *name-#*)
	    )
	  (setq *name-#* (1+ *name-#*))
	  )
	)
      (princ "\nNo Blocks Selected: ")
      )
 (princ)
 )

 

HTH

Henrique

Link to comment
Share on other sites

Here is a another example plot all title blocks in model space by auto find the title "Block" one of the extra things you can do is pull the sheet number out of the title block and add that to your file name. Will need a title block dwg or block name and attribute Tag name to change code. A later version of plot all I added plot by range like plot page 4-7 this could be added also this is posted here will find but it does layouts but same method.

 

 (PROMPT ".....PRINTING DRAWING TO plotter....")
(setq oldsnap (getvar "osmode"))
(setvar "osmode" 0)

(setq ss2 (ssget "x" '((0 . "INSERT")(2 . "your title block name here")(410 . "Model")))) 
(setq n (sslength ss2))

(setq index 0)
(repeat n
   (setq en (ssname ss2 index))
   (setq el (entget en))
   (setq inspt (assoc 10 el)) ; insertion pt

  (setq xmin (- (cadr inspt) 6.0))
  (setq ymin (- (caddr inspt) 6.0))
  (setq xymin (strcat (rtos xmin 2 1) "," (rtos ymin 2 1)))

  (setq xmax (+ xmin 813.0)) ; hard coded for 813 wide 6mm offset
  (setq ymax (+ ymin 566.0)) ;hard code for 566 high
  (setq xymax (strcat (rtos xmax 2 1) "," (rtos ymax 2 1)))


 (COMMAND "-PLOT"  "Y"     "" "DWG To PDF.pc3"
       "A3"	"M"     "LANDSCAPE"   "N"
       "W"	  xymin   xymax "1=2"  "C"
       "y"	  "Designlaser.ctb"      "Y"   ""	"n"   "n"
       "y"	
   )
  
 (setq index (+ index 1))

)

(setvar "osmode" oldsnap)
(princ)

Link to comment
Share on other sites

@ hmsilva: Thanks for your time and effort, your code work for me as I desire.

 

@ Bigal: Thanks to you and the cadtutor forum who help us people who do not have vlisp knowledge.

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