Have a look here http://www.cadtutor.net/forum/showth...ghlight=length in Pbe's code about the first 5 lines pulls the length of a pline out the rest may be usefull also.
Try using Serach I used "length" and found about 30 sec later.

Registered forum members do not see this ad.
Hi,
I'm a french user of AutoCad, so I hope my english will be great.
I work in public work.
For a new project, our client gives us :
*___a large amount of plan representing
*____________"pull box" (burried in the ground)
*____________section of cables connected to the pull box.
*___for each plan, we have an excel table which give us for each section
*____________the start pull box
*____________the finish pull box
But we don't have the length of section in this table.
We have a lot of plans and for each plan, there are lot of section.
Pull box are block with attributes
section are polyline.
We are looking for a code who can extract the length of all section of a plan
Is there someone here who can help me?
a lisp code that is almost the same that i'm looking for ? something i can adapt ?
Thank you in advance.
If you have question, don't hesitate.




Have a look here http://www.cadtutor.net/forum/showth...ghlight=length in Pbe's code about the first 5 lines pulls the length of a pline out the rest may be usefull also.
Try using Serach I used "length" and found about 30 sec later.
A man who never made mistakes never made anything
Thank you for the recommendation Bigal
@guigol
You may want to check this for as well
-----> Total Length & Area Programs by Lee Mac <----
or --> Area Label by Lee Mac <---- similar to this but twek for Length rather than Area
What you're asking has been done before (i think),
Extracting the length is the easy, If the section lines are Polylines connected to a pull boxes with unique properties or attribute values then it wouldnt be hard to automatically assign the length value to your table.
---- More info, more answers ----

Thank you for your help, but I realize that my skills in lisp are very weak.
Since tuesday, i work with your link but without success
i'm looking for a routine which can extract data of a dwg in one step. not clicking in all polyline one by one.
However, i reduced my expectations.
Now, the only thing i would is to obtain a file (txt, csv, xls, ...) with the following elements :
x of pline start / y of pline start / x of pline end / y of pline end / length of pline

