Author Topic: Looking for a LISP routine (Inserting Text)....  (Read 2930 times)

0 Members and 1 Guest are viewing this topic.

StykFacE

  • Guest
Looking for a LISP routine (Inserting Text)....
« on: December 12, 2007, 09:37:53 AM »
Does anyone have a LISP routine that allows you to insert text into all selected TEXT entities within a drawing? Here's what I'm trying to accomplish:

I have hundreds of HVAC Air Diffusers that have CFM's labeled to each one. they all are a 3 digit number, ranging from 100 to 400. All I want to do is select all that text, and add an "A-" in the front of it. so then they all range from A-100 to A-400. The "A" is simply to label what type of air diffuser it is.

I suppose this is a simple routine that I could create on my own, but I'm on a time crunch here... Thanks all who can help!  :wink: :mrgreen:

daron

  • Guest
Re: Looking for a LISP routine (Inserting Text)....
« Reply #1 on: December 12, 2007, 09:44:23 AM »
Yes, actually. I do. I got this from a friend and I feel that I can post it because it is a routine that is posted on the internet somewhere on cadalyst, as you can see it made it to one of Hot Tip Harry's winning candidates.

Code: [Select]
;Tip1527A:  DDAPTXT.LSP   Append to Text  (c)1999, Scott A. Matthews
P.S. I tried looking for the cadalyst tip in the cadalyst archives. I can't find anything previous to 2004 and I haven't seen or heard from Scott since about 2000.
« Last Edit: December 12, 2007, 09:52:51 AM by Daron »

StykFacE

  • Guest
Re: Looking for a LISP routine (Inserting Text)....
« Reply #2 on: December 12, 2007, 09:50:17 AM »
Man that worked perfectly, and thanks for the quick reply. Saved the day :)

daron

  • Guest
Re: Looking for a LISP routine (Inserting Text)....
« Reply #3 on: December 12, 2007, 09:55:23 AM »
Non è un problema.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Looking for a LISP routine (Inserting Text)....
« Reply #4 on: December 12, 2007, 10:28:59 AM »
Daron's example is versatile but you need to select the text.
Here is one less versatile but automatic.
Code: [Select]
;;  Fully automatic, Add prefix to plin text with 3 numbers only
;;  Honers locked layers
(defun c:addA- (/ ss prefix layfilter lst)
  (setq prefix "A-")
  (setq layfilter nil) ; add layer name if needed
  (vla-EndUndoMark (vla-get-ActiveDocument (vlax-get-acad-object)))
  (vla-StartUndoMark (vla-get-activedocument (vlax-get-acad-object)))
  (and
    (if layfilter
      (setq ss (ssget "_X" (list '(0 . "TEXT") '(1 . "###")(cons 8 layfilter))))
      (setq ss (ssget "_X" '((0 . "TEXT") (1 . "###"))))
    )
    (setq lst (mapcar 'vlax-ename->vla-object (mapcar 'cadr (ssnamex ss))))
    (mapcar '(lambda (x)
               (vl-catch-all-apply 'vla-put-textstring
                 (list x (strcat prefix (vla-get-textstring x)))))
            lst)
  )
  (vla-EndUndoMark (vla-get-ActiveDocument (vlax-get-acad-object)))
  (princ)
)

PS I just had to write some code this morning. :-)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

StykFacE

  • Guest
Re: Looking for a LISP routine (Inserting Text)....
« Reply #5 on: December 12, 2007, 10:35:34 AM »
LOL @ CAB.... code is what you do best, man. I got another one off the CADTutor.net forums too, but they all work great. Definitely apart of the archive now. When I get AutoCAD files from other firms, I have to do this quite often and this time it was a big architectural plan with multiple floors, so this made it absolutely easy to do instead of one by one. :)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Looking for a LISP routine (Inserting Text)....
« Reply #6 on: December 12, 2007, 10:41:03 AM »
Glad it helped. 8-)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

daron

  • Guest
Re: Looking for a LISP routine (Inserting Text)....
« Reply #7 on: December 12, 2007, 12:21:15 PM »
Hey, it was quick he wanted. Honestly, I haven't used that lisp since Scott gave it to me.

DEVITG

  • Bull Frog
  • Posts: 481
about (setq lst (mapcar 'vlax-ename->vla-object (mapcar 'cadr (ssnamex ss))))
« Reply #8 on: December 14, 2007, 03:14:59 PM »
Hi Cab instead this

(setq lst (mapcar 'vlax-ename->vla-object (mapcar 'cadr (ssnamex ss))))

I use

(setq ss-obj (setq ca-sel (vla-get-activeselectionset adoc))
Where adoc comes from

(setq adoc
        (vla-get-activedocument
          (vlax-get-acad-object)
        )
      )

Then If I want to do any thing with all objects I use the
VLAX-FOR  obj  ss-obj

Now my question,

¿ what are the pros and con of each way to the smame task.?





Location @ Córdoba Argentina Using ACAD 2019  at Window 10

daron

  • Guest
Re: Looking for a LISP routine (Inserting Text)....
« Reply #9 on: December 14, 2007, 04:43:07 PM »
Speed. Plus Alan's is short, sweet and easy to read.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
¿ what are the pros and con of each way to the smame task.?
I find the list my way creates is MUCH easier to work with. You are not limited to vlax-for
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.