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
  • Agree 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)
))

 

  • Like 1
  • 2 weeks later...
Posted

@Dayananda

Is something like this what you're actually after?

It has the advantage of only picking the line instead of picking two points.

(defun c:redlines ( / *error*  make:line
                      linesset line linelist linelisteach lineinfo linest lineen linean linedt)
  
  (defun *error* ( rramsg )
    (if (not (member rramsg '("Function cancelled" "quit / exit abort")))
        (princ (strcat "\nError: " rramsg))
    )
    (command-s "_.UNDO" "_END")
  );(defun)*error*
  
  (defun make:line ( lpt1 lpt2 )
    (entupd
      (entmakex
        (list
    	    (cons 0 "LINE")
    	    (cons 10 lpt1);starting point
    	    (cons 11 lpt2);ending point
        );(list)
      );(entmakex)
    );(entupd)
  );(defun), make:line
  
  (setq linesset (ssget (list '(0 . "LINE"))));creates the selection set using standard autocad selection procedures
  (command "_.UNDO" "_BEGIN")
  (if linesset
    (repeat (setq line (sslength linesset));get the number of items in the selection set and use as counter for repeat
      (setq linelist (cons (ssname linesset (setq line (1- line))) linelist));set variable to new list
      ;move throught the sset (ssname), index no. is from sslength, (cons) construct the list and then set it
    );(repeat), from Lee Mac
  );(if) Lee Mac create a list for processing from the selection set
  (foreach linelisteach linelist ;for each line (linelisteach) of each entity in the selection set list (linelist)
    (setq lineinfo (entget linelisteach));get the entity data as a list
    (setq linest (cdr (assoc 10 lineinfo)))
    (setq lineen (cdr (assoc 11 lineinfo)))
    (setq linean (angle linest lineen))
    (setq linedt (distance linest lineen))
    (cond
      ( ;0 degrees subfunction
        (equal linean (* pi 0.0) 0.001);0 degrees
        (make:line 
          (list    (nth 0 linest)                 (+ (nth 1 linest) 5) (nth 2 linest))
          (list (+ (nth 0 linest) (* 0.3 linedt)) (+ (nth 1 linest) 5) (nth 2 linest))
        )
      ) ;0 degrees subfunction
      ( ;90 degrees subfunction
        (equal linean (* pi 0.5) 0.001);90 degrees
        (make:line 
          (list (- (nth 0 linest) 5)    (nth 1 linest)                 (nth 2 linest))
          (list (- (nth 0 linest) 5) (+ (nth 1 linest) (* 0.3 linedt)) (nth 2 linest))
        )
      ) ;90 degrees subfunction
      ( ;180 degrees subfunction
        (equal linean (* pi 1.0) 0.001);180 degrees
        (make:line 
          (list    (nth 0 linest)                 (+ (nth 1 linest) 5) (nth 2 linest))
          (list (- (nth 0 linest) (* 0.3 linedt)) (+ (nth 1 linest) 5) (nth 2 linest))
        )
      ) ;180 degrees subfunction
      ( ;270 degrees subfunction
        (equal linean (* pi 1.5) 0.001);270 degrees
        (make:line 
          (list (- (nth 0 linest) 5)    (nth 1 linest)                 (nth 2 linest))
          (list (- (nth 0 linest) 5) (- (nth 1 linest) (* 0.3 linedt)) (nth 2 linest))
        )
      ) ;270 degrees subfunction
    );(cond)
  );(foreach)
);(defun)

 

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