list the length of all segments of a polyline

list the length of all segments of a polyline

Anonymous
Not applicable
12,522 Views
48 Replies
Message 1 of 49

list the length of all segments of a polyline

Anonymous
Not applicable

sir,

 

can I get a lisp programme for getting the segment length of all the segments of a polyline. a sampe polyline is attached

Accepted solutions (1)
12,523 Views
48 Replies
Replies (48)
Message 41 of 49

ndnam1296
Participant
Participant

Thank you for your reply, I mean can you modifie your code at message 24, I need export have text inside polyline and area polyline (like picture) can you help me, please, very thank you!!

 

ndnam1296_0-1701314915782.png

 

0 Likes
Message 42 of 49

Kent1Cooper
Consultant
Consultant

So by "I need text inside polyline" you do not mean what I first assumed, which was that you want to add text inside it, presumably labeling the segment lengths [see my previous Reply].  Instead, it looks like you want to get the text content from a Text object that is already drawn inside the Polyline.

 

If so, is it always plain Text, or might it be Mtext [or possibly something else]?  Would there ever be any other things inside the Polyline?  If so, will looking for Text/Mtext only on a particular Layer, or of a particular Style or height, work to find only what you want?  Could there ever be more than one qualifying object inside?  Are the Polylines always closed?

Kent Cooper, AIA
Message 43 of 49

ndnam1296
Participant
Participant

Thank you for your reply, text inside Polyline just normal text, any high, any text,only have one text and polyline is closed, can you help me to modifie your lisp code have more 2 columns text inside polyline and area polyline, same my picture, very thank you!

0 Likes
Message 44 of 49

Sea-Haven
Mentor
Mentor

Why not a couple of extra questions, does each pline exist fully in that it is a closed pline around the text, not 1 close and the other 2 are "U" touching each other, its not a problem as I would use Bpoly and ignore your cyan plines in case they are multi plines & lines. 

 

Working on something give it a try, DONT have Excel open is easiest. Just pick 1 text, then select all required text.

 

; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/list-the-length-of-all-segments-of-a-polyline/td-p/7506972/page/3


(defun c:wow ( / putcell2 lay ss lst lst2 tot len ins txt co-ord area d I K X myxl)

;;	Thanks to fixo			;;
;;   = Set Excel cell text =    ;;
;;				;;
(defun putcell2 (row column text)
(setq cells (vlax-get-property  (vlax-get-property myxl "ActiveSheet") "Cells"))
  (vl-catch-all-apply
    'vlax-put-property
    (list cells 'Item row column
	(vlax-make-variant (vl-princ-to-string text) vlax-vbstring)))
)


(setq lay (cdr (assoc 8 (entget (car (entsel "\nPick text for layer search "))))))
(setq ss (ssget (list (cons 0 "TEXT")(Cons 8 lay)(cons 410 (getvar 'ctab)))))
(if (= ss nil)
  (progn
   (alert "You did not pick any text on correct layer \n\nwill exit now")
   (exit)
  )
)
(setvar 'dimzin 3)

(setq lst '() tot 0)
(repeat (setq x (sslength ss))
(setq ent (ssname ss (setq x (1- x))))
  (setq ins (cdr (assoc 10 (entget ent))))
  (setq txt (cdr (assoc 1 (entget ent))))
  (command "bpoly" ins "")
  (setq area (vlax-get (vlax-ename->vla-object (entlast)) 'area))
  (setq co-ord (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) 
(entget (entlast)))))
  (entdel (entlast))
  (setq K 0 lst2 '())
  (repeat (- (length co-ord) 1)
   (setq d (rtos (abs (distance (nth k co-ord) (nth (1+ k) co-ord))) 2 3 ))
   (setq lst2 (cons d lst2))
   (setq k (1+ k))
  )
  (setq d (rtos (abs (distance (last co-ord) (nth 0 co-ord))) 2 3 ))
  (setq lst2 (cons d lst2))
  (setq cols (length lst2))
  (if (> cols tot)(setq tot cols))
  (setq lst (cons (list txt area lst2) lst))
)

(setq lst (reverse lst))

(or (setq myxl (vlax-get-object "Excel.Application"))
    (setq myxl (vlax-get-or-create-object "excel.Application"))
)
(vla-put-visible myXL :vlax-true)
(vlax-put-property myxl 'ScreenUpdating :vlax-true)
(vlax-put-property myXL 'DisplayAlerts :vlax-true)
(or (setq wks (vlax-get myxl 'ActiveSheet))
    (vlax-invoke (vlax-get myxl 'workbooks) 'Add)
)

(putcell2 1 1 "Text inside")
(putcell2 1 2 "Area")
(putcell2 1 3 "Lengths")

(setq row 2 col 2 I -1)
(foreach val lst
  (putcell2 row 1 (car val))
  (putcell2 row 2 (cadr val))
  (setq val2 (caddr val))
  (setq len (length val2))
  (repeat len
   (putcell2 row (setq col (1+ col)) (nth (setq I (1+ I)) val2))
  )
  (setq col 2)
  (setq row (1+ row) i -1)
)
(princ)
)
(c:wow)

 

 

2nd question do you want a Table, and an export to Excel ? Please confirm.

 

 

Message 45 of 49

ndnam1296
Participant
Participant

Thank you, before when use Kent1Cooper 's lisp code at message 24, by select all polyline it will export length of all segments, now I need more 2 columns, text inside polyline and area polyline, just one text inside (not mtext) and all polyline is closed (yellow colums in my picture), please help me, thank you very much!

ndnam1296_0-1701511201061.png

 

 
0 Likes
Message 46 of 49

Sea-Haven
Mentor
Mentor

Did you try what I posted ?

Message 47 of 49

ndnam1296
Participant
Participant

Thank you, I have tried but it not same what I want, can you check more!

0 Likes
Message 48 of 49

ndnam1296
Participant
Participant

Can you help me? thank you

0 Likes
Message 49 of 49

Kent1Cooper
Consultant
Consultant

Try the attached [minimally tested].

Kent Cooper, AIA
0 Likes