Jump to content

Recommended Posts

Posted

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.

  • Replies 27
  • Created
  • Last Reply

Top Posters In This Topic

  • guigol

    14

  • pBe

    13

  • BIGAL

    1

Top Posters In This Topic

Posted Images

Posted

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

 

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 ----

Posted

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

Posted

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

 

You dont need to lower your expectaions, if you'll explain more clearly what you need you might get exactly what you want guigol.

 

What you're asking now is too easy, but that is not what you want is it?

Posted

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

Posted (edited)

[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))))
                            [color=blue][color=black]([/color](and[/color] (eq typ "LWPOLYLINE")
                                  [color=blue](> (distance (vlax-curve-getStartPoint ent)(vlax-curve-getEndPoint ent)) 0.1))[/color]
                       (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)
     )

(defun c:ConnectedTo  (/ _rtos _carcadr fn fl)
     (setq _rtos (lambda (q) (rtos q 2 16)))
     (setq _carcadr (lambda (x) (list (car x) (cadr x))))
    [color=blue] (if (= (getvar 'Dwgtitled) 1)
           (progn
[/color]                  (c:guigol)
                 [color=blue](setq fn   (open  (setq fl (strcat
                                        (getvar 'Dwgprefix)
                                        (cadr (fnsplitl
                                                    (getvar
                                                          'Dwgname)))
                                        ".csv"))
                                  "w"))
[/color]                  (textscr)
                 (Foreach
                        Plines [color=blue](vl-sort
                              PB&PlineList
                              '(lambda (s1 s2)
                                     (< (last s1) (last s2))))
[/color]                        (print (car plines))
                       (princ (strcat
                                    "\n\t\t\tLength of Polyline:  "
                                    (_rtos (last plines)))
                              )
                      [color=blue] (write-line
                             (strcat (caar plines)
                                     ","
                                     (_rtos (last plines))
                                     ","
                                     (if (eq (caar plines)(cadar plines)) "" (cadar plines)))
                             fn)
                       )
[/color]                  [color=blue](close fn)
                 (startapp (strcat "explorer /select, "fl", /e"))
[/color]                  [color=blue])[/color])
     (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

Edited by pBe
UPDATE Code to write to CSV
Posted

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

Posted

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.

Posted
but one is huge. and I don't see it on the dwg.

 

hence:

but the boundary also shares the same layer, I could exclude that one while generating the plinelist but after you clarify the other issues.

 

Did you try the code? will you be able to pick up from where i left off?

Posted

excuse me, i've just to understand the meaning of boundaries. Indeed, the boundary is on the same layer but don't have to be extract.

 

I've tried the code. It work perfectly. with your code CONNECTEDTO, I obtain all I need. I removed the X and the Y. keeping only name of pullbox (start and end) and length

I made some processing and obtain a 3 rows excel table

And i succeed to upolad the length in my original table with VLOOKUP

 

but unfortunately, after many try, I don't succed to transform CONNECTEDTO to make able the export to excel.

Posted
excuse me, i've just to understand the meaning of boundaries. Indeed, the boundary is on the same layer but don't have to be extract.

 

Check

 

excuse me, i've just to understand the meaning of boundaries. Indeed, the boundary is on the same layer but don't have to be extract.

 

I've tried the code. It work perfectly. with your code CONNECTEDTO, I obtain all I need. I removed the X and the Y. keeping only name of pullbox (start and end) and length

I made some processing and obtain a 3 rows excel table

And i succeed to upolad the length in my original table with VLOOKUP

 

Does that mean you dont need the START/END X&Y coordinates for the plines anymore?

 

...but unfortunately, after many try, I don't succed to transform CONNECTEDTO to make able the export to excel.

 

Perhaps we can help you with that, post an example of a xls file which shows the compiled data

Posted

Does that mean you dont need the START/END X&Y coordinates for the plines anymore?

 

Not really. Not for my final table, but It would be usefull to check data later.

 

Perhaps we can help you with that, post an example of a xls file which shows the compiled data

Annexe 6 corrigée controlée CAGC .xls

here is my final table. The row "G" have to be completed.

 

I'm developping à VBA macro to complete it with different source files. (the extract xhixh is our subject, is one of them)

Posted

Alrighty then, i'll look into it later.

Posted
No problem

 

I saw your code is attached to RAB_F09097040411, but this name will change for every dwg we'll have to process.

 

Okay, now answer me this, if its not the same for every drawing, how would the program diffrentiate which polyllnes to process? preferably the conduits resides on its own unique layer, that will reduce the number of items to process. we could however use a wildcard "RAB_F*" for conduits layers

 

What about the Pull box blocks, do they differ on every drawing as well? or a least have the same TAG name for the value attributes?

 

EDIT: In the end what you really need is the length of the polylines connected to a pull box data. and not the pull boxes Start/Endpoint, as the ConnectedTo rouitne already shows what pull boxes are associated with a particular conduit, is that correct? I believe you only need that info before to compare the coordinates with the collected plines coordinates.

Posted
Okay, now answer me this, if its not the same for every drawing, how would the program diffrentiate which polyllnes to process? preferably the conduits resides on its own unique layer, that will reduce the number of items to process. we could however use a wildcard "RAB_F*" for conduits layers.

 

Here is some others dwg to test your code.

F12187110411_75113_110411.dwg

F37510300511_75113_300511.dwg

 

the layers where there are polylines begin with RA : "RAA, RAB, RAC, ..."

 

 

What about the Pull box blocks, do they differ on every drawing as well? or a least have the same TAG name for the value attribute

they always have the tag name

 

 

EDIT: In the end what you really need is the length of the polylines connected to a pull box data. and not the pull boxes Start/Endpoint, as the ConnectedTo rouitne already shows what pull boxes are associated with a particular conduit, is that correct? I believe you only need that info before to compare the coordinates with the collected plines coordinates.

yes exactly. the coordinates of the pullbox and the plines are not usefull for me. It's just transition data which can help me to put and length together.

F62884220711_75113_220711.dwg

F12707110411_75113_120411.dwg

F04364230311_75113_240311.dwg

Posted (edited)

CODE UPDATE:

Write to CSV file with this format

Format in Notepad
14214[b][color=blue],[/color][/b]9.693995455208048[color=blue][b],[/b][/color]14213
14217[b][color=blue],[/color][/b]10.6469506871911[color=blue][b],[/b][/color]14221

Format in Excel
14214 9.693995455208048 14213
14217 10.6469506871911 14221

 

IT will still scroll thru the screen and launch explorer with the file highlighted

 

 

There are still polyliens connected to jsut one pullbox. You will recognize it when you open the CSV file

[color=blue]22211[/color] 1.344204292 
14214 9.693995455 14213

 

HTH

Edited by pBe

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...