Lisp to print PDF and name from block

Lisp to print PDF and name from block

karprokas
Explorer Explorer
1,542 Views
10 Replies
Message 1 of 11

Lisp to print PDF and name from block

karprokas
Explorer
Explorer

Hello everyone,

 

I am new at LISP but I found one that lets to print drawings straight from model area to pdf. I modified it a little bit and now it works perfectly, but I would like to change one thing. Right now when I am printing it creates name for PDF from DWG name and also put numbers at back. Is there any way it can create name from block attributes values. My current block "A1" its just that square with 3 attributes. How can i change that LISP can create PDF with name like A-B-C.pdf or something like that. Thanks in advance.

Untitled.png

 

 

(vl-load-com)
(defun c:SpA1 (/ dwg file hnd i len llpt lst mn mx ss tab urpt)
    (if (setq ss (ssget "_X" '((0 . "INSERT") (2 . "A1"))))
        (progn
            (repeat (setq i (sslength ss))
                (setq hnd (ssname ss (setq i (1- i)))
                      tab (cdr (assoc 410 (entget hnd)))
                      lst (cons (cons tab hnd) lst)
                )
            )
            (setq lst (vl-sort lst '(lambda (x y) (> (car x) (car y)))))
            (setq i 0)
            (foreach x lst
                (setq file (strcat (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 (cdr x)) 'mn 'mx)
                (setq llpt (vlax-safearray->list mn)
                      urpt (vlax-safearray->list mx)
                      len  (distance llpt (list (car urpt) (cadr llpt)))
                )
                (command "-plot"
                         "yes"
                         (car x)
                         "DWG TO PDF.PC3"
                         "A1"
                         "Millimeters"
                         "Landscape"
                         "No"
                         "Window"
                         llpt
                         urpt
                         "Fit"
                         "Center"
                         "yes"
                         "PSP.ctb"
                         "yes"
                         ""
                )
                (if (/= (car x) "Model")
                    (command "No" "No" file "no" "Yes")
                    (command
                        file
                        "no"
                        "Yes"
                    )
                )
            )
        )
    )
    (princ)
)

 

 

 

0 Likes
Accepted solutions (1)
1,543 Views
10 Replies
Replies (10)
Message 2 of 11

ВeekeeCZ
Consultant
Consultant

This this. Untested. 

 

(vl-load-com)
(defun c:SpA1 (/ dwg file hnd i len llpt lst mn mx ss tab urpt val)
  
  (if (setq ss (ssget "_X" '((0 . "INSERT") (2 . "A1"))))
    (progn
      (repeat (setq i (sslength ss))
	(setq hnd (ssname ss (setq i (1- i)))
	      tab (cdr (assoc 410 (entget hnd)))
	      lst (cons (cons tab hnd) lst)
	      )
	)
      (setq lst (vl-sort lst '(lambda (x y) (> (car x) (car y)))))
      (setq i 0)
      (foreach x lst
	(setq file (strcat
		     (cond ((not (vl-catch-all-error-p (setq val (vl-catch-all-apply 'getpropertyvalue (list hnd "1"))))) val) ("1"))
		     "-"
		     (cond ((not (vl-catch-all-error-p (setq val (vl-catch-all-apply 'getpropertyvalue (list hnd "2"))))) val) ("2"))
		     "-"
		     (cond ((not (vl-catch-all-error-p (setq val (vl-catch-all-apply 'getpropertyvalue (list hnd "3"))))) val) ("3"))
;;;		     (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 (cdr x)) 'mn 'mx)
	(setq llpt (vlax-safearray->list mn)
	      urpt (vlax-safearray->list mx)
	      len  (distance llpt (list (car urpt) (cadr llpt)))
	      )
	(command "-plot"
		 "yes"
		 (car x)
		 "DWG TO PDF.PC3"
		 "A1"
		 "Millimeters"
		 "Landscape"
		 "No"
		 "Window"
		 llpt
		 urpt
		 "Fit"
		 "Center"
		 "yes"
		 "PSP.ctb"
		 "yes"
		 ""
		 )
	(if (/= (car x) "Model")
	  (command "No" "No" file "no" "Yes")
	  (command
	    file
	    "no"
	    "Yes"
	    )
	  )
	)
      )
    )
  (princ)
  )
0 Likes
Message 3 of 11

maratovich
Advisor
Advisor

Maybe try this - Revers 
Any file name can be used

---------------------------------------------------------------------
Software development
Automatic creation layouts and viewport. Batch printing drawings from model.
www.kdmsoft.net
0 Likes
Message 4 of 11

karprokas
Explorer
Explorer

Hey @ВeekeeCZ,

 

It works but just for one drawing at a time. If I am trying to print more than one it prints last one but gives error for all the others. Maybe there is solution for that?

It looks like it takes different blocks but always give same name for all of them.

Untitled.png

0 Likes
Message 5 of 11

karprokas
Explorer
Explorer
I know this program but lisp is much more convenient and also I dont need to pay for it 😄
0 Likes
Message 6 of 11

hosneyalaa
Advisor
Advisor

For better help

Attached drawing example 

0 Likes
Message 7 of 11

karprokas
Explorer
Explorer

Hi, I attached drawing with created block and also LISP.

0 Likes
Message 8 of 11

ВeekeeCZ
Consultant
Consultant

Replacing hnd with x in added part should fix it.

0 Likes
Message 9 of 11

karprokas
Explorer
Explorer

I just tried it, but it still makes same name 😕

0 Likes
Message 10 of 11

ВeekeeCZ
Consultant
Consultant
Accepted solution

Oh... this 

(cdr x)

 

0 Likes
Message 11 of 11

karprokas
Explorer
Explorer

Now it works perfectly, thanks man!!!

0 Likes