is there a lisp routine to extract Polyline length and width (both) to a table?

is there a lisp routine to extract Polyline length and width (both) to a table?

Anonymous
Not applicable
12,227 Views
12 Replies
Message 1 of 13

is there a lisp routine to extract Polyline length and width (both) to a table?

Anonymous
Not applicable

 

Hi there,

 

I was wondering if anyone knows about a lisp routine to extract Polyline length and Global width (both) to a table?

I have found a lisp routine that only gives me the length in a table (see attachment - LAYLENGTH.lisp).

 

I want to get a quantity take off of many pipe diameters (width) and length that I drew with polyline command.

 

unfortunately I am not good in lisp Coding, is there a savvy in coding  that can modify it and include Global width, please?

 

Thanks.

 

John

0 Likes
Accepted solutions (2)
12,228 Views
12 Replies
Replies (12)
Message 2 of 13

ВeekeeCZ
Consultant
Consultant
Accepted solution
So basically all you need is use the code 43 (width) instead of 8 (layer).
And maybe fix the entity filter to allow just LWPOLYLINE to select.
Message 3 of 13

Anonymous
Not applicable

AWESOME!!

 

Thanks BeeKeecz,

 

it works! 

 

I was wondering if I can include also a code to include a misc object data property (MATERIAL) I added to PoLyline  (see Picture)

 

(I used commands: ADEDEFDATA to define object data and then ADEATTACHDATA to link the object data to the polyline) 

 

I just don't know how to make this field shows in my table as well

 

thanks.

0 Likes
Message 4 of 13

ВeekeeCZ
Consultant
Consultant

Post the dwg sample of this polyline. Not sure if you can attach dwg -- if not, post it on some other cloud and post just a link.

 

Also not sure how the table should look like - just two columns, the 1st column the material, the 2nd would be the length as well?

 

 

I just don't know how to make this field shows in my table as well

 

There is this line in the code:

