Jump to content

Total length by color


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 post
Share on other sites

Now I found one, but it calculate it from whole drawing. I need only selected items. Any idea how to modify it?

 

Link to post
Share on other sites
  • 2 weeks later...
BIGAL

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 post
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 post
Share on other sites
Tharwat

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
  )

 

Link to post
Share on other sites
Posted (edited)

Hi, it works great. Many thanks. I will test it more later.

Edited by VAC
Link to post
Share on other sites
Tharwat
18 hours ago, VAC said:

Hi, it works great. Many thanks. I will test it more later.

 

You're welcome anytime.

Link to post
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
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...