Jump to content

Choose points and connect them with a line


Burrr

Recommended Posts

Hey guys, I have a task to do with lisp. 

So I want to choose 3 points (getpoint) in autoCAD, connect them with a closed line and define the points with the pointstyle 33 (pdmode).

 

My "coding" so far:

 

(
defun c:punktverb ()
;
; LISP fragt nacheinander drei Punkte ab und stellt sie als geschlossenen Linienzug dar mit dem Punkstil 33
(alert "Geben Sie drei Punkte ein")

; Eingabe von Punkten

 

(setq p1 (getpoint "Eingabe von Punkt 1"))
(setq p2 (getpoint "Eingabe von Punkt 2"))
(setq p3 (getpoint "Eingabe von Punkt 3"))

(setq x1 (nth 0 p1)
      y1 (nth 0 p1)
      x2 (nth 0 p2)
      y2 (nth 0 p2)
      x3 (nth 0 p3)
      y3 (nth 0 p3))
      
      (command "_line" (list x1 y1) (list x2 y2) (list x3 y3)"")
      

So my problem is, after I choosed the three points in CAD, I get a line, but the line is straight and dont lies on the points. In addition the line isnt a straight line, its splitted in two.

I appreciate every help
      

 

Link to comment
Share on other sites

Hi,

Simple codes for you to learn from.

(defun c:punktverb ( / p1 p2 p3)
  (and (setq p1 (getpoint "Eingabe von Punkt 1"))
       (setq p2 (getpoint "Eingabe von Punkt 2"))
       (setq p3 (getpoint "Eingabe von Punkt 3"))
       (entmake (list '(0 . "LINE") (cons 10 p1) (cons 11 p2)))
       (entmake (list '(0 . "LINE") (cons 10 p2) (cons 11 p3)))
       (entmake (list '(0 . "LINE") (cons 10 p3) (cons 11 p1)))
       )
  (princ)
  )

 

Link to comment
Share on other sites

Just for fun

 

; LISP fragt nacheinander drei Punkte ab und stellt sie als geschlossenen Linienzug dar mit dem Punkstil 33

(defun c:punktverb ( / mygetpoint lst p_lst cnt)
  (alert "Geben Sie drei Punkte ein")

  (defun mygetpoint (p_txt / pt )
    (setq pt (getpoint (strcat "\nEingabe von Punkt " p_txt " : ")))
    (entmake (list (cons 0 "POINT") (cons 10 pt)))
    pt
  );end_defun
  
  (setvar 'pdmode 33)
  (setq lst (list "1" "2" "3"))
  (mapcar '(lambda (x) (setq p_lst (cons (mygetpoint x) p_lst))) lst)
  (setq p_lst (reverse (cons (last p_lst) p_lst))
	cnt 0
  );end_setq
  (repeat (1- (length p_lst))
    (entmake (list '(0 . "LINE") (cons 10 (nth cnt p_lst)) (cons 11 (nth (1+ cnt) p_lst))))
    (setq cnt (1+ cnt))
  );end_repeat
  (princ)
);end_defun

 

Edited by dlanorh
Link to comment
Share on other sites

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