Author Topic: quoting polyline  (Read 4507 times)

0 Members and 1 Guest are viewing this topic.

Lupo76

  • Bull Frog
  • Posts: 343
quoting polyline
« on: April 02, 2012, 10:34:54 AM »
Hello everyone,
I have to create a function that fits the dimensions along the segments of a polyline.
I have made ​​this function, but is not able to manage the arcs present in a polyline.
In fact to obtain the vertices of the polyline using the following function:

Code: [Select]
(defun vertexpoli (oggreg / coords n p listavertex)
  (vl-load-com)
  (setq coords (vla-get-coordinates (vlax-ename->vla-object oggreg)))
  (setq coords (vlax-safearray->list (vlax-variant-value coords)))
  (setq n 0)
  (setq p (list (nth n coords)  (nth (+ n 1) coords)))
 
  (repeat (/ (length coords) 2)
    (progn
      (if listavertex
        (setq listavertex (append (list p) listavertex))
        (setq listavertex (list p))
      )
      (setq n (+ n 2))
      (setq p (list (nth n coords)  (nth (+ n 1) coords)))
    )
  )
  listavertex
)

Can you give me some advice on how to implement it, add to the list, the data of the arcs?

efernal

  • Bull Frog
  • Posts: 206
Re: quoting polyline
« Reply #1 on: April 02, 2012, 12:50:41 PM »
one way:

see dxf code 42 (bulge)
find out the included angle and  divide by 2.0
find out the distance between start point and end point
use half of this distance and half of included angle to calculate radius, so length will be radius * included angle
e.fernal

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: quoting polyline
« Reply #2 on: April 03, 2012, 01:22:02 AM »
If it's just a situation of wanting points on the arc vectors or their arc lengths, then perhaps look into the vlax-curve-* functions.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

ribarm

  • Gator
  • Posts: 3279
  • Marko Ribar, architect
« Last Edit: April 03, 2012, 03:08:02 AM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

Lupo76

  • Bull Frog
  • Posts: 343
Re: quoting polyline
« Reply #4 on: April 03, 2012, 12:20:25 PM »
What to say ....  :-)
I did not think just find all this code ready!  :lmao:

Thank you!

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: quoting polyline
« Reply #5 on: April 04, 2012, 08:06:25 AM »
What to say ....  :-)
I did not think just find all this code ready!  :lmao:

Thank you!

Code - Auto/Visual Lisp: [Select]
  1. (defun test (e)
  2.   ;; (test (car(entsel)))
  3.   (vl-remove nil
  4.              (mapcar (function (lambda (a b)
  5.                                  (if (= (car a) 10)
  6.                                    (list (cdr a) (cdr b))
  7.                                  )
  8.                                )
  9.                      )
  10.                      (entget e)
  11.                      (cdddr (entget e))
  12.              )
  13.   )
  14. )

test:
Code: [Select]
(test (car(entsel)))
=>>
'(((1728.94 1778.07) 0.0)
  ((1945.34 1892.39) 0.0)
  ((2269.92 1759.53) 0.0)
  ((2671.7 2161.3) -0.694158)
  ((3098.4 1966.54) 0.0685342)
  ((3135.5 1404.21) -0.538618)
  ((2647.19 915.904) -0.187763)
  ((1973.16 1351.68) -0.851784)
  ((2147.77 1526.3) 1.95618)
  ((2147.77 1635.94) -0.23567)
  ((1715.03 1564.88) 1.02521)
)

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: quoting polyline
« Reply #6 on: April 04, 2012, 08:12:46 AM »
Another :-)

Code - Auto/Visual Lisp: [Select]
  1. (defun _lwvertices ( e )
  2.     (if (setq e (member (assoc 10 e) e))
  3.         (cons
  4.             (cons
  5.                 (cdr (assoc 10 e))
  6.                 (cdr (assoc 42 e))
  7.             )
  8.             (_lwvertices (cdr e))
  9.         )
  10.     )
  11. )

