Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 12/26/2023 in all areas

  1. Try This, (defun c:dimauto (/ ss ent dxf_ent var_cmdecho var_osmode llpt urpt) (defun *error* ( msg ) (if (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*")) (princ (strcat "\nError: " msg)) ) (setvar 'cmdecho var_cmdecho) (setvar 'osmode var_osmode) (princ) ) (setq var_cmdecho (getvar "cmdecho")) (setq var_osmode (getvar "osmode")) (setvar 'cmdecho 0) (setvar 'osmode 0) (or sn (setq sn 1)) (initget 4) (if (setq tmp1 (getint (strcat "\nEnter Starting Number : <" (rtos sn 2 0) ">: "))) (setq sn tmp1) ) (while (setq ss (ssget ":S" (list '(0 . "*POLYLINE") ))) (if ss (repeat (setq n (sslength ss)) (setq ent (ssname ss (setq n (1- n))) dxf_ent (entget ent) ) (vla-getboundingbox (vlax-ename->vla-object ent) 'mn 'mx) (setq llpt (vlax-safearray->list mn)) (setq urpt (vlax-safearray->list mx)) (setq midpt (mapcar '(lambda (x y) (/ (+ x y) 2)) llpt urpt)) (command "_.DIMALIGNED" (list (car llpt) (cadr urpt)) urpt (list (car llpt) (- (cadr urpt) 0.5))) (command "_.DIMALIGNED" (list (car llpt) (cadr urpt)) llpt (list (+ (car llpt) 0.5) (cadr urpt))) (make_text (list (car midpt) (- (cadr midpt) 0.5)) (rtos sn 2 0)) (setq sn (1+ sn)) ) ) ) (setvar 'cmdecho var_cmdecho) (setvar 'osmode var_osmode) (princ) );defun (defun make_text (txt_pt txt_val) (entmake (list '(0 . "TEXT") '(8 . "0") (cons 10 txt_pt) (cons 40 0.2895) (cons 1 txt_val) '(50 . 0.0) '(71 . 0) '(72 . 1) '(73 . 2) (cons 11 txt_pt)))) (princ "\nDIMAUTO" ) (princ) DimAuto.lsp
    1 point
  2. So I guess at the end of your code you will have some function that sets the variables (fonts, osmode and so on) back to what they were... but if you cause an 'error', say with the escape then the LISP will never get as far as these lines that return everything back to what they were. Couple of things you can do, make the changes as short as possible. Some will change say OSMode in the first few lines of code, and reset it at the last line where in reality it might only need to be changed for 1 line of code (as an example),... so just change it for where it is needed (and if you need to change it a few times so be it if it will reduce errors) Second thing you can do is to look into error trapping - a small sub routine that does stuff in the case of an error (such as hitting escape), it might be a simple error message "LISP Cancelled" or could do other things such as resetting variables back to how they were.
    1 point
×
×
  • Create New...