Jump to content

Prefix/Suffix - add to numbers or text


coniferous
 Share

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 23
  • Created
  • Last Reply

Top Posters In This Topic

  • eric_monceaux

    2

  • Least

    2

  • Lee Mac

    5

  • Isaac26a

    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

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

 Share


×
×
  • Create New...