draw line continuously

draw line continuously

nychoe1
Advocate Advocate
1,492 Views
4 Replies
Message 1 of 5

draw line continuously

nychoe1
Advocate
Advocate

hello, good luck for you everyone.

I am making a lsp of that draw line continuously.

first, start point and then click for direction, and then input line length

but it so difficult and help.

 

(defun c:lin (/ p1 p2)
  (defun rtd (a) (* 180.0 (/ a pi))) 
  (if (= dirang nil)(setq dirang 0))
  (if (= dirlen nil)(setq dirlen 0))
  (setq p1 (getpoint (strcat "\nstart point :")))
(while
  (if (/= p1 nil)
      (setq p2 (getpoint (getvar "lastpoint") "\npoint for direction :"))
  )
  (setq dirlens-x (getdist (strcat "\nline length : ")))
  (if (numberp dirlens-x)(setq dirlen dirlens-x))
  (if (/= p2 nil)
      (setq ang (angle (getvar "lastpoint") p2)
            dirang (rtd ang)
      )
  )
  (command "line" p1 (strcat "@" (rtos dirlen 2 1) "<" (rtos dirang)))
)
  (princ)
)

 

attached file. I want to make like this.

 

0 Likes
1,493 Views
4 Replies
Replies (4)
Message 2 of 5

ВeekeeCZ
Consultant
Consultant

Try this...

It's a little confusing with a regular workflow.... different visual by dashed line might little help.

 

(defun c:DLLine ( / p1 p2 len)

  (if (setq p1 (getpoint "\nSpecify first point: "))
    (while (setq p2 (getpoint p1 "\nSpecify point for direction: "))
      (if (and (not (initget 7))
	       (setq len (getdist "\nSpecify length: "))
	       (setq p2 (polar p1 (angle p1 p2) len)))
	(command "_.LINE" "_none" p1 "_none" (setq p1 p2) ""))))
  (princ)
)

 

or little improved by ability to accept the current length.

 

Spoiler
(defun c:DLLine2 ( / p1 p2 len)

  (if (setq p1 (getpoint "\nSpecify first point: "))
    (while (setq p2 (getpoint p1 "\nSpecify point for direction: "))
      (if (and (not (initget 4))
	       (setq len (cond ((getdist (strcat "\nSpecify length <" (rtos (distance p1 p2) 2 2) ">: ")))
			       ((distance p1 p2))))
	       (setq p2 (polar p1 (angle p1 p2) len)))
	(command "_.LINE" "_none" p1 "_none" (setq p1 p2) ""))))
  (princ)
)
Message 3 of 5

nychoe1
Advocate
Advocate

wow, so simple.

thank you for your help. good luck

0 Likes
Message 4 of 5

Kent1Cooper
Consultant
Consultant

@nychoe1 wrote:

....

I am making a lsp of that draw line continuously.

first, start point and then click for direction, and then input line length

....


I'm not sure you need a routine to do that.  If you are in a Line command where it's asking for the next point, you can just "aim" the cursor in the right direction [i.e. position the cursor at the point where you would pick for the direction, but without picking it], and enter the length.  You can even lock onto Object-Snap locations for directional purposes, also without actually picking on them.  That works when drawing anything, so you could draw a Polyline as a single object that way, rather than being limited to only making it as separate Lines.

 

The only advantage I see to something like your attempt or BeekeeCZ's suggestion is that you have the option [if you would ever want to use it] to specify each distance by picking two points on-screen independent of [and not necessarily even in the general vicinity of] the Line(s) you're drawing, rather than always typing in a distance.  But given what's in the image, I would think you typically know the distances as numerical values ahead of time anyway, so typing them in would be the norm.

Kent Cooper, AIA
0 Likes
Message 5 of 5

john.uhden
Mentor
Mentor

As Stephan Koster taught us years ago, the IF function is highly overrated.  Instead you can just use AND as it will stop on the first evaluation that is nil...

 

(and
(not (initget 7)) (setq len (getdist "\nSpecify length: ")) (setq p2 (polar p1 (angle p1 p2) len))) (vl-cmdf "_.LINE" "_none" p1 "_none" (setq p1 p2) ""))))

John F. Uhden

0 Likes