Jump to content

Recommended Posts

Posted

Hey all

I have to annotate drawings to show footages, and the current method I use is pretty inefficient.

right now I need to draw a polyline click it check the footage then delete that polyline then edit a block to show that footage. This gets beyond tedious on larger jobs.

 

Is there a way to draw a polyline have it automatically pop up the length of that polyline via text or even just the command line then delete said polyline?

 

Posted

Try this one, It gives all selected polyline dimensions.. You can select similar the Pline and delete it later.

DIMENSION POLY.LSP

Posted

Well I hope this can help you with what you do.

;;;;;;;;;;;; Program lp2t selects a pline and puts its length in to a new text.
;;;;;;;;;;;;
;;;;;;;;;;;; by Isaac A. 20210603
;;;;;;;;;;;; https://www.cadtutor.net/forum/topic/73155-polyline-lengths/?_fromLogin=1

;********** Program to obtain the length of a pline and put it into a text **********
(vl-load-com)
(defun C:lp2t (/ long poli)
   (setvar "cmdecho" 0)
   (vl-cmdf "_.undo" "_begin")
   (setq oldosm (getvar "osmode"))

   (setvar "osmode" 0)
   (setq poli (car (entsel "\nSelect the polyline")))
   (setq long 0)
   (vl-cmdf "_.area" "_e" poli)
   (setq long (getvar "perimeter"))
   (setq pt11 (getpoint "Pick a point to insert the text"))
   (vl-cmdf "_.style" "times" "times new roman" "0" "1" "" "" ""
            "_.text" "_s" "times" pt11 "1" "0" (strcat "L=" (rtos long 2 2) "m."))

   (vl-cmdf "_.undo" "_end")
   (setvar "osmode" oldosm)
   (princ "\n")
   (princ)
) 								;;; Ends c:lp2t

 

Posted

Just for fun. :)

If your current text style with zero height then the program would get the width factor as the text height instead.

 

