Draw a line lisp

a.tawkXHKN6
Contributor
Contributor

Draw a line lisp

a.tawkXHKN6
Contributor
Contributor

i want a lisp that draws a line as follows: 

1. select point pt1 

2. draw a line such that first point is pt1 second point is away 100,000 mm from pt1 toward the cursor side.

 

0 Likes
Reply
Accepted solutions (2)
8,192 Views
19 Replies
Replies (19)

Kent1Cooper
Consultant
Consultant

@a.tawkXHKN6 wrote:

i want a lisp that draws a line as follows: 

1. select point pt1 

2. draw a line such that first point is pt1 second point is away 100,000 mm from pt1 toward the cursor side.

 


Define what you mean by "side."  In the cursor direction, whatever the angle, or orthogonally  to the right or left side [or maybe up or down?] from pt1?

 

I think this is going to involve (grread) operations.  And I think the User will have to pick  somewhere on the side [or direction?] they want to go, because the cursor location at the time of selecting pt1 will not be to any side, and slight movement subsequently might not be in the desired direction.

Kent Cooper, AIA
0 Likes

devitg
Advisor
Advisor
Accepted solution

@a.tawkXHKN6  hi, maybe it??

 

 

 

(DEFUN C:+100-LINE  (/ ANG AUX OSMODE PT1 PT2)

  (SETQ PT1 (GETPOINT))

  (SETQ AUX (CADR (GRREAD)))
  (SETQ ANG (ANGLE PT1 AUX))

  (SETQ PT2 (POLAR PT1 ANG 100.000))

  (SETQ OSMODE (GETVAR 'OSMODE))
  (SETVAR 'OSMODE 0)
   (grdraw pt1 pt2 1 3); it draw a vector 
  (COMMAND "line" PT1 PT2 "")

  (SETVAR 'OSMODE OSMODE)

  )

 

 

It is my first time I use GRnnn function  , I notice that GRREAD do not allow to use a SNAp . 

0 Likes

a.tawkXHKN6
Contributor
Contributor

thanks for your reply. but it doesn't work. 

0 Likes

a.tawkXHKN6
Contributor
Contributor

let's say point2 is in cursor direction and orthogonally. 

0 Likes

devitg
Advisor
Advisor

@a.tawkXHKN6 What do not work?, please clear .

 

 

 

0 Likes

a.tawkXHKN6
Contributor
Contributor
It's giving an error while using it in AutoCAD



0 Likes

devitg
Advisor
Advisor

@a.tawkXHKN6 please show the error , from the text screen , press F2 , to see it. 

 

 

0 Likes

Kent1Cooper
Consultant
Consultant

The way this is usually done involves a (while) function reading the (grread) returned list.  As long as that indicates that what has happened is movement of the cursor, [in this case] a Line can be drawn using (grdraw) or (grvecs) or (entmakex), so you can see what you're getting.  And every time the cursor is moved again, that's deleted and a new one drawn based on the new cursor location.  When (grread) finally indicates that a pick has been made, then it keeps the latest Line drawn.

 

A more sophisticated example, but one of the few times I've made full use of it, is RectMidPoint.lsp>here<.  It's repeatedly drawing a rectangle based around the specified midpoint, checking for the first entry in what (grread) returns to be a 5 for cursor movement, getting rid of the previous rectangle and drawing a new one, and when it's a 3 for a pick, it leaves the latest thing drawn.

Kent Cooper, AIA
0 Likes

ВeekeeCZ
Consultant
Consultant

Try THIS Lees version. Also using grread. 

0 Likes

ВeekeeCZ
Consultant
Consultant

@devitg wrote:

 

....

It is my first time I use GRnnn function  , I notice that GRREAD do not allow to use a SNAp . 


 

Yes, osnaps are challenging when using the grread function. Fortunately, Lee had written THIS utility... for all of us common people 🙂 

0 Likes

pbejse
Mentor
Mentor

@a.tawkXHKN6 wrote:

i want a lisp that draws a line as follows: 

1. select point pt1 

2. draw a line such that first point is pt1 second point is away 100,000 mm from pt1 toward the cursor side.

...

let's say point2 is in cursor direction and orthogonally. 

...


Not sure why the native Line command will not be enough for this. 

Grid X=spacing 100,000

Grid Y=spacing 100,000

Grid On

Snap On

Ortho On

 

 

 

 

ВeekeeCZ
Consultant
Consultant

👍 

1+1... how easy is that.

0 Likes

pbejse
Mentor
Mentor

@ВeekeeCZ wrote:

👍 

1+1... how easy is that.


 

I know right?,  AAMOF its too easy, makes me think there's more to this than what the OP is telling is.

 

 

 

0 Likes

Kent1Cooper
Consultant
Consultant

@pbejse wrote:
....Not sure why the native Line command will not be enough for this. 

Grid X=spacing 100,000

Grid Y=spacing 100,000

Grid On

Snap On

Ortho On


Perhaps because that requires the start point and end point of the Line to fall on the Snap-increment grid, whereas building the length into a routine will allow starting from anywhere, and will not require changing any settings, nor having to "aim" the cursor and type in the value.

Kent Cooper, AIA
0 Likes

pbejse
Mentor
Mentor
Accepted solution

@Kent1Cooper wrote:


Perhaps because that requires the start point and end point of the Line to fall on the Snap-increment grid, whereas building the length into a routine will allow starting from anywhere, and will not require changing any settings, nor having to "aim" the cursor and type in the value.

Yup, that could be the reason.

(DEFUN C:Whynot	( / PT1 pt2dir)
  (if
    (and
      (SETQ PT1 (GETPOINT))
      (setq pt2dir (getpoint pt1 "\nPick Direction point"))
    )
     (progn
       (COMMAND	"line"
		PT1
		(POLAR PT1 (angle PT1 pt2dir) 100000)
		""
       )
     )
  )(princ)
)

 

0 Likes

ВeekeeCZ
Consultant
Consultant

...and its late night edition.

 

(defun c:whynot-latenightedition ( / pt1 pt2dir)
  (if (setq pt1 (getpoint))
    (while (setq pt2dir (getpoint pt1 "\npick direction point"))
      (command "line" "non" pt1 "non" (setq pt1 (polar pt1 (angle pt1 pt2dir) 100000)) "")))
  (princ)
  )

Kent1Cooper
Consultant
Consultant

@Kent1Cooper wrote:

The way this is usually done involves a (while) function reading the (grread) returned list.  ....


If it's important to you, the one thing you might consider an advantage of the (grread) approach over the other solutions is that after giving it the first point, as you move the cursor around, it can show the Line that will result at the specified length, no matter what the distance from the first point to the cursor.  So you can see exactly what you'll get, not just the direction it will aim.  Is that worth pursuing?

Kent Cooper, AIA
0 Likes

Sea-Haven
Mentor
Mentor

Line pick 1st point drag mouse then type 100,000. With ortho on will draw square on the X Y axis no code required.

0 Likes

sporter2B74A
Observer
Observer

Here is a touch of fancy:

(defun dst (space lst / ds endpt lin midpt startpt str)
  ;; RJP - While we have two items in the list
  (while (cadr lst)
    ;; https://knowledge.autodesk.com/search-result/caas/CloudHelp/cloudhelp/2016/ENU/AutoCAD-ActiveX/files/GUID-26C95029-14BB-40B9-9987-49EFC980CB9D-htm.html
    (setq lin (vlax-invoke space 'addline (car lst) (cadr lst)) ;_ end of VLA-ADDLINE
    ) ;_ end of setq
    (setq ds      (vla-get-length lin)
          startpt (vlax-get lin 'startpoint)
          endpt   (vlax-get lin 'endpoint)
          midpt   (polar endpt (angle endpt startpt) (/ (distance endpt startpt) 2.0))
          ;; RJP - fixed multiple errors in line below
          ;;https://knowledge.autodesk.com/search-result/caas/CloudHelp/cloudhelp/2015/ENU/AutoCAD-ActiveX/files/GUID-9D3A7DE5-4219-42D8-A2A2-20C723F01ABC-htm.html
          ; str     (vla-addtext space (rtos ds 2 2) (vlax-3d-point midpt) 1.0)
    ) ;_ end of setq
    (vla-put-rotation str (angle startpt endpt))
    ;; RJP - Remove the first item
    (setq lst (cdr lst))
  ) ;_ end of while
  (princ)
  lin
) ;_ end of defun
(SETQ USERLINE (dst (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))) (LIST (SETQ PT1 (GETPOINT)) (setq pt2dir (getpoint pt1 "\nPick Direction point \n")) )))
(vla-delete userline)



per the swamp https://www.theswamp.org/index.php?topic=54565.0

0 Likes