Jump to content

How to use lisp to enter the angle of inclination of the line in degrees


Nikon

Recommended Posts

@BIGAL

Thanks for the help.

6 hours ago, BIGAL said:

(defun c:11 ( / .....
.....
..
)
(c:11)

As I understand it, lisps with this ending (c:11) should not be in the startup,
otherwise (if there are 10-20 pieces. - they will all immediately start executing this commands) there will be confusion...
or am I wrong in my assumption?

Link to comment
Share on other sites

That's right, if there is a stand alone line of code in the LISP (not enclosed by  (defun ...... ) then that will be executed as the LISP loads.

 

If the file only contains a single LISP then loading the file on demand as discussed above will run the LISP. You can delete this or comment it out (with ;; )in the file you have saved if it is more convenient.

 

For example, I have a start up LISP file and in this there are lines, outside of a function, that sets the system to my preferences, so it is the same each time I load a drawing rather than whatever it was last time I closed one, this functionality has its uses.

  • Thanks 1
Link to comment
Share on other sites

Posted (edited)

Happy New Year to all
Is it possible to slightly change lisp "11" so that the line at an angle (minus) (anglevalue) does not go under the X axis?

(defun c:11 (/ p0 ang dist)
 (defun 11error (errormsg /)
 (setvar "SNAPANG" old_snapang) ; reset variables
 (setvar "ORTHOMODE" old_orthomode)
 (setq *error* temperr) ; reset *error*
 (prompt "\nFunction Canelled.")
 )
 (vl-load-com)
 (setq p0 (getpoint "Pick the first point >")
 ang (angtof (rtos (getreal "Enter angle >")) 0)
 )
 (setq Old_snapang (getvar "SNAPANG")) ; to record what it was, might not be 0
 (setq old_orthomode (getvar "ORTHOMODE"))
 (setq temperr *error*)
 ;store *error* ; can wait till here to set error function, after recording old variables
 (setq *error* 11error)
 (setvar "SNAPANG" ang)
 (setvar "ORTHOMODE" 1)
 (setq dist (distance p0 (getpoint p0 "Pick a second point >")))
 (setvar "SNAPANG" Old_Snapang) ; moved this here, seto to old value (no assumption what it was)
 (setvar "ORTHOMODE" old_orthomode)
 (entmakex (list (cons 0 "LINE") (cons 10 p0) (cons 11 (polar p0 ang dist))))
 (setq *error* temperr) ; reset error
 (princ)
)

 

 

 

11-angle.png

Edited by Nikon
Link to comment
Share on other sites

2 hours ago, Nikon said:

Happy New Year to all
Is it possible to slightly change lisp "11" so that the line at an angle (minus) (anglevalue) does not go under the X axis?

Prohibition of entering a negative value

(defun c:11 (/ p0 ang dist)
 (defun 11error (errormsg /)
  (setvar "SNAPANG" old_snapang) ; reset variables
  (setvar "ORTHOMODE" old_orthomode)
  (setq *error* temperr) ; reset *error*
  (prompt "\nFunction Canelled.")
 )
 (vl-load-com)
 (setq p0 (getpeint "Pick the first point >"))
 (initget 4) ; Entering negative numbers is not allowed
 (setq ang (angtof (rtos (getreal "Enter angle >")) 0))
 (setq Old_snapang (getvar "SNAPANG")) ; to record what it was, might not be 0
 (setq old_orthomode (getvar "ORTHOMODE"))
 (setq temperr *error*)
  ;store *error* ; can wait till here to set error function, after recording old variables
 (setq *error* 11error)
 (setvar "SNAPANG" ang)
 (setvar "ORTHOMODE" 1)
 (setq dist (distance p0 (getpoint p0 "Pick a second point >")))
 (setvar "SNAPANG" Old_Snapang) ; moved this here, seto to old value (no assumption what it was)
 (setvar "ORTHOMODE" old_orthomode)
 (entmakex (list (cons 0 "LINE") (cons 10 p0) (cons 11 (polar p0 ang dist))))
 (setq *error* temperr) ; reset error
 (princ)
)

 

  • Like 1
Link to comment
Share on other sites

4 minutes ago, Steven P said:

Yes, use 'abs' where you enter the angle. Will let you have a go to work it out

(defun c:11 (/ p0 ang dist)
 (defun 11error (errormsg /)
  (setvar "SNAPANG" old_snapang) ; reset variables
  (setvar "ORTHOMODE" old_orthomode)
  (setq *error* temperr) ; reset *error*
  (prompt "\nFunction Canelled.")
 )
 (vl-load-com)
 (setq p0  (getpoint "Pick the first point >")
       ang (angtof (rtos (abs (getreal "Enter angle >"))) 0)
 )
 (setq Old_snapang (getvar "SNAPANG")) ; to record what it was, might not be 0
 (setq old_orthomode (getvar "ORTHOMODE"))
 (setq temperr *error*)
  ;store *error* ; can wait till here to set error function, after recording old variables
 (setq *error* 11error)
 (setvar "SNAPANG" ang)
 (setvar "ORTHOMODE" 1)
 (setq dist (distance p0 (getpoint p0 "Pick a second point >")))
 (setvar "SNAPANG" Old_Snapang) ; moved this here, seto to old value (no assumption what it was)
 (setvar "ORTHOMODE" old_orthomode)
 (entmakex (list (cons 0 "LINE") (cons 10 p0) (cons 11 (polar p0 ang dist))))
 (setq *error* temperr) ; reset error
 (princ)
)

 

  • Like 1
Link to comment
Share on other sites

Posted (edited)

@1958 & @Steven PThank you and happy new year!
This last code draws a line at an angle (-60) to the right side,
if you set the angle (-30), then the dotted line shows the Angle (-60), and the line turns to the right side (30)...

15.gif

Edited by Nikon
Link to comment
Share on other sites

You enter the angle value - 30 degrees to the 0-X axis, and move the cursor to the floor at an angle of 120 degrees. Paradox! 😀

  • Agree 1
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...