Jump to content

Prefix/Suffix - add to numbers or text


coniferous

Recommended Posts

1 hour ago, G Prameela said:

I am looking for prefixing 'C' in front of a column layer which is shown only in integers. Example instead of C1, they have mentioned  1, due to some reason I wanted prefix C IN front of all these integers.

Althought this shouldn't be in this post, I think this can solve your needs.

;;;;;;;;;;;; Program to put a prefix to all the layers except by 0 and Defpoints.
;;;;;;;;;;;; By Isaac Alcántara 20210319
;;;;;;;;;;;;
(vl-load-com)
(defun c:preflay ( / lay lst lyn new prefix)
   (setvar "cmdecho" 0)
   (vl-cmdf "_.undo" "_begin")
   (setq prefix (getstring T "\nType the prefix to add to the layers: "))

   (while (setq lay (tblnext "LAYER" (null lay)))
      (or (wcmatch (setq lyn (cdr (assoc 2 lay))) "0,Defpoints")
          (or (tblsearch "LAYER" (setq new (strcat prefix lyn)))
              (entmod (subst (cons 2 new) (assoc 2 (setq lst (entget (tblobjname "LAYER" lyn)))) lst))
          )
      )
   )
   (vl-cmdf "_.undo" "_end")
   (princ)
)

 

Link to comment
Share on other sites

  • 9 months later...
  • Replies 24
  • Created
  • Last Reply

Top Posters In This Topic

  • Lee Mac

    5

  • eric_monceaux

    2

  • Least

    2

  • SanMiguel

    2

Does this also work with multileaders or does that require a completely different approach?

Edited by mickeforsberg
Link to comment
Share on other sites

20 hours ago, mickeforsberg said:

Does this also work with multileaders or does that require a completely different approach?

I guess this can help you with what you are looking for

(defun c:test ( )
   (pstext (getstring t "\nSpecify Prefix <none>: ") (getstring t "\nSpecify Suffix <none>: ") 1)
)
;; (pstext "Prefix Text" "Suffix Text" <mode>)
;;
;; <mode> = 0  -  single selection
;;        = 1  -  window selection
;;
;; Author: Lee Mac 2011  -  www.lee-mac.com
(defun pstext ( preftext sufftext mode / a e i s )
   (cond
       (   (= 0 mode)
           (while
               (progn (setvar 'ERRNO 0) (setq e (car (nentsel)))
                   (cond
                       (   (= 7 (getvar 'ERRNO))
                           (princ "\nMissed, try again.")
                       )
                       (   (eq 'ENAME (type e))
                           (if (wcmatch (cdr (assoc 0 (entget e))) "TEXT,MTEXT,ATTRIB,*LEADER,*DIMENSION")
                               (entmod
                                   (setq e (entget e)
                                         a (assoc 1 e)
                                         e (subst (cons 1 (strcat preftext (cdr a) sufftext)) a e)
                                   )
                               )
                               (princ "\nInvalid Object.")
                           )
                       )
                   )
               )
           )
       )
       (   (setq s (ssget "_:L" (list '(0 . "TEXT,MTEXT,ATTRIB,*LEADER,*DIMENSION"))))
           (repeat (setq i (sslength s))
               (entmod
                   (setq e (entget (ssname s (setq i (1- i))))
                         a (assoc 1 e)
                         e (subst (cons 1 (strcat preftext (cdr a) sufftext)) a e)
                   )
               )
           )
       )
   )
   (princ)
)

 

Link to comment
Share on other sites

"APTXT" from Cadalyst is a dialog based routine that allows you to add prefixes or suffixes to any text with many options.


DDAPTXT.LSP Append to Text (c)June 1999, Scott A. Matthews
added support for MTEXT & DIMENSION's March 2003, Tom Beauford

https://forums.augi.com/showthread.php?6364-Text-prefix-suffix&p=37577&viewfull=1#post37577

 

Link to comment
Share on other sites

  • 1 month later...
On 1/15/2022 at 6:37 AM, Isaac26a said:

I guess this can help you with what you are looking for

Thanks! Sorry I haven't gotten back, I haven't had the chance to try it until now.

I get an "error: bad argument type: stringp nil"

 

Any idea? (it works with text still, but not multileaders)

Edited by mickeforsberg
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...