(setq lst (cons (mapcar '(lambda (a) (strcat "Col" (itoa (1+ (vl-position a (car lst)))))) (car lst)) lst))

change it to

(setq lst (cons '("Width" "Length") lst))

 

And search for "TITLE" is something you can do, right?

 

0 Likes
Message 5 of 13

Anonymous
Not applicable

 

BeeKeeCZ,

 

Basically, I would like to have a third column which includes the material.

 

It can be by adding the data Object property I linked to the polyline or somehow I could be able to fill out the pipe material 

for each pipe (in the polyline properties) and using the code to export it in the table aswell.

 

Thanks.

 

see dwg attached.

0 Likes
Message 6 of 13

ВeekeeCZ
Consultant
Consultant

Hmm, you mean like sorted by width, then by material, then count the lenght? Like this?

 

Width     Material    Length

110           HDPE        25,5

63             HDPE         10

50             HT 50         30

 

If so, that's another story and the code needs to be rewritten...

 

Anyway, I don't have C3D in here so I can't help you right now.. maybe next week if anyone else does not step in... (assuming those functions work in C3D as well)

0 Likes
Message 7 of 13

Anonymous
Not applicable

 

 

You are exactly Right. BeeKeeCZ 

 

that's What I would like to have. 

 

It doesn't have to be in civil 3d it can be in plain Autocad. it will work for me.

 

 

Thanks BeeKeeCZ , whenever you get the chance I will really appreciate that

 

 

john

 

 

 

 

 

0 Likes
Message 8 of 13

ВeekeeCZ
Consultant
Consultant
Accepted solution

Well, I do need C3D  🙂

 

Try the code. If you need different column sorting, see the notes in the code.

 

(vl-load-com)

(defun C:ListMaterial ( / *error* acdoc ss p i e a b ab d l) 

  (setq acdoc (vla-get-activedocument (vlax-get-acad-object)))
  (vla-startundomark acdoc)

  (defun *error* (msg)
    (and
      msg
      (not (wcmatch (strcase msg) "*CANCEL*,*QUIT*,*BREAK*,*EXIT*"))
      (princ (strcat "\nError: " msg))
    )
    (if
      (= 8 (logand (getvar 'undoctl) 8))
      (vla-endundomark acdoc)
    )
    (princ)
    )
  
  (if
    (and
      (setq ss (ssget ":L" '((0 . "LWPOLYLINE"))))
      (setq p (getpoint "\nTable scale depend on annotation scale.\nSpecify table insert point: "))
      )
    (progn
      (repeat
        (setq i (sslength ss))
        (setq e (ssname ss (setq i (1- i)))
              a (cdr (assoc 43 (entget e)))
              b (ade_odgetfield e "Pipes" "Material" 0)
              d (vlax-curve-getdistatparam e (vlax-curve-getendparam e))
        )
        (or b (setq b ""))
        (setq ab (cons b a))
        (if
          (setq o (assoc ab l))
          (setq l (subst (list ab (+ (cadr o) d)) o l))
          (setq l (cons (list ab d) l))
        )
      )
      (setq l (vl-sort l '(lambda (a b) (< (cdar a) (cdar b))))
            l (vl-sort l '(lambda (a b) (< (caar a) (caar b))))
            l (mapcar '(lambda (x) (list (caar x) ; Material 
                                         (cdar x) ; Size 
                                         (cadr x))) ; Length
                      l))
      (insert_table l p)
      )
    )
  (*error* nil)
  (princ)
  )

(defun insert_table (lst pct / tab row col ht i n space)
  (setq space (vlax-get acDoc (if (= 1 (getvar 'cvport)) 'PaperSpace 'ModelSpace))
        ht  (/ 2.5 (cond ((getvar 'cannoscalevalue)) (1.0)))
        pct (trans pct 1 0)
        n   (trans '(1 0 0) 1 0 T)
        tab (setq tab (vla-addtable space (vlax-3d-point pct) (+ 2 (length lst)) (length (car lst)) (* 2.5 ht) ht))
        )
  (vlax-put tab 'direction n)
  
  (mapcar
    (function
      (lambda (rowType)
        (vla-SetTextStyle  tab rowType (getvar 'textstyle))
        (vla-SetTextHeight tab rowType ht)
      )
    )
   '(2 4 1)
  )
  
  (vla-put-HorzCellMargin tab (* 0.14 ht))
  (vla-put-VertCellMargin tab (* 0.14 ht))

  (setq lst (cons '("Material" "Size" "Length") lst)) 

  (setq i 0)
  (foreach col (apply 'mapcar (cons 'list lst))
    (vla-SetColumnWidth tab i
      (apply
        'max
        (mapcar
          '(lambda (x)
             ((lambda (txb) (+ (abs (- (caadr txb) (caar txb))) (* 2.0 ht)))
              (textbox (list (cons 1 (vl-princ-to-string x)) (cons 7 (getvar 'textstyle)) (cons 40 ht)))
              )
             )
          col
          )
        )
      )
    (setq i (1+ i))
    )
  
  (setq lst (cons '("MATERIAL LIST") lst))
  
  (setq row 0)
  (foreach r lst
    (setq col 0)
    (vla-SetRowHeight tab row (* 1.5 ht))
    (foreach c r
      (vla-SetText tab row col (if (numberp c) (rtos c) (vl-princ-to-string c)))
      (setq col (1+ col))
      )
    (setq row (1+ row))
    )
  )
Message 9 of 13

braudpat
Mentor
Mentor

 

Hello Mr BeekeeCZ

 

I like your ListMaterial routine for ACAD MAP !

 

Thanks, Regards, Patrice

 

Patrice ( Supporting Troops ) - Autodesk Expert Elite
If you are happy with my answer please mark "Accept as Solution" and if very happy please give me a Kudos (Felicitations) - Thanks

Patrice BRAUD

EESignature


0 Likes
Message 10 of 13

ВeekeeCZ
Consultant
Consultant

Thank you @braudpat 

 

Unfortunately I'm not the original author. @Anonymous posted here the code with no author reference, but you've made me to search for him - the code is pretty good!

 

So thanks @phanaem for the code! One of the versions was posted HERE by the author.

Hope you don't mind my modifications. 

0 Likes
Message 11 of 13

Anonymous
Not applicable

 

Thanks BeeKeecz,

 

It was exactly what I was looking for.

 

Great job!!

0 Likes
Message 12 of 13

Anonymous
Not applicable

I want the lisp to add 3 columns (layer in first column ,width in second column ,length in third column)

0 Likes
Message 13 of 13

ppesquera
Participant
Participant

is there a version of this lisp that is compatible with autocad lt? unfortunately, ADEODGETFIELD is only exclusive to ACAD Map 3D

0 Likes