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

Extrapolating Individual Lines

15 REPLIES 15
Reply
Message 1 of 16
MaliktheOne
923 Views, 15 Replies

Extrapolating Individual Lines

Hello all,

 

I'm currently using AutoCAD LT and am looking for a Lisp that can help me extract the lengths of individual lines and export those measurements to Excel or CSV.

 

I came across a Lisp called LAYLENGTH that lets me extract line lengths, but it only totals up the lengths of all lines on a given layer rather than measuring each line individually. As shown in the attached picture, this isn't quite what I need.

 

Does anyone know of a Lisp or another method to get individual line lengths and export them? Any advice would be greatly appreciated!

mrahman4VVMK_0-1723735085325.png

 

 

I've also attached the lisp of the LAYLENGTH program as well to see if anyone could change the program to fit my purpose. 

 

Tags (2)
15 REPLIES 15
Message 2 of 16
ec-cad
in reply to: MaliktheOne

The Lisp you attached, gets more than just lines and builds a table.

You just want the 'length' of 'line' s to be exported to a .csv file ?

Post a small sample drawing, and explain exactly what lines you mean, or specifics about

Lines on particular Layers .. include Polylines ?, just a little more information than you have

in your post. I'm sure we can come up with a Lisp to do that (it's been done many times before).

 

ECCAD

Message 3 of 16
MaliktheOne
in reply to: ec-cad

Hello,

 

Yes, I’m looking for a way to get the length of each individual line and export that data to a CSV file. I need to be able to import this data of lengths into Excel for my work.

 

mrahman4VVMK_0-1723739892999.png

I would like to extract the individual lines with the varying lengths shown in the pic above into a table that are from the same layers. 

 

Hopefully this explains what I am trying to achieve. 

Message 4 of 16
ec-cad
in reply to: MaliktheOne

OK,

Working on it now.

🙂

ECCAD

Message 5 of 16
Moshe-A
in reply to: MaliktheOne

@MaliktheOne  hi,

 

DATAEXRACTION command will do that for you, no need for lisp

 

Moshe

Message 6 of 16
MaliktheOne
in reply to: Moshe-A

I dont think I have that command in Autocad LT 

Message 7 of 16
ec-cad
in reply to: MaliktheOne

OK, here's the Lisp. I see you have LT , hope it supports Lisp.

 

 

 

