LISP to Select Dynamic Blocks

LISP to Select Dynamic Blocks

3arizona
Advocate Advocate
1,108 Views
2 Replies
Message 1 of 3

LISP to Select Dynamic Blocks

3arizona
Advocate
Advocate

I picked up this lisp on the forum. can this plot lisp be modified to select a dynamic block or both?  I've tried and failed miserably.

 

(vl-load-com)
(defun c:unitPDF ( / *error* ss ed obj i box ll ur pt1 pt2 pdffile tag val)
  (defun *error* (errmsg)
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break"))
      (princ (strcat "\nError: " errmsg)))
;;;;; Do stuff then error, ESC,
(mapcar 'setvar VarList OldVars)
          (setvar "CMDECHO" 1)
(princ)
  );;;; end *error*
  ;;;;; Main routine
         (setvar "CMDECHO" 0)   
     (setq logname (getvar "loginname"))
(command "psetupin" "Details.dwg" "11x17 Landscape" "y")
(command "-PLOT" "n" "model" "11x17 Landscape" "Bluebeam BW.pc3" "N" "Y" "N")
   (setq ss (ssget (list '(0 . "INSERT")'(2 . "UNITS"))))
   (if ss
      (progn
         (setq i 0)
         (while (< i (sslength ss))
            (setq ent (ssname ss i)
                  obj (vlax-ename->vla-object ent)
                  box (vlax-invoke-method obj 'getboundingbox 'pt1 'pt2)
                  ll  (vlax-safearray->list pt1)
                  ur  (vlax-safearray->list pt2)
            )
            (while
               (and
                  (setq ent (entnext ent))
                  (= "ATTRIB" (cdr (assoc 0 (setq edata (entget ent)))))
               )
               (setq tag (cdr (assoc 2 edata)))
               (setq val (cdr (assoc 1 edata)))
               (cond
                  ((= tag "-DO-NOT-EDIT-")   (setq SHEET1 val))
               )
            )
            (setq pdffile

               (strcat
                  "C:/Documents and Settings/" (getvar 'loginname) "/desktop/PDF/"
                  SHEET1 ".pdf"
               )
            )
            (command "-export" "_P" "_W" ll ur "_N" pdffile)
            (setq i (1+ i))
         )
      )
   )
          (setvar "CMDECHO" 1)
   (princ)
)
0 Likes
1,109 Views
2 Replies
Replies (2)
Message 2 of 3

dbhunia
Advisor
Advisor

A quick check......change the line.....

 

(setq ss (ssget (list '(0 . "INSERT")'(2 . "UNITS"))))

To

(setq ss (ssget (list '(0 . "INSERT"))))

 

I can't check the LISP right now........

 

 


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes
Message 3 of 3

Moshe-A
Mentor
Mentor

@3arizona  hi,

 

Here is my untested correction 😀

Note that in (*error*) function there is this call:

 

(mapcar 'setvar VarList OldVars)

 

VarList and OldVars are global variables and are not define in this lisp, they maybe exist in your environment but if they don't you will get a bad argument type error if this program is break somehow.

 

enjoy

Moshe

  

 

(vl-load-com)
(defun c:unitPDF ( / *error* ss ed obj i box ll ur pt1 pt2 pdffile tag val)
  
 (defun *error* (errmsg)
  (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break"))
   (princ (strcat "\nError: " errmsg))
  )
  ;;;;; Do stuff then error, ESC,
  (mapcar 'setvar VarList OldVars)
  (setvar "cmdecho" 1)
  (princ)
 );;;; end *error*
  
  ;;;;; Main routine
  (setvar "cmdecho" 0)
  (command "._undo" "_begin")
  
  (setq logname (getvar "loginname"))
  (command "psetupin" "Details.dwg" "11x17 Landscape" "y")
  (command "-PLOT" "n" "model" "11x17 Landscape" "Bluebeam BW.pc3" "N" "Y" "N")
  
  (if (setq ss (ssget (list '(0 . "INSERT") '(2 . "`*U*"))))
   (progn
    (setq i 0)
    (while (< i (sslength ss))
    (setq ent (ssname ss i))
    (setq obj (vlax-ename->vla-object ent))
	 
    (if (eq (strcase (vla-get-effectiveName obj)) "UNIT")
     (progn 
      (setq box (vlax-invoke-method obj 'getboundingbox 'pt1 'pt2))
      (setq ll  (vlax-safearray->list pt1))
      (setq ur  (vlax-safearray->list pt2))
	   
      (while (and
               (setq ent (entnext ent))
               (= "ATTRIB" (cdr (assoc 0 (setq edata (entget ent)))))
             )
       (setq tag (cdr (assoc 2 edata)))
       (setq val (cdr (assoc 1 edata)))
       
       (cond
        ((= tag "-DO-NOT-EDIT-")   (setq SHEET1 val))
       )
      ); while
	      
      (setq pdffile (strcat "C:/Documents and Settings/" (getvar 'loginname) "/desktop/PDF/" SHEET1 ".pdf"))
      (command "-export" "_P" "_W" ll ur "_N" pdffile)
     ); progn
    ); if
     
    (setq i (1+ i))
   ); while
  ); progn
 ); if

 (command "._undo" "_end")
 (setvar "cmdecho" 1)
 (princ)
); c:unitPDF

0 Likes