Jump to content

Polyline lengths


Chrisbc

Recommended Posts

  • 1 year later...

pdim

 

 

 

 

 

(if you look through the files you will find somethng like (defun c:pdim ( / ) at the start of each routine. If there is a 'c:' whatever follows (here pdim) is the command to use).  

Edited by Steven P
Link to comment
Share on other sites

I have not done it for a while but should get back in the habit of when loading code add a little message at the end about how to run. I find "alert" is good but keep it outside the defun so it only displays once.

 

(defun c:mycode ( / a s d f )

..........
)
(alert "to run just type MYCODE")

or
(defun c:mycode ( / a s d f )

..........
)
(c:mycode)

 

  • Like 1
Link to comment
Share on other sites

  • 1 year later...

@Isaac26a is there any way "LP2T" to select multiple objects at once and put the length in middle of square/circle ?

 

 

 

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

Link to comment
Share on other sites

Using VL makes getting the length and area much easier, you do though need to look at what type of object you have picked.

 

(defun c:wow ( / ss x len pt)
(vl-cmdf "_.style" "times" "times new roman" "0" "1" "" "" "")
(setq ss (ssget '((0 . "Lwpolyline,Circle"))))
(if (= ss nil)
(alert "No plines or circles selected ")
(repeat (setq x (sslength ss))
(setq obj (vlax-ename->vla-object (ssname ss (setq x (- x 1)))))
(if (= (vlax-get obj 'Objectname) "AcDbPolyline")
  (progn
   (setq len (rtos (vlax-get obj 'Length) 2 3))
   (setq Pt (osnap (vlax-curve-getStartPoint obj) "gcen"))
  )
  (progn
   (setq len (rtos (vlax-get obj 'Circumference) 2 2))
   (setq pt (vlax-get obj 'center))
 )
)
(vl-cmdf "_.text" "_s" "times" pt "1" "0" (strcat "L=" len "m."))
)
)
(princ)
)
(c:wow)

 

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