Modifying GetPoint Variable value in a loop

Modifying GetPoint Variable value in a loop

parutter
Contributor Contributor
965 Views
11 Replies
Message 1 of 12

Modifying GetPoint Variable value in a loop

parutter
Contributor
Contributor

I write AutoLisp scripts poorly at best, but I have created a function called csplot (cut sheet plot) that allows me to make multiple PDFs from 1 Paper Space Tab. I designate the number of sheets, click the bottom left corner of the 8.5x11 borders and send the specified number of PDFs to a specific location where I combine them into 1 PDF.

I know using individual tabs would solve the problem through Plot/Publish, but it isn't practical because of the volume of these individual sheets we make (it's hundreds throughout the project).

 

I Always space my sheets the same in these viewports, and I realized that if I know how many sheets I'm making, I can automate the window selection process for the plots based on the first border I click. How do I modify the location of a variable with the Getpoint info?

 

I attempted googling the answer, but I'm not familiar enough with the AutoLisp Terms to find what I'm looking for. 

 

Below is the function as it is. I intend on starting the loop after the getpoint, but I felt context would be helpful.

 

 

;CSPLOT.lsp

(
defun C:csplot ()
(command "FILEDIA")
(command "0")
(setq a 1)
(setq times (getint "\nEnter Number of Sheets: "))
(while (<= a times)
(setq startpoint (getpoint "Click on bottom left corner of 8.5 x 11 border"))
(setq str2 (itoa a))
(setq str (strcat "C:\\CSPLOT\\" str2 ".pdf"))
(command "-PLOT")
(command "YES")
(command " ")
(command "DWG TO PDF.PC3")
(command "LETTER")
(command "inches")
(command "PORTRAIT")
(command "NO")
(command "WINDOW")
(command startpoint)
(command "@8,10.2")
(command "1:1")
(command "CENTER")
(command "yes")
(command "W2K_LJ5")
(command "YES")
(command "YES")
(command "NO")
(command "NO")
(command str)
(command "N")
(command "Y")
(princ)
(princ)
(setq a (1+ a))
(princ)
(princ)
)
(command "FILEDIA")
(command "1")
)

 

 

0 Likes
Accepted solutions (1)
966 Views
11 Replies
Replies (11)
Message 2 of 12

paullimapa
Mentor
Mentor

If the 8.5x11 borders are actually blocks then you can use the lisp code here to generate your plots of all the title blocks in the current layout 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 3 of 12

ronjonp
Advisor
Advisor

If you have a common titleblock, you could use the bounding box property to automate this more.

0 Likes
Message 4 of 12

parutter
Contributor
Contributor

I was trying to read through the code but without running it, I wasn't able to identify where it was selecting objects.  My sheets are identical block names, where is the object selection in this code?

0 Likes
Message 5 of 12

ronjonp
Advisor
Advisor

@parutter wrote:

I was trying to read through the code but without running it, I wasn't able to identify where it was selecting objects.  My sheets are identical block names, where is the object selection in this code?


No object selection in that code. Post a sample drawing of what you're trying to plot.

0 Likes
Message 6 of 12

parutter
Contributor
Contributor

I appreciate any help.  Please see the attached. It is a stripped down version of our file, most of the information is gone but the viewports / borders are in the CS-Drain Tab

0 Likes
Message 7 of 12

ronjonp
Advisor
Advisor

We don't even need to use the bounding box, we can just ad the width and the height to the basepoint since it's in the lower left corner. 

 

See if you can add your plot parameters to this snippet:

 

 