(defun c:Test (/ old new len ins sty str get grd)
  ;; Tharwat - 3.Jun.2021	;;
  (setq old (entlast))
  (vl-cmdf "_.Pline")
  (while (< 0 (getvar 'CMDACTIVE))
    (vl-cmdf "\\")
  )
  (and (not (equal old (setq new (entlast))))
       (setq
         len (vlax-curve-getdistatparam new (vlax-curve-getendparam new))
       )
       (entdel new)
       (setq ins (trans (cadr (grread 13 0)) 1 0)
             sty (getvar 'TEXTSTYLE)
             str (entmakex
                   (list
                     '(0 . "TEXT")
                     (cons 10 ins)
                     (cons 11 ins)
                     (cons 40
                           (cdr
                             (assoc
                               (if
                                 (zerop
                                   (cdr
                                     (assoc
                                       40
                                       (setq get (entget (tblobjname "STYLE" sty)))
                                       )
                                     )
                                   )
                                 41
                                 40
                                 )
                               get
                               )
                             )
                           )
                     (cons 1 (rtos len 2 2))
                     (cons 7 sty)
                     )
                   )
             get (entget str)
             )
       (while (= (car (setq grd (grread t 15 0))) 5)
         (entmod (subst (cons 10 (cadr grd)) (assoc 10 get) get))
         )
       )
  (princ)
)



 

Posted (edited)

This allows you to select multiple objects at once and add them all up.

 

;;----------------------------------------------------------------------;;
;ADD UP TOTAL LENGHTS OF SELECTED OBJECTS.
(defun c:TLEN (/ e ss len i)
  (setq len 0.0 ss (ssget '((0 . "LINE,SPLINE,LWPOLYLINE,POLYLINE,ARC,CIRCLE,ELLIPSE"))))
  (foreach e (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
    (setq len (+ len (vlax-curve-getDistAtParam e (vlax-curve-getEndParam e))))
  )
  (princ (strcat "\nTotal length = " (rtos len 2 3)))
  (vlax-invoke (vlax-get (vlax-get (vlax-create-object "htmlfile") 'ParentWindow) 'ClipBoardData) 'setData "TEXT" (rtos len 2 3))
  ;above copys to clipboard
  (princ)
)

 

Added the last line so it also copies it to the clipboard so when you edit your block all you have to do is Ctrl+V to paste the value.

 

Total length = 231.311
Ctlr+V will past  "231.311"

Edited by mhupp
  • Like 1
Posted
1 hour ago, Isaac26a said:

Well I hope this can help you with what you do.


;;;;;;;;;;;; Program lp2t selects a pline and puts its length in to a new text.
;;;;;;;;;;;;
;;;;;;;;;;;; by Isaac A. 20210603
;;;;;;;;;;;; https://www.cadtutor.net/forum/topic/73155-polyline-lengths/?_fromLogin=1

;********** Program to obtain the length of a pline and put it into a text **********
(vl-load-com)
(defun C:lp2t (/ long poli)
   (setvar "cmdecho" 0)
   (vl-cmdf "_.undo" "_begin")
   (setq oldosm (getvar "osmode"))

   (setvar "osmode" 0)
   (setq poli (car (entsel "\nSelect the polyline")))
   (setq long 0)
   (vl-cmdf "_.area" "_e" poli)
   (setq long (getvar "perimeter"))
   (setq pt11 (getpoint "Pick a point to insert the text"))
   (vl-cmdf "_.style" "times" "times new roman" "0" "1" "" "" ""
            "_.text" "_s" "times" pt11 "1" "0" (strcat "L=" (rtos long 2 2) "m."))

   (vl-cmdf "_.undo" "_end")
   (setvar "osmode" oldosm)
   (princ "\n")
   (princ)
) 								;;; Ends c:lp2t

 

This works out pretty well for what i need (i havent tried the other suggestions yet though) What variable do i change to make the text larger? I have figured out how to edit the text output to drop the L= and m to say something along the lines of 103' which is perfect just not sure which variable changes the size of the text.

Posted

Disregard that I fiddled around with it and figured it out I appreciate all of yall's help! I am going to test out the other ones when I go in tonight i work night shift.

  • Like 1
Posted (edited)

I lied I havent yet got it nailed down. I need to change the style to 120-temp and the text height to 12. 

Heres what I did to what you wrote keep in mind I have next to no idea what im looking at I only know basic C++ and this style of coding is a bit odd to say the least coming from that. I was able to get it to change to 120-temp but the text height ends up going to 144.

 

 

;;;;;;;;;;;; Program lp2t selects a pline and puts its length in to a new text.
;;;;;;;;;;;;
;;;;;;;;;;;; by Isaac A. 20210603
;;;;;;;;;;;; https://www.cadtutor.net/forum/topic/73155-polyline-lengths/?_fromLogin=1

;********** Program to obtain the length of a pline and put it into a text **********
(vl-load-com)
(defun C:lp2t (/ long poli)
   (setvar "cmdecho" 0)
   (vl-cmdf "_.undo" "_begin")
   (setq oldosm (getvar "osmode"))

   (setvar "osmode" 0)
   (setq poli (car (entsel "\nSelect the polyline")))
   (setq long 0)
   (vl-cmdf "_.area" "_e" poli)
   (setq long (getvar "perimeter"))
   (setq pt11 (getpoint "Pick a point to insert the text"))
   (vl-cmdf "_.style" "times" "120-TEMP" "0" "1" "" "" ""                               ;;;;;i dont understand this area as of yet not sure what its doing?
            "_.text" "_s" "120-temp"  "0" "0" (strcat (rtos long 2 0) "'"))            ;;;;;This area "120-TEMP" seems to set the value to that style of text? the first zero ;;;;;;seems to be associated with the height of the text assuming times new roman in the original. rtos long 2 0 changed to 0 to round up/down i dont ;;;;;;need the decimal precision.  

   (vl-cmdf "_.undo" "_end")
   (setvar "osmode" oldosm)
   (princ "\n")
   (princ)
) 

 

i added a few comments in it to show my thought process let me know if i am completely off base.

Edited by SLW210
Added Code Tags!!
Posted (edited)
;;;;;;;;;;;; Program lp2t selects a pline and puts its length in to a new text.
;;;;;;;;;;;;
;;;;;;;;;;;; by Isaac A. 20210603
;;;;;;;;;;;; https://www.cadtutor.net/forum/topic/73155-polyline-lengths/?_fromLogin=1

;********** Program to obtain the length of a pline and put it into a text **********
(vl-load-com)
(defun C:tt (/ long poli)
   (setvar "cmdecho" 0)
   (vl-cmdf "_.undo" "_begin")
   (setq oldosm (getvar "osmode"))

   (setvar "osmode" 0)
   (setq poli (car (entsel "\nSelect the polyline")))
   (setq long 0)
   (vl-cmdf "_.area" "_e" poli)
   (setq long (getvar "perimeter"))
   (setq pt11 (getpoint "Pick a point to insert the text"))
   (vl-cmdf "_.style" "120-temp" "times new roman" "0" "1" "" "" ""
            "_.text" "_s" "120-TEMP" pt11 "12" "0" (strcat (rtos long 2 0) "'"))

   (vl-cmdf "_.undo" "_end")
   (setvar "osmode" oldosm)
   (princ "\n")
   (princ)
) 

 

That ended up working exactly how I wanted. I dont know how or why it does but there it is if someone comes behind me and sees this post. 

Edited by SLW210
Added Code Tags!!
Posted
1 minute ago, Chrisbc said:

That ended up working exactly how I wanted. I dont know how or why it does but there it is if someone comes behind me and sees this post. 

;;;;;;;;;;;; Program lp2t selects a pline and puts its length in to a new text.
;;;;;;;;;;;;
;;;;;;;;;;;; by Isaac A. 20210603
;;;;;;;;;;;; https://www.cadtutor.net/forum/topic/73155-polyline-lengths/?_fromLogin=1

;********** Program to obtain the length of a pline and put it into a text **********
(vl-load-com)
(defun C:lp2t (/ long poli)
   (setvar "cmdecho" 0)
   (vl-cmdf "_.undo" "_begin")			;;; This is set so you can undo every change in just one undo
   (setq oldosm (getvar "osmode"))		;;; Saving your osnap settings

   (setvar "osmode" 0)				;;; Setting the osnap to none
   (setq poli (car (entsel "\nSelect the polyline")))
   (setq long 0)
   (vl-cmdf "_.area" "_e" poli)
   (setq long (getvar "perimeter"))
   (setq pt11 (getpoint "Pick a point to insert the text"))
   (vl-cmdf "_.style" "120-TEMP" "times new roman" "0" "1" "" "" ""	;;; You're calling the style 120-TEMP
                                                           ;;; The first 0 is for the size of the text, but if you put it to 0,
                                                           ;;; you dont' affect the other texts that already exist, the 1 is for the width factor
            "_.text" "_s" "120-TEMP" pt11 "12" "0" (rtos long 2 0))   ;;; Here you set the size to 12, and you're right about the decimals
      ;;; But since you just seem to need the plain lenght there is no need for (strcat )

   (vl-cmdf "_.undo" "_end")			;;; Here is where the undo ends
   (setvar "osmode" oldosm)			;;; Restoring your osnap settings
   (princ "\n")
   (princ)
) 								;;; Ends c:lp2t

For the next time(s) please when pasting a code use the <> (Code paste) button so becomes clearer

I hope now the code is more explained.

Posted
12 hours ago, Chrisbc said:

Is there a way to draw a polyline have it automatically pop up the length of that polyline via text or even just the command line then delete said polyline?

 

 

Apparently you have changed your mind with what asked for and with the one you wanted to select the polyline. !

Posted

Ah tharwat i havent tried yours just yet I just ended up running with that one because I could understand it a little easier (mostly cuz im clueless on how to read this code). I plan on trying the other solutions later tonight. 

Posted

Thwart I just tried yours that is actually exactly what I asked for originally honestly I should have tried all of them before tinkering with the other one. Thanks a lot. the only issue I have with it is I dont see how to change the text like I did with the other lisp. Very impressive I know lisps are probably simple for yall but to me its a leap to get even basic programs to work.  

Posted
2 minutes ago, Chrisbc said:

Thwart I just tried yours that is actually exactly what I asked for originally honestly I should have tried all of them before tinkering with the other one. Thanks a lot. the only issue I have with it is I dont see how to change the text like I did with the other lisp. Very impressive I know lisps are probably simple for yall but to me its a leap to get even basic programs to work.  

Good to hear that.

You can replace the entire code from (cons 40 ......) and with your desired / fixed one like for example: (cons 40 0.2) 

Posted

Okay I replaced it like ya said and sure enough I can get it to scale up/down (cons 40 12) made it text height 12. would i need to add something like the other code had to make it say.   20'  per say 

for example

(cons 40 12 " ' " )?

Posted

Yeah I figured that one out by messing it up hehe. Where does the code take the information it collects then dump it into the text line. forgive the ignorance here. 

for example in C lets say

input: length

output: footage

 

Footage = length + '

 

So for example it would input the length from the selected entity 

then output footage+' 

 

I know thats not a real code you wouldnt say integer+' its just an example

 

Posted (edited)
24 minutes ago, Chrisbc said:

Okay I replaced it like ya said and sure enough I can get it to scale up/down (cons 40 12) made it text height 12. would i need to add something like the other code had to make it say.   20'  per say 

for example

(cons 40 12 " ' " )?

To do that you would have to change (cons 1 (rtos len 2 2)) to -> (cons 1 (strcat (rtos len 2 0) "´"))

Edited by Isaac26a
Posted

I use the "BOMLengths" one pretty frequently for doing takeoffs/estimating for federal projects.  Super handy.

It works with a variety of different autocad objects - polylines most importantly.

 

You can either get your selection set first of what you want to sum, then run the lisp.

Or you run the lisp, use the polyline option (for polylines) then select each polyline u want to sum and it will return the value.

 

The other one I posted is an oldy but a goody that my boss had on file from circa 1996 😆  thought I would share.

LENGTH.LSP BOMLengths.lsp

Posted
4 minutes ago, Isaac26a said:

To do that you would have to change (cons 1 (rtos len 2 2)) to -> (cons 1 (strcat (rtos len 2 0) "´"))

Ahh i was so CLOSE haha i didnt know about the strcat addition otherwise i typed almost word for word what you typed! 

I honestly have only 1 day of exposure to lisps so i really appreciate the help!

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