Jump to content

LISP or SCRIPT needed


CadTechJGC184

Recommended Posts

Hello all,

 

I have over 100 dwg's to rename the title (not xrefed) and change the file names. It will take me forever to do them one at a time! Plus I would shoot myself first. lol

 

Any suggestions?

 

Thanks in advance!!

 

PS. I would like one lisp or scr to do the file renaming and another that will do the titles. This way I can use them in the future.

Link to comment
Share on other sites

There are ways to do what you're asking, but could you be more specific? Where are the patterns in the work.. are you appending a certain bit of text to each file, are they all in a certain directory? I get the feeling there's a lot of easy ways to do what you want, and wouldn't be a problem at all.

 

I had posted this earlier.. really only changed it from "vl-file-copy" to "vl-file-rename":

(defun c:renameFiles( / )
 (vl-load-com)
 (setq filExt ".dwg")
 (setq filApp "_new")
 
 (setq getDir (vl-filename-directory (getfiled "Select file to specify directory.." "" "" 32)))
 (setq getFil (vl-directory-files getDir (strcat "*" filExt) 1))
 (foreach filVar getFil
   (vl-file-rename (strcat getDir "\\" filVar) (strcat getDir "\\" (substr filVar 1 (- (strlen filvar) 4)) filApp filExt))
   )
 (princ)
 )

 

Just specify, in your code, the file type and whatever string you want to be appended to the end of the file. If you need the string in a specific location, that can be done as well. When you run the program, it'll ask you to select a file in a directory, it'll run the function on all files in that directory.

 

Editing a title block is easy as well. What is the value / name of the attribute to change, and what would you like it changed to? Do you want to specify it for each file, or will it be consistent?

Link to comment
Share on other sites

freerefill,

 

The titles of the sheets I have to change are not an attribute. They are stand alone text. Is that going to be a problem?

 

As far as the file names, They are all in the same directory and it's as simple as adding an s at the end of PLAN (PLANS). I would like to be able to change more at a later date.

 

Thank you!

Link to comment
Share on other sites

VLA sure is fun to play around with, once you know what you're doing ^.^

 


(defun c:renameFiles_append( / filExt filApp getDir getFil)
 (vl-load-com)
 (setq filExt ".dwg")
 (setq filApp "appendTxt")
 
 (setq getDir (vl-filename-directory (getfiled "Select file to specify directory.." "" "" 32)))
 (setq getFil (vl-directory-files getDir (strcat "*" filExt) 1))
 (foreach filVar getFil
   (vl-file-rename (strcat getDir "\\" filVar) (strcat getDir "\\" (substr filVar 1 (- (strlen filvar) 4)) filApp filExt))
   )
 (princ)
 )

(defun c:renameFiles_remove( / filExt filRem getDir getFil)
 (vl-load-com)
 (setq filExt ".dwg")
 (setq filRem 3)
 
 (setq getDir (vl-filename-directory (getfiled "Select file to specify directory.." "" "" 32)))
 (setq getFil (vl-directory-files getDir (strcat "*" filExt) 1))
 (foreach filVar getFil
   (if (> (strlen filVar) filRem) (vl-file-rename (strcat getDir "\\" filVar) (strcat getDir "\\" (substr filVar 1 (- (strlen filvar) 9)) filExt)))
   )
 (princ)
 )

(defun c:renameFiles_replace( / filExt filSea filRep getDir getFil)
 (vl-load-com)
 (setq filExt ".dwg")
 (setq filSea "FIND")
 (setq filRep "REPLACE")
 
 (setq getDir (vl-filename-directory (getfiled "Select file to specify directory.." "" "" 32)))
 (setq getFil (vl-directory-files getDir (strcat "*" filExt) 1))
 (foreach filVar getFil
   (vl-file-rename (strcat getDir "\\" filVar) (strcat getDir "\\" (vl-string-subst filRep filSea filVar) filExt))
   )
 (princ)
 )

Here are a few commands, sorry about how lengthy the commands are, but you can change that. Each one pretty much does what it sounds like.

 

renameFiles_append appends each file with the text filApp

renameFiles_remove removes the selected number of characters (filRem) from the file name

renameFiles_replace replaces the given text (filSea) with the other given text (filRep) (note that this only replaces the first instance, not all instances)

 

And yes, replacing stand alone text is MUCH easier than attribute text, provided there's a place to start! Attribute texts have names, so it's generally easier to locate them once you figure out how to spider through the blocks, which is difficult. Stand alone texts are harder to locate, but alls you need is a simple entmod, and you're done. To that end, could you elaborate on the attributes of the text? Anything that would make it unique from the rest of the drawing?