;; Export_Lines_to_csv.lsp
;; Function call: GO
;; Written by: ECCAD , Control Systems & Services, LLC (Arizona LLC)
;; Revision: 1.0, Aug 15, 2024 for Acad Forum

 (defun C:GO ( / path nam OUTFILE O OX ofil ss Count lay pt1 pt2 len)

  (setq path (getvar "dwgprefix")); includes the "\\"
  (setq nam (getvar "dwgname"))
  (setq nam (substr nam 1 (- (strlen nam) 4))); strip the .dwg
  (setq OUTFILE (strcat path nam "_Line_Report.csv"))

;; Function to output to the .csv file
 (defun write_to_csv_file ( S ); send in 'string', formatted as .csv
   (if (findfile OUTFILE)
    (progn
     (setq FLAG 0)
     (setq ofil (open OUTFILE "a"))
     (write-line S ofil)
     (close ofil)
    ); progn
   ); if
   (if (not (findfile OUTFILE))
    (progn
     (setq FLAG 0)
     (setq ofil (open OUTFILE "w"))
;; Header
     (setq OX (strcat
        (chr 34) "LINE#" (chr 34) ","
        (chr 34) "LAYER" (chr 34) ","
        (chr 34) "LENGTH" (chr 34) ",,"
     )); setq/strcat
     (write-line OX ofil)
     (write-line S ofil)
     (close ofil)
    ); progn
   ); if
 ); function

 

 

 

Looks like the Forum clipped some of the code.. see the .lsp attached.

 

ECCAD

 

Message 8 of 16
Sea-Haven
in reply to: MaliktheOne

A couple of decisions, 

 

Make a table only,

Send direct to Excel only

Make a table and send to Excel

 

For me direct to Excel or LibreCad Calc no CSV.

 

I ask as like others can do all 3. 

 

Do you don't want more objects ? Can be "please choose object type" also. Trying to avoid repeated goes at the code.

 

Lastly post sample dwg with desired table, so can size correctly.

Message 9 of 16
MaliktheOne
in reply to: ec-cad

Hello @ec-cad,

 

Thank you so much for the lisp for the exporting of lines. Is it possible to change the program for circles and rectangles instead of lines?

 

 

Message 10 of 16
ec-cad
in reply to: MaliktheOne

Sure, couple of questions:

You said "Is it possible to change the program for circles and rectangles instead of lines?"

Does that mean to 'exclude' Lines ? "instead of lines" ...

What information do you need for the Circles ? Radias / Diameter / Center / Circumfrence?

And for the Rectangles, Are they Polylines - Closed, or Open ? or just lines that form a Rectangle ?

Any specific Layers to check for Circles / Rectangles ?

So many questions, I know..

Awaiting your response.

 

ECCAD

 

Message 11 of 16
ec-cad
in reply to: MaliktheOne

This one will do just the Circles. May have too much info, but you could remove data items if needbe.

Awaiting answers to the Rectangles. When done, we can make a single Lisp, that asks for 'what' type

of items you want to export. A for All, L for Lines, C for Circles, R for Rectangles, etc.

 

ECCAD

Message 12 of 16
MaliktheOne
in reply to: ec-cad

Hello @ec-cad 

 

Thank you so much for the LISP for the circle extraction. 

 

For the rectangle, I am using the rectangle polyline function that is provided from the autocad LT. I would like for to export the width, length, and layers if possible.

 

That would be great if we could combine all of them. 

Message 13 of 16
ec-cad
in reply to: MaliktheOne

Sure, make up a small sample drawing with Layers, and Polylines and attach.

 

I'll see what I can do.

Once we get the last piece in place, we'll tie them all together and output

all that stuff.

 

ECCAD

Message 14 of 16

Hi, @MaliktheOne 

 

As an option. If such lisp's operates in LT.
XDTOOLS_PROP2 - save values of objects properties in their XData. (Your interface will be in English).

XDTOOLS_PROP2_ru.png

XDTOOLS_2CSV - unload XData content to txt, csv.
Of course, first you need to create/edit XData definition - XDTOOLS_MDEFINE.
Then attach the required XData to many objects - XDTOOLS_ADD.
Etc.

 


-- Alexander, private person, pacifist, english only with translator 🙂 --

Object-modeling _ odclass-odedit.com _ Help

Message 15 of 16
ec-cad
in reply to: MaliktheOne

I'm assuming your 'Rectangle Polyline' routine just outputs "LWPolyLines", in the form of a Rectangle.

This Lisp attached, will report those Rectangles.

Now that we have Lines / Circles / Rectangles, how do you want the 'output' .csv file stacked ?

Since each item has a little different Header Line, do you want (3) Header Lines, seperating

the Lines from the Circles, and the Circles from the Rectangles. Then the final report would

be Header for Lines, line data, Header for Circles, circle data, and lastly, Header for Rectangles,

rectangle data .. ???

 

ECCAD

Message 16 of 16
Sea-Haven
in reply to: ec-cad

This is something I did for this type of task, I just use (if (not AH:plprops)(load "Pline line arc props")) so no need to have all the code in multiple lisps.

 

 

; properties use as a library function
; By Alan H july 2020

(defun AH:cords (obj / co-ords xy )
(setq coordsxy '())
(setq co-ords (vlax-get obj 'Coordinates))
(setq numb (/ (length co-ords) 2))
(setq I 0)
(repeat numb
(setq xy (list (nth (+ I 1) co-ords)(nth I co-ords) ))
(setq coordsxy (cons xy coordsxy))
(setq I (+ I 2))
)
)


(defun AH:chkcwccw (obj / lst newarea)
(setq lst (CORDS obj))
(setq newarea
(/ (apply (function +)
            (mapcar (function (lambda (x y)
                                (- (* (car x) (cadr y)) (* (car y) (cadr x)))))
                    (cons (last lst) lst)
                    l)) 
2.)
)
(if (< newarea  0)
(setq cw "F")
(setq cw "T")
)
)

; Can use reverse in Autocad - pedit reverse in Bricscad.

(defun AH:plprops (obj txt / lst)
(foreach val lst
(cond
((= (strcase val)  "LAY") (setq lay (vla-get-layer obj)))
((= (strcase val) "AREA")(setq area (vla-get-area obj)))
((= (strcase val) "START")(setq start (vlax-curve-getstartpoint obj)))
((= (strcase val) "END" (strcase txt))(setq end (vlax-curve-getendpoint obj)))
((= (strcase val) "LEN" (strcase txt))(setq len (vlax-get obj 'Length)))
((= (strcase val) "CW" (strcase txt))(AH:chkcwccw obj))
((= (strcase val) "CORDS" (strcase txt))(CORDS obj))
((= (strcase val) "MID" (strcase txt))(setq mp (vlax-curve-getpointatdist obj(/ (vlax-get obj 'Length) 2.0))))
)
)
)

(defun AH:lineprops (obj lst / )
(foreach val lst
(cond
((= (strcase val)  "LAY") (setq lay (vlax-get obj 'layer)))
((= (strcase val) "START")(setq start (vlax-get obj 'startpoint)))
((= (strcase val) "END" (strcase txt))(setq end (vlax-get obj 'endpoint)))
((= (strcase val) "LEN" (strcase txt))(setq len (vlax-get obj 'Length)))
((= (strcase val) "MID" (strcase txt))(setq mp (mapcar '* (mapcar '+ (vlax-get obj 'startpoint)(vlax-get obj 'endpoint)) '(0.5 0.5))))
)
)
)

(defun AH:circprops (obj lst / )
(foreach val lst
(cond
((= (strcase val)  "LAY") (setq lay (vlax-get obj 'layer)))
((= (strcase val) "LEN" (strcase txt))(setq len (vlax-get obj 'Circumference)))
((= (strcase val) "RAD" (strcase txt))(setq rad (vla-get-radius obj)))
((= (strcase val) "CEN" (strcase txt))(setq cen (vlax-get obj 'Center)))
((= (strcase val) "AREA" (strcase txt))(setq end (vlax-get obj 'AREA)))
)
)
)

(defun AH:arcprops (obj txtlst)
(foreach val lst
(cond
((= (strcase val) "LAY") (setq lay (vlax-get obj 'layer)))
((= (strcase val) "LEN" (strcase txt))(setq len (vlax-get obj 'length)))
((= (strcase val) "RAD" (strcase txt))(setq rad (vlax-get obj 'radius)))
((= (strcase val) "CEN" (strcase txt))(setq cen (vlax-get obj 'Center)))
((= (strcase val) "START" (strcase txt))(setq start (vlax-get obj 'startpoint)))
((= (strcase val) "END" (strcase txt))(setq area (vlax-get obj 'endpoint)))
((= (strcase val) "AREA" (strcase txt))(setq end (vlax-get obj 'AREA)))
((= (strcase val) "MID" (strcase txt))(setq mp (vlax-curve-getpointatdist obj(/ (vlax-get obj 'ArcLength) 2.0))))
)
)
)

; starts here
; (setq ent (vlax-ename->vla-object (car (entsel "Pick Object "))))
; do a check for object type then use defun
; pick an example below


; many examples copy to command line for testing mix and match 
; (AH:plprops ent '("LAY"))(princ lay)
; (AH:plprops ent '("END"))(princ end)
; (AH:plprops ent '("START"))(princ start)
; (AH:plprops ent '("END" "START"))(princ end)(princ start)
; (AH:plprops ent '("AREA" "LAY" "END" "START"))(princ area)(princ lay)(princ end)(princ start)
; (AH:plprops ent '("START" "AREA" "LAY" "CW"))(princ start)(princ area)(princ cw)
; (AH:plprops ent '("start" "END" "CORDS" "cw"))(princ start)(princ end)(princ coordsxy)(princ cw)
; (AH:plprops ent '("CW"))(princ cw)
; (AH:plprops ent '("AREA"))(princ area)
; (AH:plprops ent '("CORDS"))(princ coordsxy)
; (AH:lineprops ent "len"))(princ len)
; (AH:lineprops ent '("len" "lay"))(princ len)(princ lay)
; (AH:lineprops ent '("lay" "end" "start" "len"))(princ len)(princ lay)(princ start)(princ end)
; (AH:circprops ent '("lay" "rad" "area" "cen"))(princ lay)(princ rad)(princ area)(princ cen)
; (AH:circprops ent '("lay" "rad"))
; (AH:arcprops ent '("lay" "rad"))



 

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