Author Topic: Generate a Pline from a list of points?  (Read 12245 times)

0 Members and 2 Guests are viewing this topic.

Shade

  • Guest
Generate a Pline from a list of points?
« on: March 02, 2006, 12:55:46 PM »
How does one generate a polyline from a list of points?
The number of points in my list may vary at different times.

Any help would be appreciated.
 :-)

T.Willey

  • Needs a day job
  • Posts: 5218
Re: Generate a Pline from a list of points?
« Reply #1 on: March 02, 2006, 01:04:56 PM »
Code: [Select]
(command "_.pline")
(foeach pt PtList)
 (command pt)
)
(comamnd "")
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Jeff_M

  • King Gator
  • Posts: 3944
  • C3D user & customizer
Re: Generate a Pline from a list of points?
« Reply #2 on: March 02, 2006, 01:08:59 PM »
One way:
Code: [Select]
(setq ptlist '((0.0 0.0)(10.0 0.0)(10.0 10.0)(20.0 10.0)))
(command "pline")
(mapcar '(lambda (x)
   (command x)
   )
ptlist)
(command "")

MP

  • Seagull
  • Posts: 17454
Re: Generate a Pline from a list of points?
« Reply #3 on: March 02, 2006, 01:18:28 PM »
Modified from this post --

Code: [Select]
(apply 'command
    (append
       '(".pline")
        points
       '("")
    )
)

Of course there's always the entmake / activex route too ... :)
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox

Shade

  • Guest
Re: Generate a Pline from a list of points?
« Reply #4 on: March 02, 2006, 02:06:59 PM »
Thanks everyone, I will give it a try.

 :-)

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1540
  • Moscow (Russia)
