Jump to content

Drawing a line using Azimuth


Silvercloak

Recommended Posts

One of the survey bosses here is asking me for a quick Lisp to draw a line using azimuth. He wants to do it with just one command instead of using the drop down inside the line toolbar.

 

So I figured - fine this should be easy. If I type line, and use the ZD transparent command, I can do the same thing in a lisp.

 

Unfortunately when I use the ZD transparent command, it doesn't draw the line until I do it twice. I don't get it - why can't it do it the FIRST time as it does when I click on the toolbar button?

 

I'm sorry, this may be a really DUMB question, but can anyone help? If this doesn't make any sense - I'll try and explain more. Let me know.

 

Here's the really lame code that I made... which should've been enough if the command would actually WORK the first time.

 

(defun C:LTR ()
(command "LINE" pause "'zd" "")
(PRINC)
)

 

Silvercloak

Link to comment
Share on other sites

Thanks, but that doesn't work. It has to remain a transparent command. If I remove the "" it completely ignores the 'zd and becomes a regular line command.

Link to comment
Share on other sites

Maybe this will fix the issue:

(defun C:LTR ()
 (command "_.line" "\\" "'zd")
 (while (/= (logand (getvar 'cmdactive) 3) 0) (command "\\"))
 (princ)
)

 

Or else try this:

(defun C:LTR ( / pt)
 (if (setq pt (getpoint "\nSpecify first point: "))
   (vla-sendcommand (vla-get-activedocument (vlax-get-acad-object)) "_.line _non (getvar 'lastpoint) 'zd ")
 )
 (princ)
)

Link to comment
Share on other sites

Thanks Roy!! The second one worked! I wish I knew the visual basic stuff. It's like greek to me right now.

 

Silvercloak

Link to comment
Share on other sites

Maybe this will fix the issue:

(defun C:LTR ()
 (command "_.line" "\\" "'zd")
 (while (/= (logand (getvar 'cmdactive) 3) 0) (command "\\"))
 (princ)
)

 

Or else try this:

(defun C:LTR ( / pt)
 (if (setq pt (getpoint "\nSpecify first point: "))
   (vla-sendcommand (vla-get-activedocument (vlax-get-acad-object)) "_.line _non (getvar 'lastpoint) 'zd ")
 )
 (princ)
)

 

Sorry I spoke too soon. I think that 'lastpoint in there is messing things up. Whenever I run this command it's not using the getpoint that I gave it, instead it's going to the lastpoint I clicked BEFORE I ran this command.

 

I'm trying to figure out the correct... replacement to your (getvar 'lastpoint) there but I'm not doing so great. :(

 

silvercloak

Link to comment
Share on other sites

In BricsCAD the getpoint function updates the lastpoint variable. It seems that AutoCAD fails to do so.

Revised code:

(defun C:LTR ( / pt)
 (if (setq pt (getpoint "\nSpecify first point: "))
   (progn
     (setvar 'lastpoint pt)
     (vla-sendcommand (vla-get-activedocument (vlax-get-acad-object)) "_.line _non (getvar 'lastpoint) 'zd ")
   )
 )
 (princ)
)

Link to comment
Share on other sites

OMG I can't believe I didn't think of that. So frigging simple.

 

I'm SO rusty. Thanks Roy.

 

Silvercloak

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