Jump to content

labeling using autolisp


autocrap

Recommended Posts

  • Replies 28
  • Created
  • Last Reply

Top Posters In This Topic

  • autocrap

    10

  • Lee Mac

    6

  • alanjt

    4

  • gplow

    4

Top Posters In This Topic

(defun c:Test (/ ss)
 ;; AJ Thompson, angle modified by LeeMac
 (if (setq ss (ssget '((0 . "LINE"))))
   ((lambda (i / e l p p1 p2 a)
      (while (setq e (ssname ss (setq i (1+ i))))
        (entmake
          (list
            '(0 . "TEXT")
            (cons 10
              (setq p ; LM
                  (mapcar (function (lambda (a b) (/ (+ a b) 2.)))
                          (setq p1 (cdr (assoc 10 (setq l (entget e)))))
                          (setq p2 (cdr (assoc 11 l)))
                  )
              )
            )
            (cons 40 (getvar 'textsize))
            (cons 1  (rtos (- (caddr p2) (caddr p1)))) ; LM
            (cons 50 (LM:MakeReadable (angle p1 p2))) ; LM
            (cons 72 1) ; LM
            (cons 73 0) ; LM
            (cons 11 p) ; LM
          )
        )
      )
    )
     -1
   )
 )
 (princ)
)

(defun LM:MakeReadable ( a )
 ;; © Lee Mac 2010
 (cond
   (
     (and (> a (/ pi 2)) (<= a pi))

     (- a pi)
   )
   (
     (and (> a pi) (<= a (/ (* 3 pi) 2)))

     (+ a pi)
   )
   (
     a
   )
 )
)

Link to comment
Share on other sites

(defun c:Test (/ ss)
 ;; AJ Thompson, angle modified by LeeMac
 (if (setq ss (ssget '((0 . "LINE"))))
   ((lambda (i / e l p p1 p2 a)
      (while (setq e (ssname ss (setq i (1+ i))))
        (entmake
          (list
            '(0 . "TEXT")
            (cons 10
              (setq p ; LM
                  (mapcar (function (lambda (a b) (/ (+ a b) 2.)))
                          (setq p1 (cdr (assoc 10 (setq l (entget e)))))
                          (setq p2 (cdr (assoc 11 l)))
                  )
              )
            )
            (cons 40 (getvar 'textsize))
            (cons 1  (rtos (- (caddr p2) (caddr p1)))) ; LM
            (cons 50 (LM:MakeReadable (angle p1 p2))) ; LM
            (cons 72 1) ; LM
            (cons 73 0) ; LM
            (cons 11 p) ; LM
          )
        )
      )
    )
     -1
   )
 )
 (princ)
)

(defun LM:MakeReadable ( a )
 ;; © Lee Mac 2010
 (cond
   (
     (and (> a (/ pi 2)) (<= a pi))

     (- a pi)
   )
   (
     (and (> a pi) (<= a (/ (* 3 pi) 2)))

     (+ a pi)
   )
   (
     a
   )
 )
)

 

Thank for your quick response. It is working fine except that I would like to know where I can change the text size (which is now at 0.2) in your lisp.

 

Thank again

GP

Link to comment
Share on other sites

LM,

I can change the size/height now. Thanks. Where can I change the decimal places from 3 to 0. and also to the nearest integer.

Thanks again.

GP

 

Currently uses your LUPREC, but for manual precision control:

 

(rtos (- (caddr p2) (caddr p1)))

 

Becomes:

 

(rtos (- (caddr p2) (caddr p1)) 2 [color=red][b]0[/b][/color])

 

Red part is the number of dp.

Link to comment
Share on other sites

  • 8 months later...

This is the code I am now using

(defun c:PT (/ p1 p2 di ins txt oldsnap)
 (while
 (setq oldsnap(getvar "osmode"))
(setvar "osmode" 165)
(setq p1 (getpoint "\nSpecify first point: "))
(setq p2 (getpoint p1 "\nSpecify second point: "))
(setq di (distance p1 p2))
(setq ang (angle p1 p2))
 (setvar "osmode" 0)
(setq ins (getpoint "\nSpecify text location: "))
(setq txt(rtos di))
 (setvar "osmode" oldsnap)
 (entmake
   (list
    '(0 . "text")
     (cons 1 txt)
     (cons 10 ins)
     (cons 50 ang)
     (cons 40 8.0)
     (cons 72 1)
     (cons 73 3)
     (cons 11 ins)
    )
   )
 (princ)
 (setq ppt(getstring "\nSpecify pipe size" ))
 (entmake
   (list
     '(0 . "text")
     (cons 1 ppt)
     (cons 10 ins)
     (cons 50 ang)
     (cons 40 8.0)
     (cons 72 1)
     (cons 73 1)
     (cons 11 ins)
     )
   )
 (princ)
 )
 )

however I would like the text to be further apart (vertically), but I am not sure how to this myself, can anyone ehlp me with this?

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