lisp for automatic data extratiocn

lisp for automatic data extratiocn

Anonymous
Not applicable
2,023 Views
16 Replies
Message 1 of 17

lisp for automatic data extratiocn

Anonymous
Not applicable

Hello,

 

I'm wondering if it is possible to write a lisp for the following situations.

We're doing two kinds of data extraction, and it takes some time to fill in the extraction form. If we could do it by typing in a command to get the results this would be great.

 

There's just one difference between the data extractions. The first one is for a 25 mm headpipe and 25 mm pipes to the sprinklers. This data extraction looks like the following steps:

 

step 1: 

 

data extraction 1.png

 

step 2: 

 

data extraction 2.png

 

Step 3: 

 

data extraction 3.png

 

Step 4: 

 

data extraction 4.png

 

Step 5: 

 

data extraction 5.png

 

Step 6: 

 

data extraction 6.png

 

This will export the lengt of the selected polylines and lines into an excel sheet. (the layers of these lines are just for a controle check). If it is possible to do this with a command (something like berekenleiding25 ) it would be great and saves a lot of time.

 

The other data extraction is for headpipes with a 32 mm / 40 mm diameter and 25 mm pipes to the sprinkler. 

It looks quite the same as the data extraction shown above, but now it should only take the length of the lines and not the polylines.  I think the command for this should be something like berekenleiding 

 

All the data extractions could be saved in one  excel file and this file could be overwritten each time we use the command.  (i could enter the filelocation by myself in the lisp if marked where to do). 

 

I've attached an example dwg and the files I'm currently using for data extraction. 

 

I'm wondering if this is possible and if anyone is able to help me (i'm just a basic level autocad user, writing lisp's is something I've never done before).

 

Kinds regards,

 

Niels 

 

 

0 Likes
2,024 Views
16 Replies
Replies (16)
Message 2 of 17

devitg
Advisor
Advisor

Hi @Anonymous ,  as far as I can see , there is no way , from dwg, to know what  diameter is each pipe 

 

The other data extraction is for headpipes with a 32 mm / 40 mm diameter and 25 mm pipes to the                    sprinkler. 

 

0 Likes
Message 3 of 17

Anonymous
Not applicable

Hi Devitg,

 

That's correct. It's only  visible in the autocad add-on "landexpert". However, this add-on does not calculate everything correctly and that is why we use a data extraction.

 

What matters most: An automatic data extraction should be done based on the displayed lines (copied directly from the "landexpert" plug-in), if possible of course. One for the length of both the lines and the polylines and one that only shows the length of the lines. This is the difference between all pipes in 25 mm (polylines are main pipes) or another diameter main pipe (pipes to the sprinklers are lines). The length of the main pipe is in the last case shown correctly in landexpert so this is not an issue. 

 