(defun c:foo (/ fn n p1 p2 s)
  (cond	((setq s (ssget '((0 . "INSERT") (2 . "8X11SS-newlogo"))))
	 (setq n 0)
	 (setq fn (strcat (getvar 'dwgprefix) (getvar 'ctab)))
	 (foreach e (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
	   (setq p1 (cdr (assoc 10 (entget e))))
	   (setq p2 (mapcar '+ p1 '(8 10.2 0)))
	   (grdraw p1 p2 1)
	   ;; You'll need to modify this for your plot settings ( I took a first stab )
	   (command "-plot"
		    "yes"
		    (getvar 'ctab)
		    "DWG TO PDF.PC3"
		    "Letter"
		    "Inches"
		    "Portrait"
		    "No"
		    "Window"
		    p1
		    p2
		    "1:1"
		    "Center"
		    "Yes"
		    "W2K_LJ5.ctb"
		    "Yes"
		    "Yes"
		    "No"
		    "No"
		    (strcat fn "-" (itoa (setq n (1+ n))) ".pdf")
		    "No"
		    "Yes"
	   )
	 )
	)
  )
  (princ)
)

 

 

 

0 Likes
Message 8 of 12

paullimapa
Mentor
Mentor

The code below is modified from the post I had given you earlier.

This also sorts the title blocks to plot from left to right first and then bottom to top

; csplot plots area within all blocks: 8X11SS-newlogo in current layout
; modified from Henrique Moreira da Silva's code;
; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/batch-plot-to-pdf-in-model-space/m-p/6213711
(defun c:csplot (/ bas dwg file hnd i len llpt lst mn mx ss tab urpt)
(vl-load-com)
    (if (setq ss (ssget "_X" '((0 . "INSERT") (2 . "8X11SS-newlogo")))) ; automatically select all
;     (if (setq ss (ssget (list (cons 0 "INSERT") (cons 2 "8X11SS-newlogo")))) ; if want to manually select
        (progn
            (repeat (setq i (sslength ss))
                (setq hnd (ssname ss (setq i (1- i)))
                      tab (cdr (assoc 410 (entget hnd)))
                      bas (cdr (assoc 10 (entget hnd))) ; get insert base point
                )
                (if (equal tab (getvar"ctab")) ; if ttl blk is in current layout
                    (setq lst (cons (cons tab (cons bas hnd)) lst)) ; add to lst for plotting
                )
            )
            ; sort by blocks insert base point left to right and bottom to top
            ; https://www.cadtutor.net/forum/topic/71201-function-to-sort-a-list-of-points-first-x-then-y/
            (setq lst 
             (vl-sort lst 
             '(lambda (x y) 
               (if (= (car (cadr x)) (car(cadr y))) 
                (< (car (cadr x)) (car (cadr y)))
                (< (cadr (cadr x)) (cadr (cadr y))) 
               )
              )
             )
            )

            (setq i 0)
            (foreach x lst
                (setq file (strcat "C:\\CSPLOT\\"  ; (getvar 'DWGPREFIX)
                                   (substr (setq dwg (getvar 'DWGNAME)) 1 (- (strlen dwg) 4))
                                   "-"
                                   (itoa (setq i (1+ i)))
                                   ".pdf"
                           )
                )
                (if (findfile file)
                    (vl-file-delete file)
                )
;                (vla-getboundingbox (vlax-ename->vla-object (cddr x)) 'mn 'mx)
;                (setq llpt (vlax-safearray->list mn)
;                      urpt (vlax-safearray->list mx)
;                      len  (distance llpt (list (car urpt) (cadr llpt)))
;                )
                (setq llpt (cdr(assoc 10(entget (cddr x))))) 
                (setq urpt (list (+ 8.0 (car llpt)) (+ 10.25 (cadr llpt))))  ; use exact dimension for 8.5 x 11.0 ttl blk
                (command "-plot"
                         "yes"
                         (car x)
                         "DWG TO PDF.PC3"
                         "ANSI full bleed A (8.50 x 11.00 Inches)"
                         "inches"
                         "Portrait"
                         "No"
                         "Window"
                         llpt
                         urpt
                         "1:1"
                         "Center"
                         "yes"
                         "W2K_LJ5.ctb"
                         "yes"
                         ""
                )
                (if (/= (car x) "Model")
                    (command "No" "No" file "no" "Yes")
                    (command
                        file
                        "no"
                        "Yes"
                    )
                )
            )
        )
    )
    (princ)
) ; defun

Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 9 of 12

Sea-Haven
Mentor
Mentor

If you make a list of each pdf name as you go you can via lisp use Ghostscript to join all the pdfs back into 1 pdf. 

 

;MergePdfs
;Merges multiple pdf (or eps) files into one
;Requires the installation of Ghostscript 

; make a batch file ?
;gs -sDEVICE=pdfwrite \
;    -dNOPAUSE -dBATCH -dSAFER \
;    -sOutputFile=combined.pdf \
;    first.pdf \
;    second.pdf \
;    third.pdf [...]

;Ghostscript (http://www.ghostscript.com/) can be used to combine PDFs.

; Something like this should work: by Roy_043

(defun KGA_String_Join (strLst delim)
(if strLst
(apply
'strcat
(cons
(car strLst)
(mapcar '(lambda (a) (strcat delim a)) (cdr strLst))
)
)
""
)
)

; (CombinePdf 
;  (setq gsexe "C:\\Program Files\\gs\\gs9.19\\bin\\gswin64c.exe")
(setq gsexe "P:\\gs\\gs9.19\\bin\\gswin64c.exe")
; (setq srcFilelst  '("D:\\Tmp\\A.pdf" "D:\\Tmp\\B.pdf"))
; (setq trgfile "C:\\Acadtemp\\Total.pdf")
; )
; Note: Existing trgFile will be overwritten.
(defun CombinePdf (gsExe srcFileLst trgFile)
(startapp 
(strcat
gsExe " "
"-sDEVICE=pdfwrite -dBATCH -dNOPAUSE -dQUIET  "
"-sOutputFile=\"" trgFile "\" "
"\"" (KGA_String_Join srcFileLst "\" \"") "\""
)
)
)

0 Likes
Message 10 of 12

john.uhden
Mentor
Mentor
Accepted solution

@parutter 

You have named your (getpoint) variable as startpoint.

You just need to modify it with each increment of a.

Let's say all your sheets (titleblocks?) are in a row, and the distance between lower left corners is always 10.

Then each time after a plot (setq startpoint (polar startpoint 0.0 10)),

  like right after (setq a (1+ a))

John F. Uhden

0 Likes
Message 11 of 12

parutter
Contributor
Contributor

Thank you all so much for all of the help. I apologize for the considerable delay, but all of you have certainly helped expand my minimal knowledge of AutoLISP!

0 Likes
Message 12 of 12

parutter
Contributor
Contributor

This is some icing on the cake, for Sure!

0 Likes