Jump to content

Recommended Posts

Posted

Hi,

 

I have a problem with the strcat , and it is not goining values .

(setq num 1)
(while (setq pt (getpoint "\n Enter Coordinates points :"))
        (setq num (1+ num))
          (setq txt (strcat "W" num)) 
         (entmakex (list '(0 . "TEXT")
                            (cons 40 (getvar 'textsize))
                            (cons 1 txt)
                            (cons 10 pt)
                      )
            )
 )

 

Any help?

 

Thanks

  • Replies 36
  • Created
  • Last Reply

Top Posters In This Topic

  • Sweety

    11

  • BlackBox

    8

  • Lee Mac

    6

  • Lt Dan's legs

    5

Top Posters In This Topic

Posted

the variable num is an integer not a string. Use rtos to convert it to a string first

(strcat "W" (rtos num 2 0))

Posted

Wonderful . :)

 

Thank you soooooooooo much. :lol:

 

Sweety.

Posted

My two cents...

 

the variable num is an integer not a string. Use rtos to convert it to a string first

(strcat "W" [color=red](itoa[/color] num[color=red])[/color])

 

If the num variable were a real, then I would use rtos. 8)

Posted
My two cents...

If the num variable were a real, then I would use rtos. 8)

 

YES, Also a very good point. :)

 

Thank you for interests.

 

Sweety.

Posted

