When user hits "Esc" the code exits with error, in that example an error-handler function is defined to reset the osmode variable:
(defun *error* ; define the error-handler function (alert (strcat "\nError occured, now you are inside the *error* function \nand reseting the osmode variable!")) (if osm (setvar 'osmode osm)) ; when your code crashes, it will check and reset the osmode value (princ)); defun *error*
Try the code I posted there. Hi ng...
Grrr is trying to nudge you in the right direction.
Your code might look like this:
(defun c:fuste8 (/ *error*pin altura dsup dinf nlados esp e2 ss1 p1esq p2esq p1dir p2dir p1esq1 p2esq1 p1dir1 p2dir1 jorr lest ldir dirint esqint teste dinttopo dintbase aitopo aibase osm ) ;_ end of / (defun *error* (msg) (if (and msg (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))) ;_ end of and (princ (strcat "\nError: " msg)) ) ;_ end of if (if osm (setvar 'osmode osm) ) ;_ end of if (princ) ) ;_ end of defun (setq osm (getvar 'osmode)) (setvar 'osmode 0) (setq pin (getpoint "\nPonto de introducao: ")) (setq altura (getint "\nAltura: ")dsup (getint "\nDiametro superior: ")dinf (getint "\nDiametro inferior: ") ;nlados (getint "\nNumero de lados: ")esp (getint "\nEspessura: ")jorr (/ (* (atan (- (/ dinf 2) (/ dsup 2)) altura) 180) PI) ) ;_ end of setq ;;DADOS COMPLEMENTARES (setq dinttopo (- dsup esp)dintbase (- dinf esp) ) ;_ end of setq (setq aitopo (* dinttopo (/ (sin (/ PI ) (cos (/ PI ))) aibase (* dintbase (/ (sin (/ PI ) (cos (/ PI ))) ) ;_ end of setq ;;Linhas extremas (setq p1esq (cons (- (car pin) (/ dsup 2)) (cons (cadr pin) (cons 0.0 '())) ) ;_ end of cons ) ;_ end of setq (setq p2esq (cons (- (car pin) (/ dinf 2)) (cons (- (cadr pin) altura) (cons 0.0 '())) ) ;_ end of cons ) ;_ end of setq (setq p1dir (cons (+ (car pin) (/ dsup 2)) (cons (cadr pin) (cons 0.0 '())) ) ;_ end of cons ) ;_ end of setq (setq p2dir (cons (+ (car pin) (/ dinf 2)) (cons (- (cadr pin) altura) (cons 0.0 '())) ) ;_ end of cons ) ;_ end of setq (command "line" p2esq p1esq "");(setq lest (entlast));(command "offset" esp lest p1dir "");(setq esqint (entlast)) (command "line" p2dir p1dir "");(setq ldir (entlast));(command "offset" esp ldir p1esq "");(setq dirint (entlast)) ;;Linha intermedia de 8 (setq p1esq1 (cons (- (car pin) (/ aitopo 2)) (cons (cadr pin) (cons 0.0 '())) ) ;_ end of cons ) ;_ end of setq (setq p2esq1 (cons (- (car pin) (/ aibase 2)) (cons (- (cadr pin) altura) (cons 0.0 '())) ) ;_ end of cons ) ;_ end of setq (setq p1dir1 (cons (+ (car pin) (/ aitopo 2)) (cons (cadr pin) (cons 0.0 '())) ) ;_ end of cons ) ;_ end of setq (setq p2dir1 (cons (+ (car pin) (/ aibase 2)) (cons (- (cadr pin) altura) (cons 0.0 '())) ) ;_ end of cons ) ;_ end of setq ;;THESE LINES OVERLAP THE PREVIOUS ONES! (command "line" p1esq1 p2esq1 "") (command "line" p1dir1 p2dir1 "")(setvar 'osmode osm) (prin1 p2esq1) (prin1 " ") (prin1 p2esq) (prin1 " ") (prin1 p1esq1) (prin1 " ") (prin1 p1esq)) ;_ end of defun Maybe the error-handling tutorial from LM would help more:
http://www.lee-mac.com/errorhandling.html
I don't know why I haven't posted it earlier. (as english is not my native language and I might be bad at explaining things).
Yeah, that's where it helped me wrap my head around error trapping... Hey ng...
As I don't know the language, what is this lisp routine supposed to do? @ PDuMont
It's Portuguese, it defines simple lines with a few parameters introduced.
Altough its simple, those are drawings used in the metal-mechanic industry for poles and high altitude towers. That is basically a front view of a pole, with a upper and bottom diameter and a height. I've recently joined a company on the sector and as I love programming I'm trying to help with drawings.
@Grrr
Sorry I didn't pay attention the your post on the link, i'll take a look at it now. Thanks very much
If you put "non"before the point that problem does not arise. Whilst error trapping is the way to go we just use old fashioned type 47
This defun is part of our library autoload.
(defun c:47 () (setvar "osmode" 47))
A better way is to have a library error trap routine and auto load it so only need 1 line in your code (myerror) with around 200+ routines I really should do this, for osmode, filedia and a couple more.
Or do it like this:
http://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/osnap-off-in-a-lisp-routine/m-p/794975#M20633
Thanks for posting this!
页:
1
[2]