Jump to content

labeling using autolisp


autocrap

Recommended Posts

my colleague made this lsip routine to measure and label lines but it does not work, please help.

 

(defun C:LF()
 (setq en(car (entsel "\n Select Line: ")))
 (setq enlist(entget en)
       pt1 (cdr(assoc 10 enlist))
       pt2 (cdr(assoc 11 enlist))
       ang (angle pt1 pt2)
       dis (distance pt1 pt2)
 )
 (command "Dtext"
   (polar (polar pt1 ang (/ dis 2.0)) (+ ang (/ pi 2.0))(* (getvar"ltscale") 0.0625))
   (* (getvar"ltscale") 0.09375)
   (angtos ang)
   (strcat (rtos (/ dis 12.0) 2 2) "'   " (angtos ang)) 
 )
)  

Edited by autocrap
Link to comment
Share on other sites

  • 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:lf (/ p1 p2 di ang ins txt)
(setq p1 (getpoint "\nspecify first point: "))
(setq p2 (getpoint p1 "\nspecify second point: "))
(setq di (distance p1 p2))
(setq ang (angle p1 p2))
(setq ins (getpoint "\nspecify text location: "))
(setq txt (strcat (rtos di 2 2) "' " (angtos ang)))
(command "text" ins 2.5 0 txt)
(princ)
)

 

i just modified the one i use. You'll need to modify futher but i think this is easier to understand what's going on.

Link to comment
Share on other sites

Food for thought...

 

(defun c:Test (/ ss)
 (if (setq ss (ssget '((0 . "LINE"))))
   ((lambda (i / e l p1 p2 a)
      (while (setq e (ssname ss (setq i (1+ i))))
        (entmake
          (list
            '(0 . "TEXT")
            (cons 10
                  (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
                  (strcat (rtos (/ (distance p1 p2) 12.) 4 2)
                          "'   "
                          (angtos (setq a (angle p1 p2)))
                  )
            )
            (cons 50 a)
          )
        )
      )
    )
     -1
   )
 )
 (princ)
)

Link to comment
Share on other sites

Nice coding Alan, this is the only change I would make - hope you don't mind:

 

(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
                  (strcat (rtos (/ (distance p1 p2) 12.) 4 2)
                          "'   "
                          (angtos (setq a (angle p1 p2)))
                  )
            )
            (cons 50 (LM:MakeReadable a)) ; 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

I have been using "Lt Dan's Leg's" lisp routine, and it works great except for it writes in decimal units, and I need it to write in architectural units. I have already done Format > units and changed them to architectural, but it still writes in decimal. What should I do now?

Link to comment
Share on other sites

(defun c:lf (/ p1 p2 di ang ins txt)
(setq p1 (getpoint "\nSpecify first point: "))
(setq p2 (getpoint p1 "\nSpecify second point: "))
(setq di (distance p1 p2))
(setq ang (angle p1 p2))
(setq ins (getpoint "\nSpecify text location: "))
(setq txt (strcat (rtos di 4 2) "' " (angtos ang)))
;or (setq txt (strcat (rtos di 4 2) (angtos ang)))
 (entmake
   (list
    '(0 . "text")
     (cons 1 TXT)
     (cons 10 ins)
     (cons 11 ins)
     (cons 40 2.5)
     (cons 50 ang)
     (cons 72 1);replace 1 with 0 for text justification left
    )
   )
(princ)
)

 

 

I'm finally getting into entmake/mod! Thanks lee and alan

 

____

sorry for editing so much..

Link to comment
Share on other sites

thanks. I hate to ask you guys for more since you have done so much for me already, but is it possible to get your program to write as 10'-6" rather than 10 1/2'. I am a an autolisp newbie and not quite sure how to do it myself

Link to comment
Share on other sites

this is Lt Dan's Legs program that I modified. I am having trouble with the second half when i try to input the pipe size when i use the program.

(defun c:KB (/ p1 p2 di ins txt)
(setq p1 (getpoint "\nSpecify first point: "))
(setq p2 (getpoint p1 "\nSpecify second point: "))
(setq di (distance p1 p2))
(setq ang (angle p1 p2))
(setq ins (getpoint "\nSpecify text location: "))
(setq txt(strcat(rtos di)))
 (entmake
   (list
    '(0 . "text")
     (cons 1 TXT)
     (cons 10 ins)
     (cons 50 ang)
     (cons 40 2.5)
     (cons 73 3)
     (cons 11 ins)
    )
   )
 (princ)
 ;;; Only changes I have made to this point is it doesn't write the angle on the drawing, and the distance is written lower on the drawing.

 (setq ppt(getkword "\nSpecify pipe size" ))
 (setq ttx(strcat (rtos ppt)))
 (entmake
   (list
     '(0 . "text")
     (cons 1 ttx)
     (cons 10 ins)
     (cons 50 ang)
     (cons 40 2.5)
     (cons 73 1)
     (cons 11 ins)
     )
   )
 (princ)
 )

 

please help

Link to comment
Share on other sites

this is Lt Dan's Legs program that I modified. I am having trouble with the second half when i try to input the pipe size when i use the program.

(defun c:KB (/ p1 p2 di ins txt)
(setq p1 (getpoint "\nSpecify first point: "))
(setq p2 (getpoint p1 "\nSpecify second point: "))
(setq di (distance p1 p2))
(setq ang (angle p1 p2))
(setq ins (getpoint "\nSpecify text location: "))
(setq txt(rtos di))[color="red"];<--- strcat deleted[/color]
 (entmake
   (list
    '(0 . "text")
     (cons 1 TXT)
     [color="red"](cons 10 ins)[/color]<--- Texts would come above each others[color="red"][/color]
     (cons 50 ang)
     (cons 40 2.5)
     (cons 73 3)
     [color="red"](cons 11 ins)[/color]<--- Texts would come above each others[color="red"][/color]
    )
   )
 (princ)
 ;;; Only changes I have made to this point is it doesn't write the angle on the drawing, and the distance is written lower on the drawing.

 (setq ppt([color="red"]getdist[/color] "\nSpecify pipe size" ))[color="red"];<-- This one is modified according to Alanjt idea .[/color]
 (setq ttx (rtos ppt))[color="red"];<--- strcat deleted[/color]
 (entmake
   (list
     '(0 . "text")
     (cons 1 ttx)
    [color="red"] (cons 10 ins)[/color]<--- Texts would come above each others[color="red"][/color]
     (cons 50 ang)
     (cons 40 2.5)
     (cons 73 1)
     [color="red"](cons 11 ins)[/color];[color="red"]<--- Texts would come above each others[/color]
     )
   )
 (princ)
 )

 

please help

 

Enjoy it :)

 

Tharwat

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