Jump to content

Recommended Posts

Posted

Just a suggestion when posting code use the Code icon it will put it in a box for you, welcome aboard.

 

image.thumb.png.d4977fc27b91426b7ecd021057e015d6.png

  • 1 year later...
Posted (edited)

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
Posted

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
  • 1 year later...
Posted (edited)

@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

 

Edited by SLW210
Added Code Tags!
Posted

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)

 

  • 6 months later...
Posted
On 6/3/2021 at 1:09 PM, Tharwat said:

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



 

 

How would you modify this to leave the polyline and not delete it?

TiA

Posted

Remove this line: (entdel new)

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