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.
Solved! Go to Solution.
Solved by pbejse. Go to Solution.
Solved by devitg. Go to Solution.
@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.
@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 .
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.
@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
@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.
@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)
)
...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 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?
Line pick 1st point drag mouse then type 100,000. With ortho on will draw square on the X Y axis no code required.
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.