Re: Generate a Pline from a list of points?
« Reply #5 on: March 03, 2006, 03:35:59 AM »
Code: [Select]
(entmakex
  (append
    (list
      '(0 . "LWPOLYLINE")
      '(100 . "AcDbEntity")
      '(100 . "AcDbPolyline")
      (cons 90 (length lst))
      '(70 . 1)
    ) ;_  list
    (mapcar '(lambda (x) (cons 10 x)) lst)
  ) ;_  append
)
蝸牛そろそろ登れ富士の山 /Kobayashi Issa/

snoopychen

  • Guest
Re: Generate a Pline from a list of points?
« Reply #6 on: March 03, 2006, 09:29:55 AM »
how can I generate the pline with a different width of the last segment from a list of points, I cant change the width when the command PL function was processing.

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1540
  • Moscow (Russia)
Re: Generate a Pline from a list of points?
« Reply #7 on: March 03, 2006, 09:45:30 AM »
how can I generate the pline with a different width of the last segment from a list of points, I cant change the width when the command PL function was processing.

 
Code: [Select]
;**************** lw_width.lsp *********************************
  ; Change of initial and final width
  ; The arbitrary segment of a polyline.
  ; Writer Evgeniy Elpanov.

       (defun C:LW_WIDTH (/ ENDWIDTH GR LW PAR STARTWIDTH)
         (vl-load-com)
         (vla-StartUndoMark (vla-get-activedocument (vlax-get-acad-object)))
         (setq lw (entsel "\n Select the necessary segment in a polyline. "))
         (if (and lw (= (cdr (assoc 0 (entget (car lw)))) "LWPOLYLINE"))
           (progn
             (setq par (vlax-curve-getParamAtPoint (car lw)
                                                   (vlax-curve-getClosestPointTo (car lw) (cadr lw))
                       ) ;_  vlax-curve-getParamAtPoint
                   lw  (vlax-ename->vla-object (car lw))
             ) ;_  setq
             (princ "\n Set width of the beginning of a segment.\t")
             (vla-GetWidth lw (fix par) 'StartWidth 'EndWidth)
             (while (and (setq gr (grread 5)) (= (car gr) 5))
               (vla-SetWidth lw
                             (fix par)
                             (setq StartWidth (* (distance (cadr gr)
                                                           (vlax-curve-getClosestPointTo lw (cadr gr))
                                                 ) ;_  distance
                                                 2.
                                              ) ;_  *
                             ) ;_  setq
                             EndWidth
               ) ;_  vla-SetWidth
             ) ;_  while
             (if (= (car gr) 2)
               (vla-SetWidth lw
                             (fix par)
                             (setq StartWidth (atof (strcat (princ (vl-list->string (cdr gr)))
                                                            (getstring)
                                                    ) ;_  strcat
                                              ) ;_  atof
                             ) ;_  setq
                             EndWidth
               ) ;_  vla-SetWidth
             ) ;_  if
             (princ "\n Set width of the extremity of a segment.\t")
             (while (and (setq gr (grread 5)) (= (car gr) 5))
               (vla-SetWidth lw
                             (fix par)
                             StartWidth
                             (* (distance (cadr gr)
                                          (vlax-curve-getClosestPointTo lw (cadr gr))
                                ) ;_  distance
                                2.
                             ) ;_  *
               ) ;_  vla-SetWidth
             ) ;_  while
             (if (= (car gr) 2)
               (vla-SetWidth lw
                             (fix par)
                             StartWidth
                             (atof (strcat (princ (vl-list->string (cdr gr))) (getstring)))
               ) ;_  vla-SetWidth
             ) ;_  if
           ) ;_  progn
           (princ "\n It is elected nothing or object not a polyline.\t")
         ) ;_  if
         (vla-EndUndoMark (vla-get-activedocument (vlax-get-acad-object)))
         (princ)
       ) ;_  defun
; for the button:
Code: [Select]
^C^C^P(if (not C:lw_width) (load "lw_arc")) lw_width
PS. Modify =>  formatting the code
« Last Edit: March 04, 2006, 09:55:05 AM by ElpanovEvgeniy »
蝸牛そろそろ登れ富士の山 /Kobayashi Issa/

LE

  • Guest
Re: Generate a Pline from a list of points?
« Reply #8 on: March 03, 2006, 11:46:27 AM »
I do not see in the samples provided [bulge] curve.... wonder if allways those polylines will be straight...


Correction s for a d
« Last Edit: March 04, 2006, 12:12:53 PM by LE »

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1540
  • Moscow (Russia)
Re: Generate a Pline from a list of points?
« Reply #9 on: March 04, 2006, 04:27:26 AM »
I do not see in the samples provides [bulge] curve.... wonder if allways those polylines will be straight...
Example - change of curvature visual (line segment => arc segment)
 
Code: [Select]
;**************** lW_arc.lsp *************************************
  ;   Substitution of a linear segment in a polyline
  ;   The arc segment.
  ;   Writer Evgeniy Elpanov.
(defun C:LW_ARC (/ A1 ENT GR I LST LW PAR PT)
  (vl-load-com)
  (vla-StartUndoMark (vla-get-activedocument (vlax-get-acad-object)))
  (setq lw (entsel "\n Select the necessary segment in a polyline. "))
  (if (and lw (= (cdr (assoc 0 (entget (car lw)))) "LWPOLYLINE"))
    (progn (setq par (vlax-curve-getParamAtPoint (car lw)
                                                 (vlax-curve-getClosestPointTo (car lw) (cadr lw))
                     ) ;_  vlax-curve-getParamAtPoint
                 a1  (angle (vlax-curve-getPointAtParam (car lw) (fix par))
                            (vlax-curve-getPointAtParam (car lw) (1+ (fix par)))
                     ) ;_  angle
           ) ;_  setq
           (princ "\n Set visually a curvature of a segment. ")
           (while (and (setq gr (grread 5)) (= (car gr) 5))
             (setq i   0
                   lst nil
                   ent (entget (car lw))
             ) ;_  setq
             (while (or (/= (caar ent) 42)
                        (if (< i (fix par))
                          (setq i (1+ i))
                        ) ;_  if
                    ) ;_  or
               (setq lst (cons (car ent) lst)
                     ent (cdr ent)
               ) ;_  setq
             ) ;_  while
             (redraw)
             (grdraw (setq pt (vlax-curve-getPointAtParam
                                (car lw)
                                (fix par)
                              ) ;_  vlax-curve-getPointAtParam
                     ) ;_  setq
                     (cadr gr)
                     6
                     1
             ) ;_  grdraw
             (entmod (append (reverse (cons (cons 42
                                                  (/ (sin (/ (- a1 (angle pt (cadr gr))) 2.))
                                                     (cos (/ (- a1 (angle pt (cadr gr))) 2.))
                                                  ) ;_  /
                                            ) ;_  cons
                                            lst
                                      ) ;_  cons
                             ) ;_  reverse
                             (cdr ent)
                     ) ;_  append
             ) ;_  entmod
             (entupd (car lw))
           ) ;_  while
    ) ;_  progn
    (princ "\n It is selected nothing or plant not a polyline. ")
  ) ;_  if
  (vla-EndUndoMark (vla-get-activedocument (vlax-get-acad-object)))
  (redraw)
  (princ)
) ;_  defun
; for the button:
Code: [Select]
^C^C^P(if (not C:LW_ARC) (load "lw_arc")) LW_ARC
PS. Modify =>  formatting the code
« Last Edit: March 04, 2006, 09:51:54 AM by ElpanovEvgeniy »
蝸牛そろそろ登れ富士の山 /Kobayashi Issa/

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1540
  • Moscow (Russia)
Re: Generate a Pline from a list of points?
« Reply #10 on: March 04, 2006, 05:01:39 AM »
Generate a Pline from a list of points and bulge

If you have (and lst-pt lst-bulge):
Code: [Select]
(if (and (setq en (car (entsel)))
         (= (cdr (assoc 0 (entget en))) "LWPOLYLINE")
    ) ;_  and
  (setq lst-pt    (mapcar (function cdr)
                          (vl-remove-if-not (function (lambda (a) (= (car a) 10))) (entget en))
                  ) ;_  mapcar
        lst-bulge (mapcar (function cdr)
                          (vl-remove-if-not (function (lambda (a) (= (car a) 42))) (entget en))
                  ) ;_  mapcar
  ) ;_  setq
) ;_  if

Example:
Code: [Select]
(entmakex
  (apply
    (function append)
    (cons
      (list
        '(0 . "LWPOLYLINE")
        '(100 . "AcDbEntity")
        '(67 . 0)
        '(410 . "Model")
        '(8 . "New_polyline")
        '(62 . 3)
        '(100 . "AcDbPolyline")
        (cons 90 (length lst-pt))
        '(70 . 0)
        ;;'(70 . 1) = Closed
      ) ;_  list
      (mapcar
        (function list)
        (mapcar (function (lambda (a) (cons 10 a))) lst-pt)
        (mapcar (function (lambda (a) (cons 42 a))) lst-bulge)
      ) ;_  mapcar
    ) ;_  cons
  ) ;_  apply
) ;_  entmakex

>LE
I have answered your question?
蝸牛そろそろ登れ富士の山 /Kobayashi Issa/

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Generate a Pline from a list of points?
« Reply #11 on: March 04, 2006, 05:10:10 AM »
Evgeniy,

nice code .. which version of ACad do you use ?

I like the dynamic visual ARC routine !

Thanks for formatting the code .. much easier to read :-)

