Nickvnlr Posted April 9 Share Posted April 9 I want to be able to make a selection of lines/polylines/etc and get a report of total length separated by lineweight. This is the LISP I have so far, but it just adds the length of all lines in the drawing and puts the results in the command prompt. I would like to insert the results as text. Any help is appreciated. Thank you! (defun c:SumLengthsByLineweight (/ _length ss e cur data) (setq _Length (lambda (en) (vlax-get en 'Length))) (if (setq ss (ssget "_X" '((0 . "LINE,POLYLINE,LWPOLYLINE")))) (progn (repeat (sslength ss) (setq e (vlax-ename->vla-object (ssname ss 0))) (if (setq cur (assoc (setq lyn (vla-get-LineWeight e)) data)) (setq data (subst (list (car cur) (+ (_Length e) (cadr cur))) cur data)) (setq data (cons (list lyn (_Length e)) data)) ) (ssdel (ssname ss 0) ss) ) (foreach itm data (print itm) (princ)) ) ) ) Quote Link to comment Share on other sites More sharing options...
Nikon Posted April 9 Share Posted April 9 2 hours ago, Nickvnlr said: I would like to insert the results as text. https://lee-mac.com/lengthfield.html Length Field Upon issuing the command syntax LF (Length Field) at the AutoCAD command-line, the program first prompts the user to make a selection of objects for which to return the length summation. At this prompt, the user may select any number of Arcs, Circles, Lines, 2D Polylines (light or heavy), or 3D Polylines. Quote Link to comment Share on other sites More sharing options...
Nickvnlr Posted April 9 Author Share Posted April 9 OK, but I want the results separated by lineweight. Quote Link to comment Share on other sites More sharing options...
Nikon Posted April 9 Share Posted April 9 (edited) In this code, you can see how to insert text into a drawing: ;; inserting the sum of the length of linear objects into the drawing (defun c:LPLINE (/ e ss l p i) (if (setq l 0.0 ss (ssget '((0 . "LINE,SPLINE,LWPOLYLINE,POLYLINE,ARC,CIRCLE,ELLIPSE")))) (progn (repeat (setq i (sslength ss)) (setq e (ssname ss (setq i (1- i))) l (+ l (vlax-curve-getDistAtParam e (vlax-curve-getEndParam e))) ) ) (if (setq p (getpoint "\nSpecify a point to insert text: ")) (entmake (list '(0 . "TEXT") '(100 . "AcDbText") (cons 10 (trans p 1 0)) (cons 40 (/ 5)) (cons 1 (rtos l)) ) ) (princ (strcat "\nTotal length = " (rtos l))) ) ) ) (princ) ) quick selection by line weight, then this lisp... Edited April 9 by Nikon Quote Link to comment Share on other sites More sharing options...
Nickvnlr Posted April 9 Author Share Posted April 9 I can't figure out how to get it to work with multiple lines/items. Quote Link to comment Share on other sites More sharing options...
Jonathan Handojo Posted April 9 Share Posted April 9 A courtesy of mine to share what I use in my workplace. Sums by all general properties CurveTotal.LSP 1 Quote Link to comment Share on other sites More sharing options...
Nickvnlr Posted April 9 Author Share Posted April 9 Thanks, but it gives me an error when trying to insert the table. Command: CRVTOTAL Select objects: Specify opposite corner: 27 found Select objects: Specify insertion point for table <exit>: Error: bad argument type: VLA-OBJECT nil I think there are functions not supported by LT. Quote Link to comment Share on other sites More sharing options...
Jonathan Handojo Posted April 9 Share Posted April 9 Ah, that explains it. My apologies, LT does have major limitation. If summarising it into a table is not achievable, then perhaps you prefer a csv/txt export? Or just in the command line? Quote Link to comment Share on other sites More sharing options...
Nickvnlr Posted April 9 Author Share Posted April 9 For now, perhaps a csv. I appreciate the effort. Quote Link to comment Share on other sites More sharing options...
Jonathan Handojo Posted April 9 Share Posted April 9 This one will now export it to a CSV file. Type CRVTOTALCSV to run the command. CurveTotal_csv.LSP 1 Quote Link to comment Share on other sites More sharing options...
Nickvnlr Posted April 9 Author Share Posted April 9 That works. Thank you! This gives me something to play with and tweak to get what I want. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.