VAC Posted March 26, 2021 Posted March 26, 2021 Hi, can anybody help me to do a lisp that will count total length of selected lines, polylines,....sorted by colour (0-256)? Output to MText/table like: 1 (color number - red) - calculated total length 2 - calculated total length 3 - not found......this line will not show in the list 4 - calculated total length .... Super should be, if this lisp should be run on just selected items (with for example selectsimilar command), (not to run this script and then select items) Lee Mac script is fine, but does not recognize colors and final value prints only into command line - I prefere to clipboard. How can I modify his lisp? http://www.lee-mac.com/totallengthandarea.html Many thanks Quote
BIGAL Posted March 27, 2021 Posted March 27, 2021 Did you google I think it exists. May be over at Forums/autodesk. Quote
VAC Posted March 27, 2021 Author Posted March 27, 2021 (edited) I googled, but found only byLayer or another, none by color: https://www.cadstudio.cz/en/download.asp?file=AddLen https://forums.autodesk.com/t5/forums/searchpage/tab/message?advanced=false&allow_punctuation=false&filter=location&location=category:AutoCADTopic1&q=total length Edited March 27, 2021 by VAC Quote
VAC Posted March 27, 2021 Author Posted March 27, 2021 Now I found one, but it calculate it from whole drawing. I need only selected items. Any idea how to modify it? Quote
devitg Posted April 7, 2021 Posted April 7, 2021 Hi VAC, please upload your sample dwg where to apply such lisp Quote
BIGAL Posted April 8, 2021 Posted April 8, 2021 Its a good idea to ask the Author 1st in this case Lee-mac who is very helpful and often repsonds with like change just this one line to suit your needs. Ok a big hint when using ssget you can have multiple filters ssget "object type" "is plines" "color is" eg (setq ss (ssget (list (cons 0 "ARC,CIRCLE,ELLIPSE,LINE,*POLYLINE,SPLINE")(cons 62 1)))) You home work, what is 62 Copy to clipboard example (defun testclip (str / pt dist ) (vlax-invoke (vlax-get (vlax-get (vlax-create-object "htmlfile") 'ParentWindow) 'ClipBoardData) 'setData "TEXT" str ) (princ) ) (testclip (rtos l 2 2)) Quote
VAC Posted April 9, 2021 Author Posted April 9, 2021 I've uploaded sample file. Maybe 62 is ByLayer? 1 is red colour. I don't know lisp language. I don't know, how to ask Lee Mac directly. Quote
Tharwat Posted April 9, 2021 Posted April 9, 2021 Hi VAC, Try the following which compute lengths of selected Lines & Polylines based on your request from the first post and the program would ignore the colour ByLayer as long as you wanted to filter them from ( 0 - 256 ) and sort them by colour number for a better presentation. (defun c:Test ( / int sel ent clr len fnd new lst ins tbl row col) ;; Tharwat - Date: 9.April.2021 ;; (and (princ "\nSelect object to computer lengths into AutoCAD Table : ") (setq int -1 sel (ssget '((0 . "LINE,*POLYLINE")))) (while (setq int (1+ int) ent (ssname sel int)) (and (setq clr (cdr (assoc 62 (entget ent)))) (or (and (setq len (vlax-curve-getdistatparam ent (vlax-curve-getendparam ent))) (setq fnd (assoc clr lst)) (setq new (list clr (+ (cadr fnd) len)) lst (vl-remove fnd lst) lst (cons new lst) ) ) (setq lst (cons (list clr len) lst)) ) ) ) (setq lst (vl-sort lst '(lambda (j k) (< (car j) (car k))))) (setq ins (getpoint "\nSpecify Table insertion point : ")) (setq tbl (vla-addtable (vlax-get (vla-get-activelayout (vla-get-activedocument (vlax-get-acad-object))) 'BLOCK) (vlax-3d-point ins) (1+ (length lst)) 2 900 4125) ) (_write:data 0 0 "Length Calculation") (setq row 1 col -1) (foreach itm lst (foreach str (list (car itm) (rtos (cadr itm) 2 2)) (_write:data row (setq col (1+ col)) str) ) (setq row (1+ row) col -1 ) ) ) (princ) ) (vl-load-com) ;; ;; (defun _write:data (r c s) (vla-settext tbl r c s) (vla-setcelltextheight tbl r c 450) (vla-setrowheight tbl r 900) (vla-setcellalignment tbl r c acMiddleCenter) s ) 1 Quote
VAC Posted April 9, 2021 Author Posted April 9, 2021 (edited) Hi, it works great. Many thanks. I will test it more later. Edited April 9, 2021 by VAC Quote
BIGAL Posted April 10, 2021 Posted April 10, 2021 (edited) A good idea you need to look into the DXF codes and what they mean for common variables like Layer, Color, Insertion point, name and so on. After a while just remember. DXF Reference (autodesk.com) Edited April 10, 2021 by BIGAL Quote
Tharwat Posted April 10, 2021 Posted April 10, 2021 18 hours ago, VAC said: Hi, it works great. Many thanks. I will test it more later. You're welcome anytime. Quote
VAC Posted July 23, 2021 Author Posted July 23, 2021 (edited) Hi, I use this script, it works great. Shoud it be possible to add possibility to count even entities that are set to ByLayer or ByBlock (separately from others of course)? Thanks Edited July 23, 2021 by VAC Quote
VAC Posted August 20, 2021 Author Posted August 20, 2021 Hi, Please, how to count even ByLayer colors (or TrueColored). Script generates nothing if one of the selected lines is set to ByLayer. It should be very usefull for me to count even ByLayer colored lines separetedly - so it will show me my mistakes in the file (I have to set all the lines with not ByLayer colours). Implementing even TrueColored lines would be wonderfull. Or at least count them to ByLayer package - it is a mistake for me too. Now it assigns and mainly counts TrueColored lines to nearest 0-256 color, so it generates mistakes for me. (for ex. TrueColor 75,91,180 goes to color 165). Many thanks Quote
mhupp Posted August 20, 2021 Posted August 20, 2021 On 4/9/2021 at 4:18 AM, VAC said: I've uploaded sample file. Maybe 62 is ByLayer? 1 is red colour. I don't know lisp language. I don't know, how to ask Lee Mac directly. use and @ sign @VAC https://www.afralisp.net/reference/dxf-group-codes.php Quote
BIGAL Posted August 21, 2021 Posted August 21, 2021 For a line If using (entget (car (entsel a line say Bylayer there will be no 62 value indicating line is "bylayer", but can get objects bylayer = 256 using ssget. (sslength (ssget "X" (list '(0 . "LINE")(cons 62 1)))) 1 : (sslength (ssget "X" (list '(0 . "LINE")(cons 62 256)))) 2 Quote
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.