Jump to content

Recommended Posts

Posted

Hi guys, I've been trying to solve this problem for a couple of hours. I'd give it a few more hours/days to try and work it out myself but it seems so simple and I can't see anything wrong.

 

I need to change the setting IMAGEFRAME to "2" for a lot of drawings. I could open them manually but I have two days until my work term is over and I have other things to do too :P

 

So I've read articles mentioning batch files many times and thought this might be the answer. I have taught myself (although I guess there's not really much to teach) scripts for AutoCAD.

 

Here is the script file:

 

 
IMAGEFRAME
2
qsave
QUIT

 

And here is the batch file I found in a google book (not mine):

 

 
FOR %%f in ("C:\batchtest\*.dwg") DO START /WAIT 
"C:\Program Files\Autodesk\ACADM 2008\acad.exe"
"%%f" /b "C:\IMAGEFRAME.scr"

 

Obviously, these are my own files paths, however from what I understand and according to the book, the batch file should find all the files ending with ".dwg" in the batchtest directory, open one instance of autocad, open the first drawing, and then run the script (since the switch "/b" is there). The script will close the file and AutoCAD. The "/WAIT" should make the batch file wait to open the next file until the first file is closed, right? So once that first instance of AutoCAD is closed, a new one should pop up and open the second file, run the script and repeat until all .dwg fiels are dealt with.

 

What it's doing is opening all three drawings at once (in three separate instances of AutoCAD), then ignoring (I think?) the switch and not running the script. At one point, I did have the batch file waiting to try and open the second and third files (I'm testing with three drawings) until the previously opened file was closed, however AutoCAD wasn't recognizing the drawings. I didn't sae that code, sorry!

 

I wrote this batch file to only open one of the drawings. It works no problem.

 

 
"C:\Program Files\Autodesk\ACADM 2008\acad.exe"
"C:\batchtest\baysh-test.dwg" /b 
"C:\IMAGEFRAME.scr"

 

I looked up for loop syntax and I can't see anything wrong with the first batch file. What am I doing wrong?

 

I'm using AutoCAD 2008 Mechanical on Windows XP. All of the code here is on one line, except for the script file.

 

Thanks for your help!

Posted

I got it to work, IT had an idea. He said to use two batch files instead of one.

 

His example opens up all of the .txt files in a directory.

 

Batch file #1:

 

 
for %%f in ("C:\*.txt") do start /wait batch2.bat "%%f"

 

Batch file #2:

 

 
notepad %1
exit

 

So he told me to adapt this to AutoCAD by popping in the proper paths and the switch I wanted,etc...

 

Batch File #1:

 

 
for %%f in ("C:\batchtest\*.dwg") do start /wait batch2.bat
"%%f"

 

Batch File #2:

 

 
"C:\Program Files\Autodesk\ACADM 2008\acad.exe" %1 /b
"C:\IMAGEFRAME.scr"
exit

 

Again, all code on one line except for an "enter" before the "EXIT" in the second batch file.

 

And this works! Sorry for the thread I guess. I will now continue lurking, hehe. If anyone knows what was wrong with the batch file in the first post, please let me know. Thanks guys!

Posted

Glad you got it to work...however next time you want to automate a mundane task like imageframe, you might want to check out Autodesk's ScriptPro which really automates the process of running scripts on multiple drawings.

http://usa.autodesk.com/adsk/servlet/item?siteID=123112&id=4091678&linkID=9240618

  • 4 weeks later...
Posted

finally I've got this bat file story worked after finding this post.

 

aflaeomor, the answer to you problem was "c" missing in the bat file like this:

 

FOR %%f in ("C:\batchtest\*.dwg") DO START /WAIT "c"
"C:\Program Files\Autodesk\ACADM 2008\acad.exe"
"%%f" /b "C:\IMAGEFRAME.scr"

 

Don't ask me for what that's for. I've found that is some other post somewhere. Hope someone can tell me.

Also what is the deference between %%f and %%v?

 