Link to comment
Share on other sites

IF you google RENAME you'll find a freeware program that will allow you rename the drawings very quickly. Works for different file types too. Especially if you just want to change PLAN to PLANS. We use it regularly here.

Link to comment
Share on other sites

OK, Here's what I got. It's on the layer name (A-BORDER TEXT TITLE). their is one other text that is on the same layer, but it's the sheet number (C2.1). The title says: UTILITY AND PAVING PLAN. i need it to say: ELECTRICAL SITE PLAN. DoI need to provide you with more info?

Link to comment
Share on other sites

here's a print screen.... sorry it's a double screen shot. I don't know how to just do a print screen on one N:\JAMES CADE SHARED\title.bmpscreen. lol

Link to comment
Share on other sites

Here you go, give this a whirl.

 

(defun c:repTitleText( / txt sel)
 (vl-load-com)
 (ssget "X" (list (cons 0 "*TEXT") (cons 8 "A-BORDER TEXT TITLE") (cons 1 "UTILITY AND PAVING PLAN")))
 (vlax-for txt (setq sel (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object))))
   (vla-put-TextString txt "ELECTRICAL SITE PLAN")
   )
 (princ)
 )

VLA certainly does make modifying selection sets easier! My days of (entmod) and (subst) are over!! :D

Link to comment
Share on other sites

I would alter that in a few ways:

 

[b][color=RED]([/color][/b][b][color=BLUE]defun[/color][/b] c:repTitleText  [b][color=RED]([/color][/b][b][color=BLUE]/[/color][/b] txt sel[b][color=RED])[/color][/b]
 [b][color=RED]([/color][/b][b][color=BLUE]vl-load-com[/color][/b][b][color=RED])[/color][/b]
 [b][color=RED]([/color][/b][b][color=BLUE]if[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]ssget[/color][/b] [b][color=#ff00ff]"X"[/color][/b]
            [b][color=RED]([/color][/b][b][color=BLUE]list[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] [b][color=#009900]0[/color][/b] [b][color=#ff00ff]"TEXT,MTEXT"[/color][/b][b][color=RED])[/color][/b]
                  [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] [b][color=#009900]8[/color][/b] [b][color=#ff00ff]"A-BORDER TEXT TITLE"[/color][/b][b][color=RED])[/color][/b]
                  [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] [b][color=#009900]1[/color][/b] [b][color=#ff00ff]"UTILITY AND PAVING PLAN"[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
   [b][color=RED]([/color][/b][b][color=BLUE]progn[/color][/b]
     [b][color=RED]([/color][/b][b][color=BLUE]vlax-for[/color][/b] txt  [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] sel [b][color=RED]([/color][/b][b][color=BLUE]vla-get-activeselectionset[/color][/b]
                                [b][color=RED]([/color][/b][b][color=BLUE]vla-get-activedocument[/color][/b]
                                  [b][color=RED]([/color][/b][b][color=BLUE]vlax-get-acad-object[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
       [b][color=RED]([/color][/b][b][color=BLUE]vla-put-TextString[/color][/b] txt [b][color=#ff00ff]"ELECTRICAL SITE PLAN"[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
     [b][color=RED]([/color][/b][b][color=BLUE]vla-delete[/color][/b] sel[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
 [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]

 

 

  • There may not be a selection set, so I would use an IF statement when creating the new one.
  • Also, remember to delete the selection set when finished with it.

Link to comment
Share on other sites

Good point, checking to see if the selection set returned nil. I didn't think of that.

 

I did consider the RText thing, but honestly, I've never seen it or used it, and I can't understand why you wouldn't want to update that as well. Is there some particular property about RText that makes it so you should just leave it alone?

 

And finally, I don't understand deleting "sel" after vlax-for has done its job. Shouldn't declaring it a local variable when the function is defined make it return nil anyway, if someone tried to use the same variable? But more than that, it seems the only thing that's being done is deleting the selection set via VLA. Now in all my time, I've not deleted a single selection set, but I've never had a problem. Is deleting it just a routine cleanup, something that should be done but is ultimately optional?

 

Also, how do you get all those pretty colours? :3

Link to comment
Share on other sites

The RText thing i have got from Patrick on here, who advised someone else to do it - but I suppose the user may want the RText updated as well.

 

As for deleting the selection set, this is again from Patrick - I can see what you are saying about localising the variable, but in VL when you create a selection set in VL you add it to the selectionsets collection and so, if another program/user tries to create a selection set through VL in the same name, it can cause problems - so I suppose this practice of deleting the selection set after use has washed from there.

 

As for the colours - I have a LISP that I run my code through and it will add the colour tags to it :D

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