Author Topic: To make a poly on the fly  (Read 3763 times)

0 Members and 1 Guest are viewing this topic.

DEVITG

  • Bull Frog
  • Posts: 481
To make a poly on the fly
« on: August 31, 2009, 03:51:10 PM »
What is the way to make a polyline on the fly by lisp

I remember some like comandactive or so on but I can not find it.
Thanks
(command "_pline"  then allow me to pick as many point as I want.




Location @ Córdoba Argentina Using ACAD 2019  at Window 10

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: To make a poly on the fly
« Reply #1 on: August 31, 2009, 03:54:48 PM »
Code: [Select]
(command "_.pline")
(while (> (getvar "CMDACTIVE") 0)
  (command pause))
(command)

DEVITG

  • Bull Frog
  • Posts: 481
Re: To make a poly on the fly
« Reply #2 on: August 31, 2009, 03:55:51 PM »
Code: [Select]
(command "_.pline")
(while (> (getvar "CMDACTIVE") 0)
  (command pause))
(command)

Thanks
That was
Location @ Córdoba Argentina Using ACAD 2019  at Window 10

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: To make a poly on the fly
« Reply #3 on: August 31, 2009, 03:57:07 PM »
No probs dude  8-)

DEVITG

  • Bull Frog
  • Posts: 481
Re: To make a poly on the fly
« Reply #4 on: August 31, 2009, 04:05:18 PM »
There is any way to sum the distance between points while in the WHILE?
I want to know the polyline length, on the fly too.

Of course It can be get after doing the poly by (entlast)
and by the vlax-curvexxx

Location @ Córdoba Argentina Using ACAD 2019  at Window 10

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: To make a poly on the fly
« Reply #5 on: August 31, 2009, 04:07:57 PM »
You could just use the distance function to calculate the distance between successive points, but you may need to rework the while loop you are using.

DEVITG

  • Bull Frog
  • Posts: 481
Re: To make a poly on the fly
« Reply #6 on: August 31, 2009, 04:13:33 PM »
I try it so

 
Code: [Select]
(setvar "cmdecho" 1)
(setq distancia 0)
 (setq pt1 (getpoint "\nInicio: "))