be well
kerry
« Last Edit: March 04, 2006, 05:14:11 AM by Kerry Brown »
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate to theSwamp<--

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1540
  • Moscow (Russia)
Re: Generate a Pline from a list of points?
« Reply #12 on: March 04, 2006, 05:22:17 AM »
Evgeniy,

nice code .. which version of ACad do you use ?

I like the dynamic visual ARC routine !

Thanks for formatting the code .. much easier to read :-)

be well
kerry
AutoCad 2004 en
 :-)
蝸牛そろそろ登れ富士の山 /Kobayashi Issa/

LE

  • Guest
Re: Generate a Pline from a list of points?
« Reply #13 on: March 04, 2006, 10:58:50 AM »
Generate a Pline from a list of points and bulge

If you have (and lst-pt lst-bulge):
Code: [Select]
) ;_  entmakex

>LE
I have answered your question?

Not exactly... I have not tested your code.... I was talking of just pure list of points..... and from them generate the pline... I will post a sample ... give me some minutes... and I need my first coffee...

I see you know very well LISP... where are you from?

==
Luis Esquivel

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1540
  • Moscow (Russia)
Re: Generate a Pline from a list of points?
« Reply #14 on: March 04, 2006, 11:03:00 AM »
where are you from?

   Moscow, Russia
蝸牛そろそろ登れ富士の山 /Kobayashi Issa/