Jump to content
VAC

Total length by color

Recommended Posts

VAC

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

Share this post


Link to post
Share on other sites
BIGAL

Did you google I think it exists. May be over at Forums/autodesk. 

Share this post


Link to post
Share on other sites
VAC

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

 

Share this post


Link to post
Share on other sites
VAC

nobody:-(

Share this post


Link to post
Share on other sites
devitg

Hi VAC, please upload your sample dwg where to apply such lisp

 

Share this post


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

 

Share this post


Link to post
Share on other sites
VAC

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.

Share this post


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
  )

 

Share this post


Link to post
Share on other sites
VAC
Posted (edited)

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

Edited by VAC

Share this post


Link to post
Share on other sites
BIGAL
Posted (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 by BIGAL

Share this post


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.

Share this post


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.   Paste as plain text instead

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