Jump to content

Trying to create 2 lines, but autolisp randomly overplaces them. Why?


ng80092a

Recommended Posts

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)

Link to comment
Share on other sites

(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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

(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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

@Grrr

I'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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

@ 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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...