Maybe a better discription of the case: 

 If I could get a routine (command)  that extracts all the data of the selected lines in a drawing  and a routine that extracts the length of all the selected polylines and lines into an excelsheet is this "problem" solved..  (I don't like the data extraction wizzard at all, takes to much time :p) 

 

Something like:

first one: command: berekenleiding , select lines and polylines, get length of only lines into excelsheet
second one: berekenleiding25, select lines and polylines, get length of selected lines and polylines into excelsheet. 

 

I hope I made myself a bit clearer now. 

 

Kinds regards,

 

CraZy-N 

 

 

0 Likes
Message 4 of 17

hak_vz
Advisor
Advisor

@AnonymousIt is not a problem to write a script that would create CSV file with desired data, but you have to give us more details. Since all pipes are created in same layer define which color defines particular pipe type.

As @devitg  has stated, there is no way to read it out from your dwg sample.

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 5 of 17

devitg
Advisor
Advisor

@Anonymous ,  an option is to set color has number 25 32 45 50 .

 

See my first csv .and lisp 

 

 

 

 

0 Likes
Message 6 of 17

devitg
Advisor
Advisor

canceled 

 

 

0 Likes
Message 7 of 17

Anonymous
Not applicable

I've tried to make things clear in the new dwg which I've attached

 

if this is not clear, forget the idea of different pipe diameters. In essence, it concerns two different data extractions that I would like to have automated:
- one where I select both the lines and the polylines and see the lengths of both in the excel file. I can adjust the command for this myself if I have to.
- One (separate command) where I can select both the lines and the polylines and only find the lengths of the selected lines in the excel file. Excluding the polylines in the selection would be more difficult. The data extraction wizard also offers the possibility to filter between lines and polylines, so this shouldn't be very difficult to filter them out?

0 Likes
Message 8 of 17

devitg
Advisor
Advisor

@Anonymous , hi please test this lisp . it will give you  CSV file, you can open with XLS , and  the use the column to text , or text in column, xls command 

 

 

 

;;arranque 
;;***********************************************************************************************
;; Hecho por  Gabo CALOS DE VIT de CORDOBA ARGENTINA
;;;    Copyleft 1995-2020 por Gabriel Calos De Vit 
;; DEVITG@GMAIL.COM \n
;;;(ascii "\"")
;;*//*/*/*/*/*/*/*/*/*/*/*/*/**/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*
(DEFUN GUARDA-LISTA-CSV-W-CABEZA/cabeza-lista (CABEZA
                                               LISTA
                                               /
                                               ;;ar
 ;nombre-archivo
                                              )
  ;;(setq nombre-archivo (getfiled "Archivo donde guardara los datos " "" ext 1))
  (SETQ NOMBRE-ARCHIVO
         (STRCAT (GETVAR "dwgprefix")
                 (VL-FILENAME-BASE (GETVAR "dwgname"))
;;;                 " lista de capas "
                 ".csv"
         ) ;_  STRCAT
  ) ;_  SETQ
  (SETQ AR (OPEN NOMBRE-ARCHIVO "w"))
  (WRITE-LINE CABEZA AR)
  (FOREACH
         TEXTO LISTA
    (WRITE-LINE TEXTO AR)
  ) ;_  FOREACH
  (CLOSE AR)
  NOMBRE-ARCHIVO
)

(defun initio ()
(VL-LOAD-COM)
  (SETQ ACAD-OBJ (VLAX-GET-ACAD-OBJECT)) ;_ el programa ACAD 
  (SETQ ADOC (VLA-GET-ACTIVEDOCUMENT ACAD-OBJ)) ;_ el DWG que esta abierto-
  (SETQ MODEL (VLA-GET-MODELSPACE ADOC))
  (SETQ SELECTIONSETS (VLA-GET-SELECTIONSETS ADOC))
  (SETQ LAY-COLL (VLA-GET-LAYERS ADOC))

);end defun initio

(defun pipe-dia-2-csv (/ ADOC CSV-FILE HEAD HEAD-AND-PIPES HEAD-AND-PIPES-OBJ HEAD-AND-PIPES-OBJ-SS
                       HEAD-AND-PIPES-OBJS OBJ-COLOR OBJ-LAYER OBJ-LENGTH OBJ-TYPE
                       OBJ-TYPE+LENGTH+CLR+LAY TYPE-LENGTH-LAY-COLOR-LIST
                      )
  (initio)

  (prompt "\n Select pipes and headpipes")

  (setq head-and-pipes (ssget '((0 . "*line*"))))

  (setq head-and-pipes-obj-ss (VLA-GET-ACTIVESELECTIONSET adoc))
;;;  (setq head-and-pipes-obj (vla-item head-and-pipes-obj-ss 5))

  (setq type-length-lay-color-list ())
  (setq HEAD (strcat "PIPE" "," "LENGTH" "," "COLOR" "," "LAYER"))
  (VLAX-FOR
         head-and-pipes-obj
                           head-and-pipes-obj-ss
    (setq obj-type (vla-get-ObjectName head-and-pipes-obj))
    (setq obj-length (rtos (VLA-GET-LENGTH head-and-pipes-obj) 2 4))
    (setq obj-color (itoa (VLA-GET-COLOR head-and-pipes-obj)))
    (setq obj-layer (VLA-GET-LAYER head-and-pipes-obj))
    (setq obj-type+length+clr+lay (Strcat obj-type "," obj-length "," obj-color "," obj-layer))
    (setq type-length-lay-color-list (cons obj-type+length+clr+lay type-length-lay-color-list))
  ) ;_  VLAX-FOR

  (setq csv-file (GUARDA-LISTA-CSV-W-CABEZA/cabeza-lista HEAD type-length-lay-color-list))

  (startapp "notepad" csv-file)


) ;_  defun




(defun c:p-2-fil ()

(pipe-dia-2-csv)

)


  

 

 

 

 

 

 

0 Likes
Message 9 of 17

hak_vz
Advisor
Advisor

@devitg  I will not write down my code since your code works very well. I would just propose, if OP wants it, to sort output strings (lines) in accordance to pipe type (diameter) i.e. depending on color. Option is to add an empty line between different types, or sum total lengths.

 

Also, instead of "," I would use ";" as a delimiter.

 

 

 

(setq HEAD (strcat "PIPE" ";" "LENGTH" ";" "COLOR" ";" "LAYER"))

 

 

To directly connect output csv with spreadsheet app

 

 

(startapp "explorer" csv-file)

 

 

 

 

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 10 of 17

devitg
Advisor
Advisor

Hi @hak_vz , thanks for your tip , I learn a new one today . 

I always use the  comma separator , and did not know about the way xls will open it with not Text on Column .

 

I left the OP to handle it as he needs on the xls . 

 

 

0 Likes
Message 11 of 17

Anonymous
Not applicable

Hi Devitg,

 

Wich command do I need to start your lisp? I'm not that good in spanish / portugese.

 

Based on the uploaded csv file:

- It's not interesting wich color a line has, this option may be deleted. I want the outcome of the csv file just as simple as it should be. 

 

I'm really looking forward to test this and could see if this lisp is what I'm searching for 🙂 

 

 

 

0 Likes
Message 12 of 17

devitg
Advisor
Advisor

@Anonymous  First APPLOAD the lisp , and just type 

 

p-2-fil

 at the command line, 

Meanwhile I suit to need. 

Test it , and send me any error if happens. 

 

0 Likes
Message 13 of 17

devitg
Advisor
Advisor

Hi @Anonymous , please test it . it will make a new XLS , each time is used 

 

in this name format x:folders\folder\dwgname date 

 

"K:\\crayzi\\beregeningsplan example new20201110.09513200.csv" 

 

 

0 Likes
Message 14 of 17

Anonymous
Not applicable

Hi Devitg,

 

I have tested the routine a few times and it works fine. I would like to have adjusted it slightly based on feedback from a colleague.

Is it possible to remove the polylines from the results? So that only the lengths of lines are visible, even though we select the polylines in autocad?

This change could be made in the routine with colors shown ( my colleagues like to see the colors). 

 

This is the only adjustment that I (and my colleagues) would like to see 🙂

 

Great job so far!

 

Kinds regards,

 

CraZy-N

0 Likes
Message 15 of 17

devitg
Advisor
Advisor

Hi @Anonymous and colleagues , back and for . What a nice way to spend the day. 

I can add the color , again, an only lines 

 

0 Likes
Message 16 of 17

Anonymous
Not applicable

Hi DevitG,

 

Sorry to put you to work so much. The lisp works perfect, but I still have one question:

 

What would be an ideal scenario for us is that we can load them both and use them. (based on command get a csv file with both polyline and lines or with a different command get a csv file with only lines)

 

What I have done is the following:
- Changed the commands of both files
- Both routines have separate names
- Changed the filename of the created csv file (just a detail)

- Used appload to load both of them.

 

 However, if both routines are loaded in autocad, things are not working correctly. As soon as I enter the lisp "leidingberekenen"(both polylines and lines) it goes wrong when calculating only the lines (lisp aftakkingberekenen, command "aftakkingberekenen"). With the lisp "leidingberekenen"  the csv file contains the polylines and lines and this is correct.

 

When I'm using "aftakkingberekenen" the csv file does not exclude the polylines anymore.

 

If I don't load one of the two routines it works fine.

 

 

I've inserted both edited lips as attachment. Is there a way to use them both and get the correct outcome based purely on a different command? (Give command leidingberekenen and get the lenght of both polylines and lines, give command aftakkingberekenen and get a csv file with only lines? CSV file may have a name like leidingen m1 in both cases).

 

I hope you still want to help us with this, I am a difficult customer I know.

 

 

0 Likes
Message 17 of 17

devitg
Advisor
Advisor

@Anonymous find attached MY WAY to do it .

 

If you want to modify to your need , do it.