Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Draw a line lisp

19 REPLIES 19
SOLVED
Reply
Message 1 of 20
a.tawkXHKN6
8190 Views, 19 Replies

Draw a line lisp

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.

 

19 REPLIES 19
Message 2 of 20
Kent1Cooper
in reply to: a.tawkXHKN6


@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
Message 3 of 20
devitg
in reply to: Kent1Cooper

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

Message 4 of 20
a.tawkXHKN6
in reply to: devitg

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

Message 5 of 20
a.tawkXHKN6
in reply to: Kent1Cooper

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

Message 6 of 20
devitg
in reply to: a.tawkXHKN6

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

 

 

 

Message 7 of 20
a.tawkXHKN6
in reply to: a.tawkXHKN6

It's giving an error while using it in AutoCAD



Message 8 of 20
devitg
in reply to: a.tawkXHKN6

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

 

 

Message 9 of 20
Kent1Cooper
in reply to: devitg

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
Message 10 of 20
ВeekeeCZ
in reply to: a.tawkXHKN6

Try THIS Lees version. Also using grread. 

Message 11 of 20
ВeekeeCZ
in reply to: devitg


@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 🙂 

Message 12 of 20
pbejse
in reply to: a.tawkXHKN6


@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

 

 

 

 

Message 13 of 20
ВeekeeCZ
in reply to: pbejse

👍 

1+1... how easy is that.

Message 14 of 20
pbejse
in reply to: ВeekeeCZ


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

 

 

 

Message 15 of 20
Kent1Cooper
in reply to: pbejse


@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
Message 16 of 20
pbejse
in reply to: Kent1Cooper


@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)
)

 

Message 17 of 20
ВeekeeCZ
in reply to: pbejse

...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)
  )
Message 18 of 20
Kent1Cooper
in reply to: Kent1Cooper


@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
Message 19 of 20
Sea-Haven
in reply to: a.tawkXHKN6

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

Message 20 of 20
sporter2B74A
in reply to: a.tawkXHKN6

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report