If you didn't know...

 

 
(cons 7 (getvar 'textstyle))
(cons 8 layer);;(setq layer "0") or whatever layer you wish

 

If you do then ignore this post :)

Posted (edited)

This may look a bit more involved, and it is, but I think you'll appreciate it in use.

 

This routine does everything you originally posted, *and* accounts for text entities you've already added, incrementing from the largest "W#" already in the current drawing.

 

This can be greatly improved (and done so easily) by adding layer (vla-put-layer ...), and style (vla-put-stylename ...) information, etc. as LT Dan's Legs has pointed out.

 

Also, if you were to use MText instead of DText, additional options would become available to the text object such as justification (vla-put-attachmentpoint ...), etc.

 

(defun c:WTEXT  (/ pt num numList)
 (vl-load-com)
 (cond
   (*activeDoc*)
   ((setq *activeDoc* (vla-get-activedocument (vlax-get-acad-object)))))
 (prompt "\n  >>  Specify Multiple Insertion Points, <Enter> to Exit: ")
 (while (setq pt (getpoint))
   (vla-addtext
 (cond
   (*modelSpace*)
   ((setq *modelSpace* (vla-get-modelspace *activeDoc*))))
 (strcat
   "W"
   (itoa
     (cond
       (num (setq num (1+ num)))
       ((setq ss (ssget "_x" '((0 . "TEXT") (1 . "W*"))))
         (progn
           (vlax-for x  (setq ss (vla-get-activeselectionset *activeDoc*))
             (setq numList 
               (cons (atoi (vl-string-left-trim "W" (vla-get-textstring x))) numList)))
           (vla-delete ss)
           (setq num (1+ (car (vl-sort numList '>))))))
       (T (setq num 1)))))
     (vlax-3d-point pt)
     (getvar 'textsize)))
 (princ))

 

[edit]

Corrected known "bad 3D point" error on exit.

[/edit]

 

Enjoy! :wink:

Edited by BlackBox
Corrected known error on exit.
Posted

Nice one Renderman, I like the way you use the COND statement :)

 

I hope you don't mind, I would be inclined to write it like this:

 

(defun c:wtext ( / spc doc p n ss )
 (vl-load-com)
 
 (setq spc
   (if
     (or
       (eq AcModelSpace
         (vla-get-ActiveSpace
           (setq doc
             (vla-get-ActiveDocument
               (vlax-get-acad-object)
             )
           )
         )
       )
       (eq :vlax-true (vla-get-MSpace doc))
     )
     (vla-get-ModelSpace doc)
     (vla-get-PaperSpace doc)
   )
 )
 (terpri)

 (while (setq p (getpoint "\rPick Point <Exit>: "))
   (vla-AddText spc
     (strcat "W"
       (itoa
         (setq n
           (cond
             (n (1+ n))
             (
               (setq ss (ssget "_X" '((0 . "TEXT") (1 . "W[0-9]*"))))
               (
                 (lambda ( i / e l s )
                   (while (setq e (ssname ss (setq i (1+ i))))
                     (if (eq "W" (vl-string-right-trim "0123456789" (setq s (cdr (assoc 1 (entget e))))))
                       (setq l (cons (atoi (substr s 2)) l))
                     )
                   )
                   (1+ (apply 'max l))
                 )
                 -1
               )
             )
             ( 1 )
           )
         )
       )
     )
     (vlax-3D-point (trans p 1 0))
     (getvar 'textsize)
   )
 )

 (princ)
)

I'm not saying yours is wrong :)

Posted
Nice one Renderman, I like the way you use the COND statement :)

 

I hope you don't mind...:

 

Thanks Lee!

 

I try not to turn down sounds advice, regardless of reputation.

 

 

Besides, there are several things I really like about your routine over my own:

  • Your use of nested setq's for the active document, and active space
  • Your use of (1 . "W[0-9]*")
  • Your use of vl-string-right-trim
  • Your application of 'max to the list (I cannot believe I forgot about that one!)
  • And, Finally, your translation from user coordinates to world.

Brilliant!

 

... Although (and I hope you don't mind)... why define the spc variable at all? 8)

 

(defun c:wtext  (/ [color=seagreen];| spc |;[/color] doc p n ss)
 (vl-load-com)
 (terpri)
 (while (setq p (getpoint "\rPick Point <Exit>: "))
   (vla-AddText
[color=red] (if[/color]
[color=red]   (or[/color]
[color=red]     (eq AcModelSpace[/color]
[color=red]       (vla-get-ActiveSpace[/color]
[color=red]         (setq doc[/color]
[color=red]           (vla-get-ActiveDocument[/color]
[color=red]             (vlax-get-acad-object)))))[/color]
[color=red]     (eq :vlax-true (vla-get-MSpace doc)))[/color]
[color=red]   (vla-get-ModelSpace doc)[/color]
[color=red]   (vla-get-PaperSpace doc))[/color]
 (strcat
   "W"
   (itoa
 (setq n
    (cond
      (n (1+ n))
    ((setq ss
      (ssget "_X" '((0 . "TEXT") (1 . "W[0-9]*"))))
  ((lambda (i / e l s)
      (while (setq e (ssname ss (setq i (1+ i))))
    (if
      (eq "W"
      (vl-string-right-trim
        "0123456789"
        (setq s (cdr (assoc 1 (entget e))))))
       (setq l (cons (atoi (substr s 2)) l))))
      (1+ (apply 'max l)))
     -1))
      (1)))))
   (vlax-3D-point (trans p 1 0))
   (getvar 'textsize)))
 (princ))

 

(Note - the formatting keeps getting distorted for some reason.)

 

Cheers! :beer:

Posted

Your formatting is distorted as you may be inserting Tabs in the VLIDE formatting. - Make sure you switch this off under the Visual LISP formatting options.

 

As for why I defined 'spc' : calling vlax-get-acad-object is slow and bad practice to be in a loop.

Posted

Holy sh**... all the op wanted to know was how to strcat a string and a number!

Posted
Your formatting is distorted as you may be inserting Tabs in the VLIDE formatting. - Make sure you switch this off under the Visual LISP formatting options.

 

I'll do that.

 

As for why I defined 'spc' : calling vlax-get-acad-object is slow and bad practice to be in a loop.

 

Yes, of course. I've developed a code management system, for both programming and production tools, that I use in concert with established global vars... one of which being the active document. Sometimes, I forget best practices when writing a *full* routine for someone else, as I typically do not duplicate code where unnecessary.

Posted
Holy sh**... all the op wanted to know was how to strcat a string and a number!

 

You're welcome...?! :unsure:

Posted
Holy sh**... all the op wanted to know was how to strcat a string and a number!

 

Dude, we're all learning here, not just the OP :wink:

Posted
Yes, of course. I've developed a code management system, for both programming and production tools, that I use in concert with established global vars... one of which being the active document. Sometimes, I forget best practices when writing a *full* routine for someone else, as I typically do not duplicate code where unnecessary.

 

Just making you aware. :)

Posted
Just making you aware. :)

 

I greatly appreciate that fact:

 

"One who is offended by truth, has no place among those who seek wisdom" - Ah... Me (aka RenderMan)
Posted

eg.

(setq num 0)
(while (setq pt (getpoint "\nSpecify point: "))
 (entmake (list '(0 . "TEXT")
                (cons 40 (getvar 'textsize))
                (cons 1 (strcat "W" (rtos (setq num (1+ num)) 2 0)))
                (cons 10 (trans pt 1 0))
          )
 )
)

Posted
eg.

(setq num 0)
(while (setq pt (getpoint "\nSpecify point: "))
(entmake (list '(0 . "TEXT")
(cons 40 (getvar 'textsize))
(cons 1 (strcat "W" (rtos (setq num (1+ num)) 2 0)))
(cons 10 (trans pt 1 0))
)
)
)

 

...And when you already have the first 12 ("W12") in the drawing?

Posted
...And when you already have the first 12 ("W12") in the drawing?
I was just following his entmake'ing. There's nothing wrong with what you and Lee posted. For the sake of posterity, I just wanted to give a simple entmake example.
Posted
I was just following his entmake'ing. There's nothing wrong with what you and Lee posted. For the sake of posterity, I just wanted to give a simple entmake example.

 

Understood; I didn't mean to dig at you, or your code for that matter... Besides, it's still a 'purty LISP, Alan (insert inside joke here). :P

 

[edit]

Hah! That's twice in two forums, in a single day!

This one just happens to be a bit more 'twangy.

[/edit]

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