Code: [Select]
(_lwvertices (entget (car (entsel))))
=>>
(
    ((-230.89 -9.2228) . 0.0)
    ((-221.288 16.2617) . -0.495079)
    ((-201.074 22.3174) . 0.553551)
    ((-185.407 28.6254) . 0.0)
    ((-190.208 48.3065) . 0.0)
    ((-206.633 48.3065) . 0.0)
)

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: quoting polyline
« Reply #7 on: April 04, 2012, 08:13:31 AM »
for test:
Code - Auto/Visual Lisp: [Select]
  1. (defun test1 (/ l)
  2.   (setq l (test (car (entsel "\n Select LWPOLYLINE:"))))
  3.     (append (list '(0 . "LWPOLYLINE")
  4.                   '(100 . "AcDbEntity")
  5.                   '(67 . 0)
  6.                   '(410 . "Model")
  7.                   '(8 . "0")
  8.                   '(62 . 1)
  9.                   '(100 . "AcDbPolyline")
  10.                   (cons 90 (length l))
  11.                   '(70 . 0)
  12.             )
  13.             (apply (function append)
  14.                    (mapcar (function (lambda (a) (list (cons 10 (car a)) (cons 42 (cadr a))))) l)
  15.             )
  16.     )
  17.   )
  18.   (princ)
  19. )

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: quoting polyline
« Reply #8 on: April 04, 2012, 08:18:10 AM »
Hi Lee Mac!  :-)
Great idea to use recursion - got short and clear!

ps. long time no theme challenge...
bored  :-D

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: quoting polyline
« Reply #9 on: April 04, 2012, 08:34:47 AM »
Hi Lee Mac!  :-)
Great idea to use recursion - got short and clear!

Thank you! Your method was also very interesting  :-)

Another for Polyline:

Code - Auto/Visual Lisp: [Select]
  1. (defun _vertices ( e / l )
  2.     (if (eq "VERTEX" (cdr (assoc 0 (setq l (entget e)))))
  3.         (cons
  4.             (cons
  5.                 (cdr (assoc 10 l))
  6.                 (cdr (assoc 42 l))
  7.             )
  8.             (_vertices (entnext e))
  9.         )
  10.     )
  11. )

ps. long time no theme challenge...
bored  :-D

 :lol:  A challenge is long overdue  :lol:

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: quoting polyline
« Reply #10 on: April 04, 2012, 08:59:56 AM »
Sorry to chip in, had to have a go at this too  :angel:
ActiveX version works on both LWPoly and old Poly:
Code - Auto/Visual Lisp: [Select]
  1.  
  2. (defun ExtractVertices  (ename / obj lst n)
  3.   (setq obj (vlax-ename->vla-object ename) n 0)
  4.   (vl-remove-if
  5.     'null
  6.     (mapcar
  7.       '(lambda (a b / m)
  8.          (setq m n n (1+ n))
  9.          (if (= (rem m 2) 0) (cons (cons a b) (vla-GetBulge eo (/ m 2)))))
  10.       (setq lst (vlax-get eo 'Coordinates))
  11.       (cdr lst))))
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: quoting polyline
« Reply #11 on: April 04, 2012, 09:39:50 AM »
That actually gave me an idea ... what about a grouping function to get around that hassle of ActiveX coordinates: http://www.theswamp.org/index.php?topic=41419.0
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: quoting polyline
« Reply #12 on: April 04, 2012, 11:42:56 AM »
Code - Auto/Visual Lisp: [Select]
  1. (defun f (o i)
  2.     (cons (cons (vlax-curve-getPointAtParam o i) (vla-getbulge o i)) (f o (1+ i)))
  3.   )
  4. )

test:
Code - Auto/Visual Lisp: [Select]
  1. (f (vlax-ename->vla-object(car(entsel))) 0)