Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

[LISP] Create a table with 3 colums Space type, Space number and Area of each polyline

10 REPLIES 10
Reply
Message 1 of 11
AVFx1410
798 Views, 10 Replies

[LISP] Create a table with 3 colums Space type, Space number and Area of each polyline

Hi there everybody!

 

I've been working on excel and manually transcribing the space type (Yellow) the space name (Blue) and the Area (Green)

 

Since this is very recurring for me I was thinking, is it possible to extract the information from the drawing via LISP?

 

I would like to run a command that loops through all polylines and either export information to Excel or Create an AutoCAD table right there in the drawing.

 

Your help is very much appreciated.

 

See drawing attached.

Victor P

 

 

10 REPLIES 10
Message 2 of 11
AVFx1410
in reply to: AVFx1410

Found this lisp in the forum all credits to  Jimmy Bergmark!

 

But this covers the Area field how would I also retrieve the space type and the Space number?

 

Thank you all so much!

 

 

Message 3 of 11
AVFx1410
in reply to: AVFx1410

I found this code by @pbejse it does almost everything I need I just need help tweaking it a little bit... I would like to make it so that there is only one text per polyline allowed and add the space type (yellow) in sample drawing column

 

also, if you would please help in making it sqft. that would be great!

 

 Thank you all so much!

 

 

(defun c:demo (/ ss i area layer all_data pts csv_file openfile)
;;			pBe Sep 2018			;;
  (if (and
        (setq all_data nil
              ss       (ssget '((0 . "LWPOLYLINE")))
        )
        (repeat (setq i (sslength ss))
          (setq e     (ssname ss (setq i (1- i)))
                area  (vlax-curve-getarea e)
                layer (cdr (assoc 8 (setq ent (entget e))))
                pts   (mapcar 'cdr
                              (vl-remove-if-not
                                '(lambda (d)
                                   (= 10 (car d))
                                 )
                                ent
                              )
                      )
          )
          (if (setq ssText (ssget "_CP" pts '((0 . "TEXT"))))
            (setq all_data
                   (cons
                     (list (if (= (sslength ssText) 1)
                             (cdr (assoc 1 (entget (ssname ssText 0))))
                             "-"
                           )
                           area
                           layer
                     )
                     all_data
                   )
            )
          )
        )
        (setq csv_file (getfiled "Save CSV File"
                                 (strcat
                                   (getvar 'dwgprefix)
                                   (vl-filename-base (getvar 'dwgname))
                                   ".csv"
                                 )
                                 "csv"
                                 45
                       )
        	)
        )
        

        (progn
          (setq openfile (open csv_file "w"))
          (write-line
            "Text inside polyline,Polyline Area (m2),Layer"
            openfile
          )
          (foreach itm (vl-sort all_data
                                '(lambda (a b) (< (Cadr a) (cadr b)))
                       )
            (write-line
              (Strcat (Car itm)
                      ","
                      (strcat (rtos (Cadr itm) 2 2) " m2")
                      ","
                      (caddr itm)
              )
              openfile
            )
          )
          (close openfile)
          (startapp "notepad" csv_file)
        )
      )
  (princ)

)

 

 

 

Message 4 of 11
devitg
in reply to: AVFx1410

@AVFx1410 

 

Change as follow 

 


@AVFx1410 wrote:

Hi there everybody!

 

I've been working on excel and manually transcribing the space type (Yellow) the space name (Blue) and the Area (Green)

 

Since this is very recurring for me I was thinking, is it possible to extract the information from the drawing via LISP?

 

I would like to run a command that loops through all polylines and either export information to Excel or Create an AutoCAD table right there in the drawing.

 

Your help is very much appreciated.

 

See drawing attached.

Victor P

 

 


(if (setq ssText (ssget "_CP" pts '((0 . "TEXT"))))
            (setq all_data
                   (cons
                     (list (if (= (sslength ssText) 1)
                             (cdr (assoc 1 (entget (ssname ssText 0))))
                             "-"
                           )
                           ( / area 12 12) ; it divide sqr inches by 12 by 12 to get sqr ft 
                           layer
                     )
                     all_data
                   )
            )
          )

 

Message 5 of 11
Sea-Haven
in reply to: AVFx1410

My $0.05 yes can have a table and / or export to excel. Or make table then export to excel. For me I go direct to excel these days.

 

Turned a few layers off so looking at room 1-055 returns Area: 76324.813 sq. in. (530.033 sq. ft.) note white line used for area.

SeaHaven_0-1684824745003.png

You can get a surrounding area of the room label, by using the bpoly command. So theoretically could get all rooms area based on room name. Not checked (sslength (ssget "X" '((0 . "TEXT")(8 . "SV-TXT-SPACENAME")))) 82 rooms ? So would get area of all rooms automatically.

 

Please note though if a room is not closed may get a wrong answer. Found 1 !

SeaHaven_1-1684825037253.png

 

Guess could do a stop room to large check, show where it is, then run again when fixed.

 

So table yes or no ?

 

Do the rooms change shape so is there a need to update the area for a room ? My answer is just make table again as it will be like 1-2 seconds. 

 

 

 

Message 6 of 11
AVFx1410
in reply to: Sea-Haven

Hi @Sea-Haven 

 

Thanks for your input, I'd like both options to create a table but also export to excel if possible, I know it may be a lot to ask... 

 

The polyline will never change it's shape for my purposes so no need to update it.

 

My reception 1-001 has a polyline so it is weird your drawings does not haha 😄

 

-----------------------------------------------------------------------------------------------------

 

On a different note I am working on some updates my self just for trial and error practice, how would I add another column for the SV-TXT-TYPE layer?

 

Thanks I appreciate every comment! 

 

 

Message 7 of 11
AVFx1410
in reply to: AVFx1410

The lisp attached is more like what I need in terms of columns, however I don't need "ID error", "Polyline Around Text?"

 

Can some one help me modify the attached so that it works properly, I've attached the csv export with some errors.

 

Also would someone help me to remove  the new, append or overwrite options... I don't really need that!

 

Thanks all for your help!

Message 8 of 11
Sea-Haven
in reply to: AVFx1410

"My reception 1-001 has a polyline so it is weird your drawings does not". I am using Bricscad, can not see a pline, no area text either, can you check please the dwg supplied. Also need a line across the doorways to isolate the Reception room say on a non plot layer if want to auto work out areas which is the way I am suggesting do all rooms in one go. Some of the doors have a line across them.

 

Message 9 of 11
AVFx1410
in reply to: Sea-Haven

Hi @Sea-Haven  here is a screen shot of the dwg I attached, I know it looks funny but it is drawn that way by design.

 

The lisp I attached before, kind of works but I get some messed up cells in the CSV 

 

Thanks for looking into it but no need to re-upload, it is good. Just need to get the areas from all the SV-SPACE Polylines might be nice to have a SV-ZONE area column (magenta) especially if it can be stripped from the code if it is no longer needed  and 2 columns more for room id (blue) and space type (yellow)

 

thanks so much and let me know how else I can assist.

 

AVFx1410_0-1684893931372.png

 

Message 10 of 11
Sea-Haven
in reply to: AVFx1410

Ok understand now looking at layer SV-SPACE. Will see what I can do.

Make sure it looks like this when running.

SeaHaven_0-1684903405850.png

 

 

Message 11 of 11
AVFx1410
in reply to: Sea-Haven

@Sea-Haven @devitg 

 

Hey guys any updates sorry to bother you but really need this.

 

Many thanks!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report