Jump to content

Copy line length and paste it in a block attribute


Recommended Posts

Posted
(I assume stepping through with entnext could work to find others?).

I am sorry to say it does not work also expect for 3Dpolyline .

 

Try this Vanilla code to get the length of Straight LWpolyline ONLY .

 

(defun length_LW (e / lst d)
 ;;     Author : Tharwat Al Shoufi        ;;
 ;; To get the length of Straight LWpolyline     ;;
 (foreach x (entget e)
   (if (eq (car x) 10)
     (setq lst (cons (cdr x) lst))
   )
 )
 (setq d 0.)
 (while (and lst
             (not (eq (length lst) 1))
        )
   (setq d   (+ d (distance (car lst) (cadr lst)))
         lst (cdr lst)
   )
 )
 d
)

 

Usage ...

 

(length_LW (car (entsel "\n Select LWpolyline :")))

  • Replies 25
  • Created
  • Last Reply

Top Posters In This Topic

  • CheSyn

    8

  • cmscardoso

    8

  • Tharwat

    6

  • GP_

    2

Posted
@CheSyn

(distance l1 l2) does not work with polylines, lines only.

 

Please see the revised code on this page:

   (if
       (= "LINE" (cdr (assoc 0 lx)) )
       (setq l1 (cdr (assoc 10 lx))
               l2 (cdr (assoc 11 lx))
               ld (rtos (distance l1 l2) 2 0)
       )
       (setq l1 (cdr (assoc 10 lx))
               l2 (cdr (assoc 10 (reverse lx)))
               ld (rtos (distance l1 l2) 2 0)
       )
   )

I used this to differentiate between lines and polylines (only works for a polyline with 2 vertices).

Posted

Well, just to make things a bit more difficult/interesting :roll: is it possible to, in the same drawing, and with an addtional block do this:

 

a) get length of the line

 

b) insert length of the line in the METROS_TOTAL attribute of the IDENTIFICACAO_CABO block

 

c) In another block (CARIMBO-DTE) that has the same insert point of the line and IDENTIFICACAO_CABO block, check one attribute (namely TIPO_ACESSO), and check if it has an "A", an "S" or na "F" and, according to that attribute, fill as follow:

.:. If it has an "A" - Additionally to put total length of the line in the attribute METROS_TOTAL of the IDENTIFICACAO_CABO block, insert it too in attribute METROS_AEREO

.:. If it has an "S" - Additionally to put total length of the line in the attribute METROS_TOTAL of the IDENTIFICACAO_CABO block, insert it too in attribute METROS_CONDUTA

.:. If it has an "F" - Additionally to put total length of the line in the attribute METROS_TOTAL of the IDENTIFICACAO_CABO block, insert it too in attribute METROS_FACHADA

 

And now, what i think that is the most difficult task...

In the same IDENTIFICACAO_CABO block, the text has always the same length - 02fc/01fa/21m - the first 10 digits are inserted manually, but the next 2 digits, are the length inserted in the field METROS_TOTAL. Is it possible to get that METROS_TOTAL value and insert it after the 10 digits and add a final "m" in the end. Example: XXXX/XXXX/"METROS_TOTAL VALUE"m

 

Basically (or not lol), like the attached drawing

 

:twisted::twisted::P

 

Thanks in advanceLineLength2BlockAttribute.dxf

Posted
I am sorry to say it does not work also expect for 3Dpolyline .

 

Try this Vanilla code to get the length of Straight LWpolyline ONLY .

 

 

Interesting, I'll study the code you posted. :)

Posted

Simply to get LINE,POLYLINE,LWPOLYLINE Length

 

  (setq s (car (entsel)))
 (setq d (vlax-curve-getdistatparam s (vlax-curve-getendparam s)))
 (princ d)

Posted
Well, just to make things a bit more difficult/interesting :roll: is it possible to, in the same drawing, and with an addtional block do this:

 

a) get length of the line

 

b) insert length of the line in the METROS_TOTAL attribute of the IDENTIFICACAO_CABO block

 

c) In another block (CARIMBO-DTE) that has the same insert point of the line and IDENTIFICACAO_CABO block, check one attribute (namely TIPO_ACESSO), and check if it has an "A", an "S" or na "F" and, according to that attribute, fill as follow:

.:. If it has an "A" - Additionally to put total length of the line in the attribute METROS_TOTAL of the IDENTIFICACAO_CABO block, insert it too in attribute METROS_AEREO

.:. If it has an "S" - Additionally to put total length of the line in the attribute METROS_TOTAL of the IDENTIFICACAO_CABO block, insert it too in attribute METROS_CONDUTA

.:. If it has an "F" - Additionally to put total length of the line in the attribute METROS_TOTAL of the IDENTIFICACAO_CABO block, insert it too in attribute METROS_FACHADA

 

And now, what i think that is the most difficult task...

In the same IDENTIFICACAO_CABO block, the text has always the same length - 02fc/01fa/21m - the first 10 digits are inserted manually, but the next 2 digits, are the length inserted in the field METROS_TOTAL. Is it possible to get that METROS_TOTAL value and insert it after the 10 digits and add a final "m" in the end. Example: XXXX/XXXX/"METROS_TOTAL VALUE"m

 

Basically (or not lol), like the attached drawing

 

:twisted::twisted::P

 

Thanks in advance

[ATTACH]44181[/ATTACH]

 

Can anyone help please?

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