(command "_.pline")
(while (> (getvar "CMDACTIVE") 0)
  (command pause)
  (setq pt2 (getvar 'lastpoint ))
  (setq dist (distance pt1 pt2))
(setq pt1 pt2)
(setq distancia ( + distancia dist))
  )
(command)
But do not work

neither it


 
Code: [Select]
(setvar "cmdecho" 1)
(setq distancia 0)
 (setq pt1 (getpoint "\nInicio: "))
(command "_.pline" )
(while (> (getvar "CMDACTIVE") 0)
  (setq pt2 (getvar 'lastpoint ))
  (setq dist (distance pt1 pt2))
(setq pt1 pt2)
(setq distancia ( + distancia dist))

  (command pause)
  )
(command)
Location @ Córdoba Argentina Using ACAD 2019  at Window 10

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: To make a poly on the fly
« Reply #7 on: August 31, 2009, 04:18:40 PM »
Hi

Something like this ?

Code: [Select]
(setq tot 0)
(command "_.pline" pause)
(setq pt (getvar 'lastpoint))
(while (/= 0 (getvar 'cmdactive))
  (command pause)
  (setq tot (+ tot (distance pt (setq pt (getvar 'lastpoint)))))
  (princ (strcat "\nDistencia = " (rtos tot)))
)
Speaking English as a French Frog

DEVITG

  • Bull Frog
  • Posts: 481
Re: To make a poly on the fly
« Reply #8 on: August 31, 2009, 04:22:25 PM »
Hi Lee MAc and gile , I did it work so, thanks both.
 
Code: [Select]
(defun C:CAUCE (/
;;; pt1 pt2 distancia
)
  (setvar "cmdecho" 1)
  (setvar 'OSMODE 1)
  (setq DISTANCIA 0)
  (setq PT1 (getpoint "\nInicio: "))
  (command "_.pline")
  (command PT1)
  (while (> (getvar "CMDACTIVE") 0)
    (setq PT2 (getvar 'LASTPOINT))
    (setq DIST (distance PT1 PT2))
    (setq PT1 PT2)
    (setq DISTANCIA (+ DISTANCIA DIST))
    (princ DISTANCIA)
    (command PAUSE))
  (command)
  (setq TEXTO (strcat (rtos DISTANCIA 2 3) " Km"))
  (setq PT2 (getvar 'LASTPOINT))
  (command "_text" "_c" PT2 12 0 TEXTO)
  )
« Last Edit: August 31, 2009, 04:34:28 PM by DEVITG »
Location @ Córdoba Argentina Using ACAD 2019  at Window 10

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: To make a poly on the fly
« Reply #9 on: September 01, 2009, 06:57:44 AM »
Glad you got it working in the end  :-)

You may want to add an IF statement, in case the user does not pick the first point  ;-)

curmudgeon

  • Newt
  • Posts: 194
Re: To make a poly on the fly
« Reply #10 on: September 02, 2009, 04:35:34 PM »
I really deeply prefer entmake to command.
it works programmatically like this:

Code: [Select]
(defun makepolyonthefly (/ pt pt_lst)

  (while (setq pt (getpoint "\nPick Vertex Point:  "))
    (setq pt_lst (append (list (cons 10 pt)) pt_lst)
    )
  )
  (entmake (append (list '(0 . "LWPOLYLINE")
'(100 . "AcDbEntity")
(cons 8 (getvar "CLAYER"))
'(100 . "AcDbPolyline")
(cons 90 (length pt_lst))
'(70 . 1)
;;closed polyline
   )
   pt_lst
   )
  )
)

 8-)

or to get a rubber band line:

Code: [Select]
(defun makepolyonthefly (/ pt pt_lst)

  (while
    (cond ((= pt nil)(setq pt (getpoint "\nPick Vertex Point:  ")))
  ( pt (setq pt (getpoint pt "\nPick Vertex Point:  ")))
  )
    (setq pt_lst (append (list (cons 10 pt)) pt_lst)
    )
  )
  (entmake (append (list '(0 . "LWPOLYLINE")
'(100 . "AcDbEntity")
(cons 8 (getvar "CLAYER"))
'(100 . "AcDbPolyline")
(cons 90 (length pt_lst))
'(70 . 1)
;;closed polyline
   )
   pt_lst
   )
  )
)
« Last Edit: September 02, 2009, 04:43:33 PM by curmudgeon »
Never express yourself more clearly than you are able to think.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: To make a poly on the fly
« Reply #11 on: September 03, 2009, 06:05:27 AM »
Nice idea Curmudgeon,

As an extension of that:

Code: [Select]
(defun mkpoly  (/ pt pt_lst flag gr_lst)

  (while
    (progn
      (initget "C")
      (cond (pt (setq pt (getpoint pt "\nPick Vertex Point: ")))
            ((setq pt (getpoint "\nPick Vertex Point: "))))
      (cond ((null pt) nil)
            ((eq "C" pt) (setq flag 1) nil)
            ((setq pt_lst (append pt_lst (list (cons 10 pt)))
                   gr_lst
                    (if (> (length gr_lst) 1)
                      (append gr_lst (list (last gr_lst) pt))
                        (append gr_lst (list pt)))))))
    (if (> (length gr_lst) 1)
      (grvecs (append '(-3) gr_lst))))

  (redraw)
 
  (entmake
    (append
      (list (cons 0 "LWPOLYLINE")
            (cons 100 "AcDbEntity")
            (cons 100 "AcDbPolyline")
            (cons 90 (length pt_lst))
            (cons 70 (if flag flag 0))) pt_lst)))


efernal

  • Bull Frog
  • Posts: 206
Re: To make a poly on the fly
« Reply #12 on: September 03, 2009, 09:10:53 PM »
;; good...
;; I made a change for my use...

(DEFUN mkpoly (/ pt pt_lst flag gr_lst cn)
  (SETQ cn 1)
  (WHILE
    (PROGN (INITGET "C")
      (COND (pt (SETQ
             pt (GETPOINT pt
                (STRCAT
                  "\rPick Vertex Point < "
                  (IF (> cn 2)
               (STRCAT   (ITOA (SETQ cn (1+ cn)))
                  " > or C to close : "
               )
               (STRCAT   (ITOA (SETQ cn (1+ cn)))
                  " > : "
               )
                  )
                )
           )
           )
       )
       ((SETQ pt (GETPOINT "\nPick Vertex Point < 1 > :\n")))
      )
      (COND ((NULL pt) nil)
       ((EQ "C" pt) (SETQ flag 1) nil)
       ((SETQ   pt_lst (APPEND pt_lst (LIST (CONS 10 pt)))
         gr_lst (IF (> (LENGTH gr_lst) 1)
             (APPEND gr_lst (LIST (LAST gr_lst) pt))
             (APPEND gr_lst (LIST pt))
                )
        )
       )
      )
    )
     (IF (> (LENGTH gr_lst) 1)
       (GRVECS (APPEND '(-3) gr_lst))
     )
  )
  (REDRAW)
  (ENTMAKE (APPEND (LIST (CONS 0 "LWPOLYLINE")
          (CONS 100 "AcDbEntity")
          (CONS 100 "AcDbPolyline")
          (CONS 90 (LENGTH pt_lst))
          (CONS 70
                (IF flag
             flag
             0
                )
          )
         )
         pt_lst
      )
  )
  (PRINC)
)
e.fernal

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: To make a poly on the fly
« Reply #13 on: September 04, 2009, 06:23:58 AM »
Glad you could make use of it  8-)

curmudgeon

  • Newt
  • Posts: 194
Re: To make a poly on the fly
« Reply #14 on: September 04, 2009, 09:35:30 AM »
Nice idea Curmudgeon,


I LIKE THAT!
I knew I had neglected the open polyline, I had forced it closed.

I like the way your cond flows - although I want to study it a bit more.
Thanks.

roy
Never express yourself more clearly than you are able to think.