But now I have a different problem. Why does it not find the drawings if the file name contains spaces? Like for example Drawing 1.dwg it does not find but Drawing1.dwg it does. Can I add something to the bat file maybe?

 

Thanx

 

EDIT:

 

Ok I've manage to figure out my problems here with a bit of more searching.

 

First I've noticed that you don't need to add the "c". You can place " for spaces like c:\"Program Files"\...\ (correct me if I'm wrong)

Secondly, my problem for the file names with spaces not opening, is to put "" around the last %%f . (something I've missed)

 

So here is my resulting code and FINALLY working:

FOR %%f in (c:\script\*.dwg) do start /wait C:\"Program Files"\"AutoCAD 2010"\acad.exe "%%f" /nologo /b C:\script\test.scr

I just would like to have the drawings open in the same AutoCAD session instead and not for AutoCAD to open and close the whole time for each dwg. It takes much longer.

 

Welcome for any input.

thanx

Posted

If you're looking to automate processes on multiple drawings, check out my Batch Engine (see link in sig). I admit it's a little cryptic at the moment (it's version 1), but I'm working on a better explanation. Until then, I can answer any questions you might have though.

 

I went the .bat file route initially myself, but a .bat file opens a new instance of AutoCAD for each drawing. You can actually do the whole thing using just one script.

Posted

thanx Freerefill, I will have a look at your Batch Engine.

 

I also don't like the .bat file story that much. It's easier to drag and drop a .scr into AutoCAD and it works fast. My problem is that I need to process over 100 dwgs+ and to quickly create a script file its easier to create a single line script per dwg. to repeat them. So it means space will count for enter then, but that don't always work. For editing attributes for example and where the replacement text are input the script don't see spaces for enter. So the only option for that is to do away with a script file where the commands are per line, so it means let say 10 lines per dwg script and to do that quickly is do run a macro in word to create my script for me. But thats a lot of copy and past from one file to another.

 

See my scr here:

_open "D:\Dwgs\drawing  1.dwg" -attedit n n drg_detail_bl dwg_rev 1 1 2 qsave close
_open "D:\Dwgs\drawing  2.dwg" -attedit n n drg_detail_bl dwg_rev 1 1 2 qsave close

 

Now this scr stops at input 1 and see it as 1 1 2 instead for entering in between. But placing the 1 1 2 in individual lines works perfect.

Posted

If you're looking to do a find and replace, I can help you set up the batch engine to do that too :) It'll work for text, mtext and attributes.. I can't seem to get it to work for tables.

Posted

Thanx would be glad if you can help me out here. Not sure how to use the Batch Engine. Maybe a few example's would help?

As you can see from my code above: I am replacing the attribute tag "dwg_rev" from value 1 to 2 witch is located in block "drg_detail_bl"

 

thanx

Posted

My tremendous apologies. I was a fool and rushed it out, then I found so many more bugs with it, not the least of which was the fact that I didn't have a good explanation prepared on how to use it! I've since rectified that mistake, and although it remains a work in progress, I'll update it post haste.

 

*EDIT* - The updated version has been uploaded in my original post, which you can get to via the link in my signature. I'm not sure of the rules regarding bumping topics even if new information is posted, and I did not want to necro post or clutter up the forum with a secondary topic.

Posted

thanx for all the documentation and examples. Im trying to get some sort of an idea how the batch engine works but still not there yet.

 

I am getting the drawings to open and close but no changes are done and errors appear. So my expression(s) sure not in the correct format. It looks like if i can get it to open a custom .scr file that it will do the job but struggle with that too.

 

Here is a few failing attempts: :?

(finalblitz '(("CMD" (vl-cmdf "-attedit" n n drg_detail_bl dwg_rev 1 1 2 QSAVE))) '("THIS") nil nil 1 ))

(finalblitz '(("CMD" (vl-cmdf "SCR"))) '("THIS") nil nil 1 ))

(finalblitz '(("CMD" (vl-cmdf "SCR" "c:\script test\script.scr"))) '("THIS") nil nil 1 ))

 

PS: I like your GrPlayground, Freerefill. Pretty cool!! 8)

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