Jump to content

Recommended Posts

Posted

I am trying to draw Following type of figure attached. When I am picking 2 points up to down, Down to up Left to right or right to left the red line should be in the correct position. I have written the following lisp codes. But it does not function correctly. Please help me to do this task.

 (setq b_p1 (getpoint "\nPick on 1st beam cl"))
 (setq b_p2 (getpoint b_p1"\nPick 2nd beam cl " ))

(command "line""non"b_p1 "non"b_p2 ""); line bottom part
(setq line1(entlast))

(setq spane1 (distance b_p1  b_p2));;; 1st span
(setq crnkL (* 0.3  spane1));; top line length
(setq gap 200);; gap between top and bottom part of line
(setq angle1 (angle b_p1 b_p2)); angle of line 1 in radiance

(if(and(>= angle1 0 )(<= angle1 (/ pi 2 ))) 
(setq angle2 (+ angle1(/  pi 2)));; angle to point b_p1 from t_p1
); if

 (if(and(>= angle1 (/ pi 2 ) )(<= angle1 pi)) 
(setq angle2 (+ angle1(/  pi 2)));; angle to point b_p1 from t_p1
); if 
    
(setq t_p1 (polar b_p1  angle2 gap )) 
(setq t_p2 (polar t_p1  angle1 crnkL )) 
(command "line""non"t_p1 "non"t_p2 "")

 

lines.PNG

Posted (edited)

How about something like this, is that what you are looking for?

(defun draw (pt1 pt2 len)
  (if (and pt1 pt2 len)
    (progn
      (entmakex
        (list
          '(0 . "LINE")
          (cons 10 pt1)
          (cons 11 (polar pt1 (angle pt1 pt2) len))
        )
      )
      (entmakex
        (list
          '(0 . "LINE")
          (cons 10 (polar pt2 (angle pt2 pt1) len))
          (cons 11 pt2)
        )
      )
    )
  )
  (princ)
)

(draw
  (getpoint "\nFirst point: ")
  (getpoint "\nSecond point: ")
  (getdist "\nLine Length: ")
)
Edited by dexus
  • Like 1
Posted

This ? in dynamic mode...

((lambda ( / pt1 pt2 gap)
  (initget 1)
  (setq
    pt1 (getpoint "\nPick on 1st beam cl: ")
    pt2 pt1
    gap 200
  )
  (while (equal pt2 pt1)
    (setq pt2
      ((lambda ( / key pt alpha spane crnkL p1 p2)
        (princ "\nPick 2nd beam cl: ")
        (while (and (setq key (grread T 4 0)) (/= (car key) 3))
          (cond
            ((eq (car key) 5)
              (redraw)
              (setq pt (cadr key))
              (setq alpha (angle pt1 pt))
              (setq spane (distance pt1 pt))
              (setq crnkL (* 0.3 spane))
              (cond 
                ((and (>= alpha 0.0) (< alpha (* pi 0.5)))
                  (setq
                    p1 (polar pt (+ alpha ( * 0.5 pi)) gap)
                    p2 (polar p1 (+ alpha pi) crnkL)
                  )
                )
                ((and (>= alpha (* pi 0.5)) (< alpha pi))
                  (setq
                    p1 (polar pt (+ alpha ( * 0.5 pi)) gap)
                    p2 (polar p1 (+ alpha pi) crnkL)
                  )
                )
                ((and (>= alpha pi) (< alpha (* 0.75 pi)))
                  (setq
                    p1 (polar pt (- alpha ( * 0.5 pi)) gap)
                    p2 (polar p1 (+ alpha pi) crnkL)
                  )
                )
                (T
                  (setq
                    p1 (polar pt (- alpha ( * 0.5 pi)) gap)
                    p2 (polar p1 (+ alpha pi) crnkL)
                  )
                )
              )
              (grdraw pt1 pt 3)
              (grdraw p1 p2 1)
            )
          )
        )
        (redraw)
        (cadr key)
      ))
    )
  )
  (prin1)
))

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...