Jump to content

Lisp for labelling Y value?


Torro

Recommended Posts

Apologies if this has been answered previously but I feel like I'm going around in circles! I'm completely new to lisp, and need a routine that allows a combination of the ones discussed here:

 

http://www.cadtutor.net/forum/archive/index.php/t-33183.html

 

http://www.cadtutor.net/forum/showthread.php?41117-Label-Point-Z-Value

 

Basically I want to drop in a little triangle, and label with just the Y value.

 

Any help much appreciated! :?

Link to comment
Share on other sites

Here is some kind of that


(defun C:ELY(/ osm p)
(setq osm (getvar 'osmode))
(setvar 'osmode 
0)
;; Choose one whatever you want:
;; 1. 
(command "_polygon" 
3   (setq p (getpoint"\nPoint: ")) "_I" 10;|<- Radius|;  (list 
(car p)(+ (cadr p)10.;|<- Radius| 0.))
(command  "_-mtext" p "_J" 
"_MC" "_H" (getvar 'dimtxt);|<- Text Height|; "_W" 0 (rtos (cadr p)(getvar 
'lunits)(getvar 'dimdec)) "" )
;; 2. 
(command "_polygon" 
3   (setq p (getpoint"\nPoint: ")) "_I" 10  (list (car p)(+ (cadr 
p)10.) 0.) "_rotate" "_L" "" p 180 "")
(command  "_-mtext"  p "_J" 
"_MC" "_H" (getvar 'dimtxt) "_W" 0 (rtos (cadr p)(getvar 'lunits)(getvar 
'dimdec)) "" )


(setvar 'osmode osm)
 (princ)
 )

Link to comment
Share on other sites

Sorry I've been out of the office haven't here since I posted! Thanks so much guys for your quick responses.

 

The second isn't quite what I was after, I was looking to drop the lower point of an inverted triangle onto a line and have that be the Y value - I didn't explain myself very well! But thanks so much Lee that one seems to do the job perfectly. I did look on your site but missed that one. Presumably I can change the number of decimal places, text and symbol size myself? As I said I'm totally new to lisp so I've no real idea where to start in terms of doing that. Any pointers gratefully received....!

Link to comment
Share on other sites

But thanks so much Lee that one seems to do the job perfectly. I did look on your site but missed that one.

 

You're welcome :)

 

Presumably I can change the number of decimal places, text and symbol size myself?

 

Certainly:

 

Text size is currently set to use the value of the DIMTXT system variable:

ts [color=red](getvar 'DIMTXT)[/color]

But this can be any positive non-zero numerical value.

 

The text is offset from the horizontal line by the text size value:

(polar (polar p2 pi (* ts 0.5 (strlen tx))) (/ pi 2.) [color=red]ts[/color])

The length of the line is equal to the number of characters in the text multiplied by the text height:

(polar p2 pi [color=red](* ts (strlen tx[/color][color=red]))[/color])

The triangle is equilateral with side length equal to the text size:

(polar p1 (/ pi 2.) (* [color=red]ts[/color] (/ (sqrt 3.0) 2.0)))
...
(cons 41 [color=red]ts[/color])

Finally, the width of the horizontal line is equal to the text size multiplied by 0.05:

(cons 40 [color=red](* ts 0.05[/color][color=red])[/color])
(cons 41 [color=red](* ts 0.05[/color][color=red])[/color])

Link to comment
Share on other sites

Brilliant, thanks! I just changed the dimtxt value and the rest sorted itself out. The only thing I can't seem to change is the number of decimal places, which I need to reduce to two. I managed to get it to round off the measurement itself to two decimal places, but it left another two zeros after it...

Link to comment
Share on other sites

  • 4 weeks later...

Hi again!

 

Thanks again for the LISP it works great. Bit of an oversight on my part though - I need the arrows to be able to point up as well as down so I can label, for example, a ceiling height or beam soffit. Is this an easy fix?

Link to comment
Share on other sites

I have indeed, yes. That's what I've been doing to get around it and it works fine. It just so happens though that I haven't needed to use the LISP on any large projects yet, but it's very likely I will need to soon so just that little bit of added time / extra processes would become a bit of a pain!

Link to comment
Share on other sites

You will have seen in the first reference in your initial post, that I submitted a very simple lisp, which draws an open triangle and writes the text as separate entities, so that the position of each could be altered simply.

 

However, your request might be acted on by those who wrote the more sophisticated routines.

Link to comment
Share on other sites

Yes thanks for that one. Although it does do the job it wasn't quite what we were looking for in terms of presentation which, ultimately, isn't down to me I'm afraid!

Link to comment
Share on other sites

Try these updated versions:

[color=GREEN];; Elevation Marker  -  Lee Mac  -  www.lee-mac.com[/color]

([color=BLUE]defun[/color] c:em ( [color=BLUE]/[/color] *error* ang hgt len ocs pt1 pt2 pt3 pt4 str )

   ([color=BLUE]defun[/color] *error* ( msg )
       ([color=BLUE]if[/color] ([color=BLUE]not[/color] ([color=BLUE]wcmatch[/color] ([color=BLUE]strcase[/color] msg [color=BLUE]t[/color]) [color=MAROON]"*break,*cancel*,*exit*"[/color]))
           ([color=BLUE]princ[/color] ([color=BLUE]strcat[/color] [color=MAROON]"\nError: "[/color] msg))
       )
       ([color=BLUE]princ[/color])
   )

   ([color=BLUE]setq[/color] hgt ([color=BLUE]getvar[/color] 'textsize)
         ocs ([color=BLUE]trans[/color] '(0.0 0.0 1.0) 1 0 [color=BLUE]t[/color])
         ang ([color=BLUE]angle[/color] '(0.0 0.0) ([color=BLUE]trans[/color] ([color=BLUE]getvar[/color] 'ucsxdir) 0 ocs [color=BLUE]t[/color]))
   )
   ([color=BLUE]terpri[/color])
   ([color=BLUE]while[/color] ([color=BLUE]setq[/color] pt1 ([color=BLUE]getpoint[/color] [color=MAROON]"\rSpecify point <exit>: "[/color]))
       ([color=BLUE]setq[/color] str ([color=BLUE]rtos[/color] ([color=BLUE]cadr[/color] pt1))
             len ([color=BLUE]strlen[/color] str)
             pt2 ([color=BLUE]list[/color] ([color=BLUE]car[/color]  pt1) ([color=BLUE]+[/color] ([color=BLUE]cadr[/color] pt1) ([color=BLUE]*[/color] hgt 0.5 ([color=BLUE]sqrt[/color] 3))))
             pt3 ([color=BLUE]list[/color] ([color=BLUE]-[/color] ([color=BLUE]car[/color] pt1) ([color=BLUE]*[/color] hgt len)) ([color=BLUE]cadr[/color] pt2))
             pt4 ([color=BLUE]list[/color] ([color=BLUE]-[/color] ([color=BLUE]car[/color] pt2) ([color=BLUE]*[/color] hgt 0.5 len)) ([color=BLUE]+[/color] ([color=BLUE]cadr[/color] pt2) hgt))
       )
       ([color=BLUE]foreach[/color] sym '(pt1 pt2 pt3 pt4)
           ([color=BLUE]set[/color] sym ([color=BLUE]trans[/color] ([color=BLUE]eval[/color] sym) 1 ocs))
       )
       ([color=BLUE]entmake[/color]
           ([color=BLUE]list[/color]
              '(000 . [color=MAROON]"LWPOLYLINE"[/color])
              '(100 . [color=MAROON]"AcDbEntity"[/color])
              '(100 . [color=MAROON]"AcDbPolyline"[/color])
              '(090 . 3)
              '(070 . 0)
               ([color=BLUE]cons[/color] 038 ([color=BLUE]caddr[/color] pt1))
               ([color=BLUE]cons[/color] 010 pt1)
              '(040 . 0.0)
               ([color=BLUE]cons[/color] 041 hgt)
               ([color=BLUE]cons[/color] 010 pt2)
               ([color=BLUE]cons[/color] 040 ([color=BLUE]*[/color] hgt 0.05))
               ([color=BLUE]cons[/color] 041 ([color=BLUE]*[/color] hgt 0.05))
               ([color=BLUE]cons[/color] 010 pt3)
               ([color=BLUE]cons[/color] 210 ocs)
           )
       )
       ([color=BLUE]entmake[/color]
           ([color=BLUE]list[/color]
              '(000 . [color=MAROON]"TEXT"[/color])
               ([color=BLUE]cons[/color] 007 ([color=BLUE]getvar[/color] 'textstyle))
               ([color=BLUE]cons[/color] 001 str)
               ([color=BLUE]cons[/color] 050 ang)
               ([color=BLUE]cons[/color] 040 hgt)
               ([color=BLUE]cons[/color] 010 pt4)
               ([color=BLUE]cons[/color] 011 pt4)
              '(072 . 1)
              '(073 . 2)
               ([color=BLUE]cons[/color] 210 ocs)
           )
       )
   )
   ([color=BLUE]princ[/color])
)

[color=GREEN];; Elevation Marker (Reversed Version)  -  Lee Mac  -  www.lee-mac.com[/color]

([color=BLUE]defun[/color] c:em2 ( [color=BLUE]/[/color] *error* ang hgt len ocs pt1 pt2 pt3 pt4 str )

   ([color=BLUE]defun[/color] *error* ( msg )
       ([color=BLUE]if[/color] ([color=BLUE]not[/color] ([color=BLUE]wcmatch[/color] ([color=BLUE]strcase[/color] msg [color=BLUE]t[/color]) [color=MAROON]"*break,*cancel*,*exit*"[/color]))
           ([color=BLUE]princ[/color] ([color=BLUE]strcat[/color] [color=MAROON]"\nError: "[/color] msg))
       )
       ([color=BLUE]princ[/color])
   )

   ([color=BLUE]setq[/color] hgt ([color=BLUE]getvar[/color] 'textsize)
         ocs ([color=BLUE]trans[/color] '(0.0 0.0 1.0) 1 0 [color=BLUE]t[/color])
         ang ([color=BLUE]angle[/color] '(0.0 0.0) ([color=BLUE]trans[/color] ([color=BLUE]getvar[/color] 'ucsxdir) 0 ocs [color=BLUE]t[/color]))
   )
   ([color=BLUE]terpri[/color])
   ([color=BLUE]while[/color] ([color=BLUE]setq[/color] pt1 ([color=BLUE]getpoint[/color] [color=MAROON]"\rSpecify point <exit>: "[/color]))
       ([color=BLUE]setq[/color] str ([color=BLUE]rtos[/color] ([color=BLUE]cadr[/color] pt1))
             len ([color=BLUE]strlen[/color] str)
             pt2 ([color=BLUE]list[/color] ([color=BLUE]car[/color]  pt1) ([color=BLUE]-[/color] ([color=BLUE]cadr[/color] pt1) ([color=BLUE]*[/color] hgt 0.5 ([color=BLUE]sqrt[/color] 3))))
             pt3 ([color=BLUE]list[/color] ([color=BLUE]-[/color] ([color=BLUE]car[/color] pt1) ([color=BLUE]*[/color] hgt len)) ([color=BLUE]cadr[/color] pt2))
             pt4 ([color=BLUE]list[/color] ([color=BLUE]-[/color] ([color=BLUE]car[/color] pt2) ([color=BLUE]*[/color] hgt 0.5 len)) ([color=BLUE]-[/color] ([color=BLUE]cadr[/color] pt2) hgt))
       )
       ([color=BLUE]foreach[/color] sym '(pt1 pt2 pt3 pt4)
           ([color=BLUE]set[/color] sym ([color=BLUE]trans[/color] ([color=BLUE]eval[/color] sym) 1 ocs))
       )
       ([color=BLUE]entmake[/color]
           ([color=BLUE]list[/color]
              '(000 . [color=MAROON]"LWPOLYLINE"[/color])
              '(100 . [color=MAROON]"AcDbEntity"[/color])
              '(100 . [color=MAROON]"AcDbPolyline"[/color])
              '(090 . 3)
              '(070 . 0)
               ([color=BLUE]cons[/color] 038 ([color=BLUE]caddr[/color] pt1))
               ([color=BLUE]cons[/color] 010 pt1)
              '(040 . 0.0)
               ([color=BLUE]cons[/color] 041 hgt)
               ([color=BLUE]cons[/color] 010 pt2)
               ([color=BLUE]cons[/color] 040 ([color=BLUE]*[/color] hgt 0.05))
               ([color=BLUE]cons[/color] 041 ([color=BLUE]*[/color] hgt 0.05))
               ([color=BLUE]cons[/color] 010 pt3)
               ([color=BLUE]cons[/color] 210 ocs)
           )
       )
       ([color=BLUE]entmake[/color]
           ([color=BLUE]list[/color]
              '(000 . [color=MAROON]"TEXT"[/color])
               ([color=BLUE]cons[/color] 007 ([color=BLUE]getvar[/color] 'textstyle))
               ([color=BLUE]cons[/color] 001 str)
               ([color=BLUE]cons[/color] 050 ang)
               ([color=BLUE]cons[/color] 040 hgt)
               ([color=BLUE]cons[/color] 010 pt4)
               ([color=BLUE]cons[/color] 011 pt4)
              '(072 . 1)
              '(073 . 2)
               ([color=BLUE]cons[/color] 210 ocs)
           )
       )
   )
   ([color=BLUE]princ[/color])
)

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