Jump to content

Recommended Posts

Posted (edited)

I'm trying to draw a line with a set length and angle through autolisp, but relative coordinates don't seem to work.

 

If I type

(command "line" point1 "3860<-170" "")

it draws the line starting at the given point and finishes where it would if point1 = 0,0.

 

Does anyone know how to fix this? I want to draw a line from a set point, with a given length and angle, without having to workout the absolute coordinates of the end point.

 

edit: sorry I eventually found the answer myself, I simply add an "@" to make autocad use the coordinates as relative. Hope this helps someone else!

Edited by bpdav1
Posted

By adding "@" should work, but is better to look to POLAR function instead. Also, take care to avoid interference with current auto OSNAP and conflicts with a localized version of AutoCAD/redefined commands.

(command "_.LINE" "_non" point1 "_non" (polar point1 (* (/ -170.0 180.0) pi) 3860.0) "")

  • Like 1
Posted

It enable the None OSNAP mode for next input - this overrides any auto OSNAP mode(s), so doesn't interfere with your drawing process. A better solution is to add the entities directly on database using ENMAKE function instead of using COMMAND; but I suggest you to let this for later when will gain more experience in AutoLISP programming.

Posted

To understand exactly how auto OSNAP influence the drawing process from AutoLISP, start a new drawing, make sure that Endpoint OSNAP mode is activated and run the two routines below (paste the code on prompter and call TEST1, respectively TEST2 commands). There should be two circles - the smaller one was supposed to be in 3, 3; second is located correctly (5, 5).

(defun c:test1()
(command "_.LINE" "_non" '(0.0 0.0) "_non" '(50.0 50.0) "")
(command "_.ZOOM" "_E")
(command "_.CIRCLE" '(3.0 3.0) 3.0)
(princ)
)

(defun c:test2()
(command "_.LINE" "_non" '(0.0 0.0) "_non" '(50.0 50.0) "")
(command "_.ZOOM" "_E")
(command "_.CIRCLE" "_non" '(5.0 5.0) 5.0)
(princ)
)

Posted

When drawing something on the screen using the COMMAND function, a possible approach could be: save the current Osnap settings, disable Osnaps, draw your objects and restore the saved Osnap.

Like this:

(setq Old (getvar "osmode"))
(setvar "osmode" 0)
(command....)
.......
.......
(setvar "osmode" Old)

To go a step further: if the Lisp crashes, the saved Osnap is not restored. That's a good reason to write an error handling for your Lisp.

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