Jump to content

Recommended Posts

Posted

Why wont this label both variables? Is that the right terminology?

I.E. layername & layercolor

 

It will label one or the other, but not both?

 

(vl-load-com)
(defun C:Test (/ nwent layername layercolor)
 (setq nwent (entsel))
 (if nwent
   (progn
     (setq nwen(car nwent))
     (setq nwelist (entget nwen))
     (setq layername (cdr (assoc 8 nwelist)))
     (setq obj (vlax-ename->vla-object (car nwent)))
     (setq layerinfo (tblsearch "layer" layername))
     (setq layercolor (cdr (assoc 62 layerinfo)))
     (setq Textloc (getpoint "Pick Label Location: "))
     )
   (alert "Nothing Selected")
       )
 (command "text" textloc "" "" layername layercolor)
   (princ)
)

Posted

Can you show me how to use that? I'm fairly new to writing lisp

Posted

As you have no VL commands yet, you don't need the first line. I also took out one of your "" as well because in my version of autocad it only asks for a point and rotation, I wasn't sure what the rest was for. You can add it back if it's required.

 

(defun C:Test (/ nwent layername layercolor)
 (setq nwent (entsel))
 (if nwent
   (progn
     (setq nwen(car nwent))
     (setq nwelist (entget nwen))
     (setq layername (cdr (assoc 8 nwelist)))
     (setq obj (vlax-ename->vla-object (car nwent)))
     (setq layerinfo (tblsearch "layer" layername))
     (setq layercolor (cdr (assoc 62 layerinfo)))
     (setq Textloc (getpoint "Pick Label Location: "))
     )
   (alert "Nothing Selected")
       )
 (command "text" textloc "" (strcat layername " " (itoa layercolor)))
   (princ)
)

Posted

If you wanted them on different lines, then let me know. That's is slightly different code.

Posted

How would I put them on separate lines?

Posted

Also, can you explain to me what you did?

 

 

I dont understand

(itoa layercolor)))

Posted

Using the TEXT command via Autolsp can easily lead to unwanted results

 

Another consideration could be in Vanilla AutoLISP:

 

