Polyline with two points with stretch from one end and trim from the other

Polyline with two points with stretch from one end and trim from the other

Anonymous
Not applicable
1,462 Views
5 Replies
Message 1 of 6

Polyline with two points with stretch from one end and trim from the other

Anonymous
Not applicable

Hi.

I am looking for two lisps actually.

1. Draw two polylines by selecting two points 'A' and 'B'. These polylines have same length but mirrored from the center of two points and spaced a certain distance apart, say 400mm. The polylines are stretched 75mm from point A and trimmed 0.15*dist. between two points.

2. Draw three polylines by selecting three points 'A', 'B' and 'C' having a certain distance and certain length from the 2nd point. All three polylines must be centered between Point 'B' and point 'C'. For example, the length of longest polyline is (0.3*L + dist. between point 'B' and point 'C' + 0.3*L) The situation is illustrated in the figure.

I thank you in advance to all of you who would take some time to help me in this. Hats off to you!

LISP1.pngLISP2.jpg

0 Likes
Accepted solutions (2)
1,463 Views
5 Replies
Replies (5)
Message 2 of 6

Moshe-A
Mentor
Mentor
Accepted solution

@Anonymous  hi,

 

here is my version

 

enjoy

moshe

 

(defun c:lisp1 (/ p0 p1 t0 t1 i)
  
 (if (and
       (setq p0 (getpoint "\nSpecify point A: "))
       (setq p1 (getpoint p0 "\nSpecify point B: "))
     )
  (progn 
   (setq i 0 t0 p0 t1 p1)
   (repeat 2
    (setq t0 (list (car t0) (+ (cadr t0) (* i 400.0))))
    (setq t1 (list (car t1) (+ (cadr t1) (* i 400.0))))
     
    (command "._line"
"_none" (polar t0 (angle t1 t0) 75.0) "_none" (polar t1 (angle t1 t0) (* (distance p0 p1) 0.15)) "") (setq i (1+ i) t0 p1 t1 p0) ) ); progn ); if (princ) ) (defun c:lisp2 (/ p0 p1 p2 p3 p4 cap len i) (if (and (setq p0 (getpoint "\nSpecify point A: ")) (setq p1 (getpoint p0 "\nSpacify point B: ")) (setq p2 (getpoint p0 "\nSpecify point C: ")) ) (progn (setq cap (distance p1 p2)) (setq len (distance p0 p1)) (setq p3 (polar p1 (angle p1 p2) (/ (distance p1 p2) 2))) (setq i 1) (foreach edge '(0.22 0.20 0.30) (setq p4 (polar p3 (/ pi 2) (* i 400.0))) (command "._line" "_none" (polar p4 (angle p0 p1) (+ (/ cap 2) (* len edge))) "_none" (polar p4 (angle p1 p0) (+ (/ cap 2) (* len edge))) "") (setq i (1+ i)) ); foreach ); progn ); if (princ) )
0 Likes
Message 3 of 6

Anonymous
Not applicable

Thank you so much! Works perfectly. You have saved a lot of my time now. Thanks once again Smiley Happy

0 Likes
Message 4 of 6

Anonymous
Not applicable

Hey thank you once again. The program runs perfectly in horizontal direction. But, when I try to draw vertically, it doesn't give the exact lines. I'm sorry I don't have any knowledge of LISP, so I don't know how to edit it. Cheers!

0 Likes
Message 5 of 6

Moshe-A
Mentor
Mentor
Accepted solution

fixed

 

(defun ma:qang (a)
 (cond
  ((or
    (equal a 0.0 1e-3)
    (equal a pi 1e-4)
    (equal a (* pi 2) 1e-3)
   )
   (/ pi 2)
  )
  ((or
    (equal a (/ pi 2) 1e-3)
    (equal a (* pi 1.5) 1e-3)
   )
   pi
  )
 ); cond
); qang



(defun c:lisp1 (/ p0 p1 t0 t1 i x0 x1)
 (setvar "cmdecho" 0)
 (command "._undo" "_begin")
  
 (if (and
       (setq p0 (getpoint "\nSpecify point A: "))
       (setq p1 (getpoint p0 "\nSpecify point B: "))
     )
  (progn 
   (setq i 0 t0 p0 t1 p1)
   (repeat 2
    (setq x0 (polar t0 (ma:qang (angle t0 t1)) (* i 400.0)))
    (setq x1 (polar t1 (ma:qang (angle t0 t1)) (* i 400.0)))
     
    (command "._line" "_none" (polar x0 (angle x1 x0) 75.0)
	              "_none" (polar x1 (angle x1 x0) (* (distance x0 x1) 0.15))
	     "")
    (setq i (1+ i) t0 x1 t1 x0)
   )
  ); progn
 ); if

 (command "._undo" "_end")
 (setvar "cmdecho" 1)
  
 (princ)
)


(defun c:lisp2 (/ p0 p1 p2 p3 p4 colHead len)
 (setvar "cmdecho" 0)
 (command "._undo" "_begin")
  
 (if (and
       (setq p0 (getpoint "\nSpecify point A: "))
       (setq p1 (getpoint p0 "\nSpacify point B: "))
       (setq p2 (getpoint p0 "\nSpecify point C: "))
     )
  (progn
   (setq colHead (distance p1 p2))
   (setq len (distance p0 p1))
   (setq p3 (polar p1 (angle p1 p2) (/ (distance p1 p2) 2)))

   (setq i 1)
   (foreach edge '(0.22 0.20 0.30)
    (setq p4 (polar p3 (ma:qang (angle p0 p1)) (* i 400.0))) 
    (command "._line"
	    (polar p4 (angle p0 p1) (+ (/ colHead 2) (* len edge)))
	    (polar p4 (angle p1 p0) (+ (/ colHead 2) (* len edge)))
	    "")
    (setq i (1+ i))
   ); foreach
  ); progn
 ); if
  
 (command "._undo" "_end")
 (setvar "cmdecho" 1)

 (princ)
)
0 Likes
Message 6 of 6

Anonymous
Not applicable

Thank you so much. Now it works just perfectly Smiley Happy

0 Likes