Excuse me for my poor english. I thought it was clear.
So i restart from the start
I have a lot of dwg. But i want to take it one by one
on each dwg, there are :
block which represent pull box
polyline which represent cable burried in ground.
I need to obtain 2 excel table with these columns
first one is for pull box:
CH_COD1 / X / Y
Second one if for cable :
x of pline start / y of pline start / x of pline end / y of pline end / length of pline
I know that pull box are not at exactly the same coordonate than the start or the end of polyline
So with these 2 tables, i'll make (with excel vba that i have skills) the following search
for each couple (X;y) of polyline, find the pull box (his CH_COD1) which is located near.
the final objective is to obtain the following table
CH_COD1 of start pull box/CH_COD1 of end pull box /length of polyline connecting them
is this more clear?
I join my dwg file.
F09097040411_75105_050411.dwg
and again, thank you for your patience
[CODE]
Code:(defun c:guigol ( / _First&Second ;|AttbList PlineList PB&PlineList|; ss ent i typ ) (vl-load-com) (defun _First&Second (lst alst / a b c d) (repeat 2 (setq a (car lst) lst (cdr lst)) (setq c (cadar (vl-sort (mapcar '(lambda (k) (list (distance a (cadr k)) k)) alst) (function (lambda (p1 p2) (< (car p1) (car p2))))))) (setq d (cons (car c) d)) ) ) (if (setq AttbList nil PlineList nil PB&PlineList nil ss (ssget "_X" '((-4 . "<OR") (-4 . "<AND") (0 . "INSERT") (2 . "FT_CHEXI") (-4 . "AND>") (-4 . "<AND") (0 . "LWPOLYLINE")(8 . "RA*") (-4 . "AND>") (-4 . "OR>") ) )) (progn (repeat (setq i (sslength ss)) (setq ent (ssname ss (setq i (1- i)))) (cond ((eq (setq typ (cdr (assoc 0 (entget ent)))) "INSERT") (if (setq attval (car (vl-remove-if-not '(lambda (j) (eq (vla-get-tagstring j) "CH_COD1")) (vlax-invoke (vlax-ename->vla-object ent) 'Getattributes)))) (setq AttbList (cons (list (vla-get-textstring attval) (cdr (assoc 10 (entget ent)))) AttbList)))) ((and (eq typ "LWPOLYLINE") (> (distance (vlax-curve-getStartPoint ent)(vlax-curve-getEndPoint ent)) 0.1)) (setq PlineList (cons (list (vlax-curve-getStartPoint ent) (vlax-curve-getEndPoint ent) (vlax-curve-getDistAtParam ent (vlax-curve-getEndParam ent)) ) PlineList) )))) (foreach itm PlineList (setq PB&PlineList (cons (list (_First&Second itm AttbList) (car itm) (cadr itm) (last itm)) PB&PlineList)) ) ) ) (princ) )Code:(defun c:ConnectedTo (/ _rtos _carcadr fn fl) (setq _rtos (lambda (q) (rtos q 2 16))) (setq _carcadr (lambda (x) (list (car x) (cadr x)))) (if (= (getvar 'Dwgtitled) 1) (progn (c:guigol) (setq fn (open (setq fl (strcat (getvar 'Dwgprefix) (cadr (fnsplitl (getvar 'Dwgname))) ".csv")) "w")) (textscr) (Foreach Plines (vl-sort PB&PlineList '(lambda (s1 s2) (< (last s1) (last s2)))) (print (car plines)) (princ (strcat "\n\t\t\tLength of Polyline: " (_rtos (last plines))) ) (write-line (strcat (caar plines) "," (_rtos (last plines)) "," (if (eq (caar plines)(cadar plines)) "" (cadar plines))) fn) ) (close fn) (startapp (strcat "explorer /select, "fl", /e")) )) (princ) )
There are plines that only connects to 1 pull box and nothing at the other end (e.g. 42513), also, there are duplicate polylines all over the place, is that really how it is? Notice the ssget filters calls for a specific layer, but the boudnary also shares the same layer, I could exclude that one while generating the plinelist but after you clarify the other issues.
HTH
On a different note:
I need the opnion of the forum members on this, I initially intended to use vlax-curve-getClosestPointTo , which i think is the ideal function in this case. In contrast with the code i posted. I use the the collection of blocks and test for distance for start/end of polyline , the smallest value if not 0 would be the target block. whilst with ClosestPoint, it will be the other way around . collection of plines to test every insertion point of block. Which of the two guys think is better the better approach? problem i can see with the second approach is there are more that one plines connected to a block sometimes more.
EDIT:CODE UPDATED [08june2012]
pBe
Last edited by pBe; 8th Jun 2012 at 11:03 am. Reason: UPDATE Code to write to CSV

Thank you for your job.
It's 9PM here. everybody is at home.
I'll try to get answer tomorrow.
Your 2 questions :
Why is there pline connected to only one pullbox ?
Indeed, it's quite strange. because a cable can't to stop in the ground. a cable is inevitably connected to 2 pullbox.
i'll check with my colleagues.
Why is there duplicate poylines ?
If these polylines come from the same start pull box to then same en pull box, it's because it represents several cable sarting from the same pull box to another pull box. it's the spine of the network.
i'll check with my colleagues.
I saw your code is attached to RAB_F09097040411, but this name will change for every dwg we'll have to process.
thank you

In theory, there is only one case where polyline are connected to only one pullbox.
it's for the "optical technical local", where is installed all the equipment of the network.
And in theory, there is only one pullbox connected to the "optical technical local"
For the second question : Why is there duplicate poylines ?
it's a mistake made by the drawer.
In theory, there is only one polyne between 2 pullbox.
We have a database which indicate the number of cable for each polyline.
i've noticed something:
for the pullbox 42513, there are 3 polyline.
2 are similar (drawer mistake ~43m) but one is huge. and I don't see it on the dwg.
Bookmarks