Nikon Posted December 26, 2023 Posted December 26, 2023 (edited) Hello to all readers. In AutoCAD, to enter the slope of the line, you need to use the angle bracket "<". To get an angle of 30°, enter <30 in the command string. Is it possible to write in lisp as well? Lisp has such a function "<". Lisp will not perceive "<" as a function? My attempt to create the code: 1. Specify 1 point 2. Enter the angle <30 3. Specify the 2nd point I have no experience in writing codes, so I ask for help from experts. (defun c:line_ang1 ( ) (vl-load-com) (setq p1 (getpoint "\nSpecify the base point: ")) (setq pnd (getreal "\nSpecify the angle: < ")) (setq xpb (car pb)) (setq ypb (cadr pb)) (setq p2 ??? (command "_line" p1 pb p2 "") (princ) ) The code is certainly incorrect... thanks for any help... Edited December 26, 2023 by Nikon Quote
Steven P Posted December 26, 2023 Posted December 26, 2023 So to get point 2, convert the angle number to radians (search deg to rad LISPs) Look at polar (polar pt ang dist) though you will also need to know a distance to calculate the point. Quote
Nikon Posted December 26, 2023 Author Posted December 26, 2023 (edited) Is it possible to do without radians? If AutoCAD has a function for setting the angle in degrees, then this can be done via lisp. But how to write it down correctly? The 2nd point can simply be indicated on the screen when the line appears at a given angle... Edited January 6 by Nikon Quote
BIGAL Posted December 26, 2023 Posted December 26, 2023 (edited) My take on your problem. Just ask if this is what you want. Pick a point then The No code way is to use SNAPANG 30 & press F8, Ortho on, this will set your angle as you draw a line. Just remember must do Snapang 0 to go to normal angle. Edited December 26, 2023 by BIGAL 1 1 Quote
Nikon Posted December 27, 2023 Author Posted December 27, 2023 @BIGAL thank you for advice. Constantly changing the SNAPANG value to the desired angle, and then returning it to 0, is not very convenient... Quote
Nikon Posted December 27, 2023 Author Posted December 27, 2023 Probably, you need to put 60 in the code instead of the angle bracket, so that you can then specify the angle value in degrees... (ascii "<") 60 Quote
1958 Posted December 27, 2023 Posted December 27, 2023 My version. Don't scold too much. (defun c:11 (/ p0 ang dist) (vl-load-com) (setvar "DYNMODE" 1) (setvar "ORTHOMODE" 0) (setvar "SNAPMODE" 0) (setvar "OSMODE" 0) (setq p0 (getpoint "SPick the first point >") ang (angtof (rtos (getreal "Enter angle >")) 0) dist (distance p0 (getpoint p0 "Pick a second point >")) ) (entmakex (list (cons 0 "LINE") (cons 10 p0) (cons 11 (polar p0 ang dist)))) ) 1 Quote
Nikon Posted December 27, 2023 Author Posted December 27, 2023 (edited) Lisp performs its task well! @1958 Thanks!!! Edited January 7 by Nikon Quote
Steven P Posted December 27, 2023 Posted December 27, 2023 Think OP wants to set the angle by text and set the distance on the screen. LISP maybe: get angle, set snapang to this, draw line, reset snapang to previous. Add error processing to return snapang to original in case of escape for example. 1 Quote
Nikon Posted December 27, 2023 Author Posted December 27, 2023 (edited) "get angle, set snapang to this, draw line, reset snapang to previous... I'm trying to write a macro, but it doesn't work ^C^C_snapang;\_LINE;\_snapang;_0 _snapang It is not returned to "0" ? ? ? Edited December 27, 2023 by Nikon Quote
1958 Posted December 27, 2023 Posted December 27, 2023 (defun c:11 (/ p0 ang dist) (vl-load-com) (setq p0 (getpoint "Pick the first point >") ang (angtof (rtos (getreal "Enter angle >")) 0) ) (setvar "SNAPANG" ang) (setq dist (distance p0 (getpoint p0 "Pick a second point >"))) (entmakex (list (cons 0 "LINE") (cons 10 p0) (cons 11 (polar p0 ang dist)))) (setvar "SNAPANG" 0) ) 2 Quote
Nikon Posted December 27, 2023 Author Posted December 27, 2023 (edited) The last code is much more convenient, thanks @1958!!! Edited December 27, 2023 by Nikon Quote
Steven P Posted December 27, 2023 Posted December 27, 2023 (edited) 2 hours ago, 1958 said: (defun c:11 (/ p0 ang dist) (vl-load-com) (setq p0 (getpoint "Pick the first point >") ang (angtof (rtos (getreal "Enter angle >")) 0) ) (setvar "SNAPANG" ang) (setq dist (distance p0 (getpoint p0 "Pick a second point >"))) (entmakex (list (cons 0 "LINE") (cons 10 p0) (cons 11 (polar p0 ang dist)))) (setvar "SNAPANG" 0) ) Small change I'd make, (defun c:11 (/ p0 ang dist) (defun 11error ( errormsg / ) (setvar "SNAPANG" old_snapang) ; reset variables (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 temperr *error*) ;store *error* ; can wait till here to set error function, after recording old variables (setq *error* 11error) (setvar "SNAPANG" ang) (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) (entmakex (list (cons 0 "LINE") (cons 10 p0) (cons 11 (polar p0 ang dist)))) (setq *error* temperr) ; reset error ) Edited December 27, 2023 by Steven P 1 1 Quote
Nikon Posted December 27, 2023 Author Posted December 27, 2023 @Steven P Thank you, your code is working. But an entry appears on the command string: Pick a second point >#<SUBR @00000000369ce930 *ERROR*> Is this normal? Quote
Steven P Posted December 27, 2023 Posted December 27, 2023 Yes, that is OK. The command line is telling you the last thing the LISP recorded, so in my example it is telling you about the error function that is reset, in the code above the report is '0' (the last variable that was set - SnapAng), the first example by 1958 should be the entity name of the line created <entity name abcdef>. Mine has "Error" in that text since the error function was the last thing recorded, nothing to worry about. You can hide these by exiting the LISP quietly with the last line being (princ), write blank to the command line, and noting that if your last line is for example (princ "Lisp Ended") and no more then the "Lisp Ended" text, being the last thing recorded by the LISP will be repeated. Quote
Nikon Posted December 27, 2023 Author Posted December 27, 2023 (edited) @Steven PThanks for the comments, now everything is clear... Edited December 27, 2023 by Nikon 1 Quote
BIGAL Posted December 28, 2023 Posted December 28, 2023 My $0.05 make defuns for snap ang. Getpoint 1, getpoint 2 or length. (defun c:30 ......... (defun c:45 ........ (defun c:60 .......... Quote
Nikon Posted December 28, 2023 Author Posted December 28, 2023 (edited) @BIGAL It is unclear what this is and where to? (defun c:30 ......... (defun c:45 ........ (defun c:60 .......... Edited December 30, 2023 by Nikon Quote
Steven P Posted December 28, 2023 Posted December 28, 2023 3 hours ago, Nikon said: @BIGAL It is unclear what this is and where to? (defun c:30 ......... (defun c:45 ........ (defun c:60 .......... Have a few LISPs, 30, 45, 60 one for each of the most frequent angles that you use, the angle is set in the LISP instead of by the user and is quicker Quote
Nikon Posted December 28, 2023 Author Posted December 28, 2023 1 hour ago, Steven P said: (defun c: 30 ......... (defun c: 45 ........ (defun c: 60 .......... (defun c: 35 ......... (defun c: 50 ........ (defun c: 68 .......... You can continue the list of angles I have over 100 lisps in automatic download. Opening files in AutoCAD takes a little longer, that's why I'm trying to make simple codes using macros... Quote
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.