[b][color=BLACK]([/color][/b]defun c:lay-clr [b][color=FUCHSIA]([/color][/b]/ en ss ed ln lc pt[b][color=FUCHSIA])[/color][/b]

 [b][color=FUCHSIA]([/color][/b]while [b][color=NAVY]([/color][/b]not en[b][color=NAVY])[/color][/b]
        [b][color=NAVY]([/color][/b]and [b][color=MAROON]([/color][/b]setq ss [b][color=GREEN]([/color][/b]ssget[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
             [b][color=MAROON]([/color][/b]= [b][color=GREEN]([/color][/b]sslength ss[b][color=GREEN])[/color][/b] 1[b][color=MAROON])[/color][/b]
             [b][color=MAROON]([/color][/b]setq en [b][color=GREEN]([/color][/b]ssname ss 0[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]

 [b][color=FUCHSIA]([/color][/b]setq ed [b][color=NAVY]([/color][/b]entget en[b][color=NAVY])[/color][/b]
       ln [b][color=NAVY]([/color][/b]cdr [b][color=MAROON]([/color][/b]assoc 8 ed[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b]
       lc [b][color=NAVY]([/color][/b]cdr [b][color=MAROON]([/color][/b]assoc 62 [b][color=GREEN]([/color][/b]tblsearch [color=#2f4f4f]"LAYER"[/color] ln[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]

 [b][color=FUCHSIA]([/color][/b]initget 1[b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]setq pt [b][color=NAVY]([/color][/b]getpoint [color=#2f4f4f]"\nLabel Location:   "[/color][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]entmake [b][color=NAVY]([/color][/b]list [b][color=MAROON]([/color][/b]cons 0 [color=#2f4f4f]"TEXT"[/color][b][color=MAROON])[/color][/b]
                [b][color=MAROON]([/color][/b]cons 1 [b][color=GREEN]([/color][/b]strcat ln [color=#2f4f4f]" "[/color] [b][color=BLUE]([/color][/b]itoa lc[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
                [b][color=MAROON]([/color][/b]cons 6 [color=#2f4f4f]"CONTINUOUS"[/color][b][color=MAROON])[/color][/b]               [color=#8b4513]; [b][color=MAROON]([/color][/b]getvar [color=#2f4f4f]"CELTYPE"[/color][b][color=MAROON])[/color][/b][/color]
                [b][color=MAROON]([/color][/b]cons 7 [b][color=GREEN]([/color][/b]getvar [color=#2f4f4f]"TEXTSTYLE"[/color][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
                [b][color=MAROON]([/color][/b]cons 8 [b][color=GREEN]([/color][/b]getvar [color=#2f4f4f]"CLAYER"[/color][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
                [b][color=MAROON]([/color][/b]cons 10 pt[b][color=MAROON])[/color][/b]
                [b][color=MAROON]([/color][/b]cons 11 [b][color=GREEN]([/color][/b]list 0 0 0[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]              [color=#8b4513];  pt value if 72 or 73 not zero[/color]
                [b][color=MAROON]([/color][/b]cons 39 [b][color=GREEN]([/color][/b]getvar [color=#2f4f4f]"THICKNESS"[/color][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
                [b][color=MAROON]([/color][/b]cons 40 [b][color=GREEN]([/color][/b]getvar [color=#2f4f4f]"TEXTSIZE"[/color][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
                [b][color=MAROON]([/color][/b]cons 41 1.0[b][color=MAROON])[/color][/b]                       [color=#8b4513]; X axis Scale[/color]
                [b][color=MAROON]([/color][/b]cons 50 0.0[b][color=MAROON])[/color][/b]                       [color=#8b4513]; Text Angle[/color]
                [b][color=MAROON]([/color][/b]cons 51 0.0[b][color=MAROON])[/color][/b]                       [color=#8b4513]; Oblique Angle[/color]
                [b][color=MAROON]([/color][/b]cons 62 [b][color=GREEN]([/color][/b]cdr [b][color=BLUE]([/color][/b]assoc 62 [b][color=RED]([/color][/b]tblsearch [color=#2f4f4f]"LAYER"[/color] [b][color=PURPLE]([/color][/b]getvar [color=#2f4f4f]"CLAYER"[/color][b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
                [b][color=MAROON]([/color][/b]cons 71 0[b][color=MAROON])[/color][/b]                         [color=#8b4513]; Text Generation[/color]
                [b][color=MAROON]([/color][/b]cons 72 0[b][color=MAROON])[/color][/b]                         [color=#8b4513]; Justification Flag[/color]
                [b][color=MAROON]([/color][/b]cons 73 0[b][color=MAROON])[/color][/b]                         [color=#8b4513]; Justification Flag[/color]
                [b][color=MAROON]([/color][/b]cons 210 [b][color=GREEN]([/color][/b]trans '[b][color=BLUE]([/color][/b]0 0 1[b][color=BLUE])[/color][/b] 0 1[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]prin1[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b]

 

 

(entmake) gives total control / flexibility over the TEXT entity

Posted
Also, can you explain to me what you did?

 

 

I dont understand

(itoa layercolor)))

 

ITOA changes an integer into a string. David is also correct though, it is much better to do it his way. Only, I would use MTEXT if you want multiple lines.

Posted

(defun FormatColorName ( col / )

(cond

((or (= col 0)(= col "0")) "ByBlock")

((or (= col 1)(= col "1")) "1 (Red)")

((or (= col 2)(= col "2")) "2 (Yellow)")

((or (= col 3)(= col "3")) "3 (Green)")

((or (= col 4)(= col "4")) "4 (Cyan)")

((or (= col 5)(= col "5")) "5 (Blue)")

((or (= col 6)(= col "6")) "6 (Magenta)")

((or (= col 7)(= col "7")) "7 (Blk/Wht)")

((or (= col 8 )(= col "8")) "8 (D.Gray)")

((or (= col 9)(= col "9")) "9 (L.Gray)")

((or (= col 256)(= col "256")) "ByLayer")

(t col)))

 

 

if you use something like :

(setq layerinfo (tblsearch "layer" layername))

(setq layercolor (cdr (assoc 62 layerinfo)))

 

then layercolor will be a number. You can then convert the number (integer) to a string (ascii) , hence itoa. If use want something more readable you could use the above code and then it would look like:

 

 

(setq layercolor (FormatColorName (cdr (assoc 62 layerinfo))))

 

 

the function strcat can glue two or more text's together (strcat "hel" "lo") -> "hello"

 

 

rlx

Posted

(defun FormatColorName ( col / )
 (cond 
   ((or (= col 0)(= col "0")) "ByBlock")
   ((or (= col 1)(= col "1")) "1 (Red)")
   ((or (= col 2)(= col "2")) "2 (Yellow)")
   ((or (= col 3)(= col "3")) "3 (Green)")
   ((or (= col 4)(= col "4")) "4 (Cyan)")
   ((or (= col 5)(= col "5")) "5 (Blue)")
   ((or (= col 6)(= col "6")) "6 (Magenta)")
   ((or (= col 7)(= col "7")) "7 (Blk/Wht)")
   ((or (= col 8 )(= col "8")) "8 (D.Gray)")
   ((or (= col 9)(= col "9")) "9 (L.Gray)")
   ((or (= col 256)(= col "256")) "ByLayer")
   (t col)))

 

Alternative if you are interested.

 

(if (vl-some '(lambda (i r) (and (or (eq n i) (eq n (itoa i))) (setq v r)))
              '(0 1 2 3 4 5 6 7 8 9 256)
              '("ByBlock" "1 (Red)" "2 (Yellow)" "3 (Green)" "4 (Cyan)" "5 (Blue)"
                "6 (Magenta)" "7 (Blk/Wht)" "8 (D.Gray)" "9 (L.Gray)" "ByLayer"
                )
     )
 v
 (setq v n)
 )

Posted

I have written a lot of little and some big routines in autocad and some go way back you know... some I rewrite and some only if I need to (because at times I'm lazy haha) But thanx for the update and I will actually gonna use it

 

 

grtz rlx

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