How to Handle an Error that Happens when I run a lisp.

How to Handle an Error that Happens when I run a lisp.

raceharder
Enthusiast Enthusiast
330 Views
3 Replies
Message 1 of 4

How to Handle an Error that Happens when I run a lisp.

raceharder
Enthusiast
Enthusiast

I have a lisp for changing a titleblock.  This lisp 1st unlocks the "barcode" layer and the deletes the "barcode" layer.  It then zooms to extents and moves all to 0,0.  It then deletes the titleblock "TB_02", inserts a different titleblock and updates the newly inserted titleblock.

 

My problem is that not all sheets have the "barcode" layer so I would like it to only delete the "barcode" layer if it exists, else continue on with the lisp (zoom to extents, move all to 0,0)

 

My 2nd issue is that not all sheets have the "TB_02" titleblock.  Same here.  I would like it to only delete "TB_02" if it exists, else continue on with the lisp (insert different titleblock and update said block)

 

Here is a copy of my code:

(defun c:tbc ( / ss x)
(command"_.Layer""_U""Barcode""")
(command"_.Laydel""N""Barcode""""Y")
(command"zoom""extents")
(command"_.Move""all""""""0,0")
(setq ss (SSGET "X" '((0 . "INSERT"))))
(repeat (setq x (sslength ss))
(setq obj (vlax-ename->vla-object (ssname ss (setq x (- x 1)))))
(if (= (vla-get-EffectiveName obj) "TB_02")
(vla-delete obj)
)
)
(princ)
(command "_.-insert" "fordtitleblock2" "R" "0" "0,0" "1" "1" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" )
(command "script" "L:/9-ControlsDesign/scripts/ngftbin.scr")
)

 

Any advice on this is greatly appreciated.  Thanks in advance for your help.  

 

RH

0 Likes
Accepted solutions (1)
331 Views
3 Replies
Replies (3)
Message 2 of 4

Jonathan3891
Advisor
Advisor
Accepted solution

You need to search for both the layer name and block name in the drawing and if it exist then proceed.

Something like this:

 

 

(defun c:tbc ( / BN SS B )
  (if (tblsearch "Layer" "barcode")
    (command "_.Laydel" "N" "Barcode" "" "Y")
    )
  (command "Zoom" "Extents")
  (command"_.Move" "all" "" (getvar "extmin") '(0 0))
  (setq BN "TB_02")
  (cond
    ((setq SS (ssget "_x" (list '(0 . "insert") (cons 2 BN))))
     (foreach x (mapcar 'cadr (ssnamex SS))
       (vl-catch-all-apply 'vla-delete (list (vlax-ename->vla-object x)))
     )
     (if (setq B (tblobjname "block" BN))
       (vl-catch-all-apply 'vla-delete (list (vlax-ename->vla-object (cdr (assoc 330 (entget B))))))
     )
    )
  )
  (princ)
)

 

 

 

 

 


Jonathan Norton
Blog | Linkedin
0 Likes
Message 3 of 4

raceharder
Enthusiast
Enthusiast

@Jonathan3891 I see what you did there.  I am new to writing lisps and with that bit of code you provided, I was able to get mine to run exactly how I wanted.  I do appreciate the time and help! Thank you very much.

0 Likes
Message 4 of 4

Sea-Haven
Mentor
Mentor

Just a comment the "laydel" command is not available in Bricscad V20 maybe in latest version.

0 Likes