Jump to content

Total length by color


VAC

Recommended Posts

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

Link to comment
Share on other sites

  • 2 weeks later...

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))

 
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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
  )

 

  • Like 1
Link to comment
Share on other sites

  • 3 months later...

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 by VAC
Link to comment
Share on other sites

  • 4 weeks later...

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

Link to comment
Share on other sites

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

 

 

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...