Jump to content

Bach Adding suffix


Jord_91

Recommended Posts

HI,

I would like to add suffix to the text in multiple files at once.

ex: the name is "ml153029ar" and I need to add "OVA" at the end but every name in the different drawing are different sort i can't just make a find and replace.

Help me please! :)

Link to comment
Share on other sites

I am working on a program that can read a users brain but at this time it only works for my mind. So either you donate your brain to me or you could provide a little bit more detailed info on your question. To get you started , are the text's always on the same layer , or is it an attribute in a block , do they allways start with ml , are they of a fixed length or of a certain format that can be use in combination with wcmatch?

 

gr. Rlx

Link to comment
Share on other sites

Rlx,

Good idea for the mind reader;) In fact, all the text are on the Layers: ''2D'' and Start with ML and it's followed by a suite of letters and different numbers that are ALWAYS DIFFERENT and has NOT the same lenght. I looked to the wcmatch and it's not possible to math i would like to do. It doesn't matter if it's a simple routine that I can modify and run in Script pro.. I don't know...

Lee mac has something to add suffix but the problem with it is that you have to run it one file at the time because you need to select the text.

;; (pstext "Prefix Text" "Suffix Text" )

;;

;; = 0 - single selection

;; = 1 - window selection

;;

;; Author: Lee Mac 2011 - http://www.lee-mac.com

 

(defun pstext ( preftext sufftext mode / a e i s )

(cond

( (= 1 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")

(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"))))

(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)

)

(defun c:OVATEXT ( )

(pstext "" "OVA" 1)

)

 

Thanks!

Ps. sorry for my bad english i'm French...

Link to comment
Share on other sites

I will try not to hold it against you , that you're French haha , just kidding...

 

But getting the right text should be easy then , you would just have to test if it starts with ml (or ML)

 

 (if (wcmatch (strcase txt) "ML*") .... 

Link to comment
Share on other sites

So i put this in my actual lisp just after pstext ??... Ok Ok I like the idea of Lisp but i'm a noob at it. I have made a lot of Macro command but lisp are clearly more complicated!! :P

Link to comment
Share on other sites

try this :

 

;; (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 txt)
 (cond    ((= 0 mode)
    (while    (progn (setvar 'errno 0)
              (setq e (car (nentsel)))
              (cond ((= 7 (getvar 'errno)) (princ "\nMissed, try again."))
                ((eq 'ename (type e)) (ctxt e))))))
                 
   ((setq s (ssget "_:L" (list '(0 . "TEXT,MTEXT"))))
    (repeat (setq i (sslength s))(ctxt (ssname s (setq i (1- i))))))
 )      
 (princ)
)


(defun ctxt (e)
 (if (and (member (cdr (assoc 0 (setq e (entget e)))) '("TEXT""MTEXT""ATTRIB"))
      (wcmatch (strcase (setq txt (cdr (assoc 1 e)))) "ML*"))
   (entmod (setq e (subst (cons 1 (strcat preftext txt sufftext)) (assoc 1 e) e))))
)

(defun c:ovatext () (pstext "" "OVA" 1))

Edited by rlx
Link to comment
Share on other sites

It don't work, The selection cycle is in the PSTEXT so if we find the text before and run a function to find another text somwhere else it won't work... I think

Link to comment
Share on other sites

It don't work, The selection cycle is in the PSTEXT so if we find the text before and run a function to find another text somwhere else it won't work... I think

 

the functions as it is written by Lee in it's current form lets you pick one text at the time only. You want it to operate on a complete drawing or folder?

Link to comment
Share on other sites

In fact, it was an example of a function and I tought that it might have worked but I can be totaly wrong! In the best case i would be able to run it on an entire folders sort that every files would be modify adding the suffix. But if it’s not possible, I would like to change on a complete drawing and I will run it in a program to run it on every files.

Thx, I hope it’s clear enough

Link to comment
Share on other sites

I think some times people put to much emphasis on must work over multiple drawings will be slow, a script will open a dwg run a lisp and close again pretty fast, repeating as required. If you have hundreds then yes look ODBX.

 

a script like

open dwg1 (load "Rlx-LEE-suffix) close Y
open dwg2 (load "Rlx-LEE-suffix) close Y
open dwg3 (load "Rlx-LEE-suffix) close Y

 

If the dwg's are in known directories and like me know a few old DOS tricks you can make the script in a couple of minutes.

DIR *.DWG >myscipt.scr /b

Edited by BIGAL
Link to comment
Share on other sites

I think some times people put to much emphasis on must work over multiple drawings will be slow, a script will open a dwg run a lisp and close again pretty fast, repeating as required. If you have hundreds then yes look ODBX.

 

a script like

open dwg1 (load "Rlx-LEE-suffix) close Y
open dwg2 (load "Rlx-LEE-suffix) close Y
open dwg3 (load "Rlx-LEE-suffix) close Y

If the dwg's are in known directories and like me know a few old DOS tricks you can make the script in a couple of minutes.

DIR *.DWG >myscipt.scr /b

 

 

It's not like I'm force feeding anyone to use my code but I get your point bigal haha. I always look for the option that it the easiest for me and in this case I already had a routine in my editor to change the textstyle so this was just a case of me being lazy :D

 

In my 'defence' (not implying I have to) I usualy work with hundreds of drawings and sometimes hundreds of thousands so for me speed is key. But I have many ways , scripts , odbx , coreconsole and of cource my 'tape deck buttons' so I press the button for next drawing , press button with srcipt and I'm done , next drawing ... all with one hand supporting my big giant head and a mouse in the other :P

 

attachment.php?attachmentid=63328&cid=1&stc=1

Tord_bored.png

Edited by rlx
Link to comment
Share on other sites

You clearly Rock man. It works as a charm. I have create a new post about running a .scr ofr multiple files if you have the time to have a look at it it would be appreciated. I made my very best but some time it doesn't work. I'm on my way to learn how to create lisp but to me it's clearly mode complicated then a macro or a Script. Anyway, Thanks and have a good day.

Link to comment
Share on other sites

You clearly Rock man. It works as a charm. I have create a new post about running a .scr ofr multiple files if you have the time to have a look at it it would be appreciated. I made my very best but some time it doesn't work. I'm on my way to learn how to create lisp but to me it's clearly mode complicated then a macro or a Script. Anyway, Thanks and have a good day.

 

gosh you make me blush :P (or were you talkin' about bigal )

 

will try to find some time (or a tardis) for your other request.

 

gr. Rlx

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