ng80092a Posted October 24, 2016 Share Posted October 24, 2016 Short version: I have a code that uses 4 commands to create 4 different lines. However, even if the points i give him are different, he sometimes places the lines over themselves. I have used a prin1 to confirm the points i give him are really different, and they are, but for some reason the code places the lines over themselves randomly! Long version: the code (defun c:fuste8 (/ 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) (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) ) ;;DADOS COMPLEMENTARES (setq dinttopo (- dsup esp) dintbase (- dinf esp) ) (setq aitopo (* dinttopo (/ (sin (/ PI ) (cos (/ PI ))) aibase (* dintbase (/ (sin (/ PI ) (cos (/ PI ))) ) ;;Linhas extremas (setq p1esq (cons (- (car pin) (/ dsup 2)) (cons (cadr pin) (cons 0.0 '())))) (setq p2esq (cons (- (car pin) (/ dinf 2)) (cons (- (cadr pin) altura) (cons 0.0 '())))) (setq p1dir (cons (+ (car pin) (/ dsup 2)) (cons (cadr pin) (cons 0.0 '())))) (setq p2dir (cons (+ (car pin) (/ dinf 2)) (cons (- (cadr pin) altura) (cons 0.0 '())))) (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 '())))) (setq p2esq1 (cons (- (car pin) (/ aibase 2)) (cons (- (cadr pin) altura) (cons 0.0 '())))) (setq p1dir1 (cons (+ (car pin) (/ aitopo 2)) (cons (cadr pin) (cons 0.0 '())))) (setq p2dir1 (cons (+ (car pin) (/ aibase 2)) (cons (- (cadr pin) altura) (cons 0.0 '())))) ;;THESE LINES OVERLAP THE PREVIOUS ONES! (command "line" p1esq1 p2esq1 "") (command "line" p1dir1 p2dir1 "") (prin1 p2esq1) (prin1 " ") (prin1 p2esq) (prin1 " ") (prin1 p1esq1) (prin1 " ") (prin1 p1esq) Quote Link to comment Share on other sites More sharing options...
rkmcswain Posted October 24, 2016 Share Posted October 24, 2016 Sounds like object snap is enabled while the routine is running. Quote Link to comment Share on other sites More sharing options...
ng80092a Posted October 24, 2016 Author Share Posted October 24, 2016 you are absolutely right.. is it possible to disable osnap and re-enable it at the end of the routine? Quote Link to comment Share on other sites More sharing options...
PDuMont Posted October 24, 2016 Share Posted October 24, 2016 (setq osnapmode (getvar 'osmode)) ;this saves your current osnap settings (setvar 'osmode 0) ;this turns off osnaps ; **your routine here (setvar 'osmode osnapmode) ;this resets to your saved osnap settings Quote Link to comment Share on other sites More sharing options...
ng80092a Posted October 24, 2016 Author Share Posted October 24, 2016 Thank you very much everyone Quote Link to comment Share on other sites More sharing options...
BIGAL Posted October 25, 2016 Share Posted October 25, 2016 A bit more on osmode sometimes in a lisp you want certain snaps and do not want operator to use wrong ones so you just set your snaps to what you want then type osmode the number shown matches that combination. eg our normal working is osmode 47. Quote Link to comment Share on other sites More sharing options...
wimal Posted October 25, 2016 Share Posted October 25, 2016 (command "line" [color="red"]"non"[/color]p1esq1 "[color="red"]non[/color]"p2esq1 "") (command "line" [color="red"]"non[/color]"p1dir1 "[color="red"]non[/color]"p2dir1 "") Put 'non"before the point Quote Link to comment Share on other sites More sharing options...
ng80092a Posted October 25, 2016 Author Share Posted October 25, 2016 Yes, using osmode (value) seems pretty nice. But i've ran into other problem, if for some reason i cancel the code mid-execution, osnap will stay at 0. Is it possible to replace osmode back to the saved value if the user presses "esc"? I might use "non", but i'm curious if a action on escape is possible with lisp Quote Link to comment Share on other sites More sharing options...
Grrr Posted October 25, 2016 Share Posted October 25, 2016 Yes, using osmode (value) seems pretty nice. But i've ran into other problem, if for some reason i cancel the code mid-execution, osnap will stay at 0. Is it possible to replace osmode back to the saved value if the user presses "esc"? I might use "non", but i'm curious if a action on escape is possible with lisp Read post #7 in this thread: http://www.cadtutor.net/forum/showthread.php?98546-Lisp-circle Quote Link to comment Share on other sites More sharing options...
ng80092a Posted October 25, 2016 Author Share Posted October 25, 2016 @Grrr I've read the post, what's new about it? Quote Link to comment Share on other sites More sharing options...
Grrr Posted October 25, 2016 Share Posted October 25, 2016 @GrrrI've read the post, what's new about it? 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. Quote Link to comment Share on other sites More sharing options...
PDuMont Posted October 25, 2016 Share Posted October 25, 2016 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 Quote Link to comment Share on other sites More sharing options...
Grrr Posted October 25, 2016 Share Posted October 25, 2016 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). Quote Link to comment Share on other sites More sharing options...
PDuMont Posted October 25, 2016 Share Posted October 25, 2016 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... Quote Link to comment Share on other sites More sharing options...
PDuMont Posted October 25, 2016 Share Posted October 25, 2016 Hey ng... As I don't know the language, what is this lisp routine supposed to do? Quote Link to comment Share on other sites More sharing options...
ng80092a Posted October 25, 2016 Author Share Posted October 25, 2016 @ 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 Quote Link to comment Share on other sites More sharing options...
wimal Posted October 26, 2016 Share Posted October 26, 2016 Yes, using osmode (value) seems pretty nice. But i've ran into other problem, if for some reason i cancel the code mid-execution, osnap will stay at 0. Is it possible to replace osmode back to the saved value if the user presses "esc"? I might use "non", but i'm curious if a action on escape is possible with lisp If you put "non"before the point that problem does not arise. Quote Link to comment Share on other sites More sharing options...
BIGAL Posted October 26, 2016 Share Posted October 26, 2016 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. Quote Link to comment Share on other sites More sharing options...
rkmcswain Posted October 26, 2016 Share Posted October 26, 2016 you are absolutely right.. is it possible to disable osnap and re-enable it at the end of the routine? 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 Quote Link to comment Share on other sites More sharing options...
Grrr Posted October 26, 2016 Share Posted October 26, 2016 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! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.