Lee Mac Posted April 23, 2009 Posted April 23, 2009 Hmmm, never used a .bat file for this kind of operation.... i'd be interested to see how it would be done... Quote
Freerefill Posted April 23, 2009 Posted April 23, 2009 Ok, so multiple lines is indeed possible @echo off set /p input1=Enter input set /p input2=Enter input set /p input3=Enter input echo -ATTEDIT N N A$C49561ED3 AAAA 01AREA 1 01AREA 1 %input1% > C:\SCRIPTY.SCR echo -ATTEDIT N N A$C49561ED3 AAAA 01AREA 1 01AREA 1 %input2% >> C:\SCRIPTY.SCR echo -ATTEDIT N N A$C49561ED3 AAAA 01AREA 1 01AREA 1 %input3% >> C:\SCRIPTY.SCR exit This should be everything you need to create a script file. Running it will be a challenge. Gotta ask, can you use the "start" command in LT? If you can, then you can place the .bat file in a directory (like C:\) and run it from the command line in AutoCAD. You enter your inputs, the prompt window closes after it writes the script file, then you can simply run the script file. Quote
Watson Posted April 23, 2009 Author Posted April 23, 2009 A little convoluted, but hear me out. .bat file. Before I found a way to do it entirely using a script, I initially had LISP which created a .bat file and a .scr file. The .bat file would open a new instance of AutoCAD, opening a certain .dwg with it, and automatically run the .scr that was created. Script files cannot accept user input. LT means no LISP, which means (getstring) is out. .bat files DO allow user input, and can write to a file. Perhaps a .bat file that creates a script using user input, then runs it in a selected .dwg? I'm working on it now, but I have very little experience with .bat files. *EDIT* Ok, some quick googling turned up some results. Open a new text file (notepad, nothing but) and copy and paste this code. Save it as "something.bat", make SURE the filetype is set to "all files." @echo off set /p input1=Enter input echo -ATTEDIT N N A$C49561ED3 AAAA 01AREA 1 01AREA 1 %input1% > C:\SCRIPTY.SCR After you save it, double-click on it. A command prompt should pop up asking you for input. Enter whatever you like, and end it by hitting "Enter." A new file will be created in your C:\ directory called "SCRIPTY.SCR". So you've just created a script file with prompts for user input, at least one line. You should be able to write multiple lines and return characters. Now, there is a way to open a .dwg and run a script file, but I think you want it to run in the drawing you have open. I'm not sure how to do that, but this is a start. I followed your instructions, but when I run the "Scripty.scr" I get: Command: -ATTEDITEdit attributes one at a time? [Yes/No] : N Performing global editing of attribute values. Edit only attributes visible on screen? [Yes/No] : N Drawing must be regenerated afterwards. Enter block name specification : A$C49561ED3 Enter attribute tag specification : AAAA Enter attribute value specification : 01AREA 1 01AREA 1 01AREA 1 0 attributes selected.*Invalid* Why would 01AREA 1 get entered 3 times when the code only has it in there twice? Quote
Watson Posted April 23, 2009 Author Posted April 23, 2009 The other issue I have is when I try it as a macros: ^C^C-ATTEDIT;N;N;"A$C49561ED3";AAAA;"01AREA 1";"01AREA 1";\ The "$" in the block name screws things up so everything after it is lost (even when I put the name in quotes like I did above). Quote
Freerefill Posted April 23, 2009 Posted April 23, 2009 Should have looked more carefully at your .scr. The whole "new line" thing and whatnot.. try this: @echo off set /p input1=Enter input set /p input2=Enter input set /p input3=Enter input echo -ATTEDIT > C:\SCRIPTY.SCR echo N >> C:\SCRIPTY.SCR echo N >> C:\SCRIPTY.SCR echo A$C49561ED3 >> C:\SCRIPTY.SCR echo AAAA >> C:\SCRIPTY.SCR echo 01AREA 1 >> C:\SCRIPTY.SCR echo 01AREA 1 >> C:\SCRIPTY.SCR echo %input1% >> C:\SCRIPTY.SCR echo -ATTEDIT >> C:\SCRIPTY.SCR echo N >> C:\SCRIPTY.SCR echo N >> C:\SCRIPTY.SCR echo A$C49561ED3 >> C:\SCRIPTY.SCR echo AAAA >> C:\SCRIPTY.SCR echo 01AREA 1 >> C:\SCRIPTY.SCR echo 01AREA 1 >> C:\SCRIPTY.SCR echo %input2% >> C:\SCRIPTY.SCR echo -ATTEDIT >> C:\SCRIPTY.SCR echo N >> C:\SCRIPTY.SCR echo N >> C:\SCRIPTY.SCR echo A$C49561ED3 >> C:\SCRIPTY.SCR echo AAAA >> C:\SCRIPTY.SCR echo 01AREA 1 >> C:\SCRIPTY.SCR echo 01AREA 1 >> C:\SCRIPTY.SCR echo %input3% >> C:\SCRIPTY.SCR exit I used "one", "two", and "three" as input to test it out, and I got this for my .scr: -ATTEDIT N N A$C49561ED3 AAAA 01AREA 1 01AREA 1 one -ATTEDIT N N A$C49561ED3 AAAA 01AREA 1 01AREA 1 two -ATTEDIT N N A$C49561ED3 AAAA 01AREA 1 01AREA 1 three Which looks a lot more like your script file. It should be easy enough to see what's going on. "Echo something >> C:\scripty.scr" basically means "Write 'something' to a new line (the >>) to the file 'scripty.scr' in C:\". The ">" means "write to" as opposed to ">>" which means "write to new line". Using ">" as the first one and ">>" as all subsequent means the file will be re-created each time the .bat file is run. Since the pattern is easy enough to see and understand, you shouldn't have much trouble editing the lines you need. You'll notice the only difference in what you're writing is the "%input1%" thing, which you should be able to recognize as the variables you set. Quote
Watson Posted April 23, 2009 Author Posted April 23, 2009 Oh man... I'm so close. Command: -ATTEDIT Edit attributes one at a time? [Yes/No] <Y>: Enter block name specification <*>: N Enter attribute tag specification <*>: Enter attribute value specification <*>: Select Attributes: N *Invalid selection* Expects a point or Window/Last/Crossing/BOX/Fence/WPolygon/CPolygon/Previous/AUto Select Attributes: *Cancel* Command: Specify opposite corner: Quote
Freerefill Posted April 23, 2009 Posted April 23, 2009 I'm working on it.. the problem was I didn't know about whitespace in batch files, so the spaces before the >> were getting written, which, of course, was messing up the command.. @echo off set /p input1=Enter input set /p input2=Enter input set /p input3=Enter input echo -ATTEDIT > C:\SCRIPTY.SCR echo N>> C:\SCRIPTY.SCR echo N>> C:\SCRIPTY.SCR echo A$C49561ED3>> C:\SCRIPTY.SCR echo AAAA>> C:\SCRIPTY.SCR echo 01AREA 1>> C:\SCRIPTY.SCR echo 01AREA 1>> C:\SCRIPTY.SCR echo %input1%>> C:\SCRIPTY.SCR echo -ATTEDIT>> C:\SCRIPTY.SCR echo N>> C:\SCRIPTY.SCR echo N>> C:\SCRIPTY.SCR echo A$C49561ED3>> C:\SCRIPTY.SCR echo AAAA>> C:\SCRIPTY.SCR echo 01AREA 1>> C:\SCRIPTY.SCR echo 01AREA 1>> C:\SCRIPTY.SCR echo %input2%>> C:\SCRIPTY.SCR echo -ATTEDIT>> C:\SCRIPTY.SCR echo N>> C:\SCRIPTY.SCR echo N>> C:\SCRIPTY.SCR echo A$C49561ED3>> C:\SCRIPTY.SCR echo AAAA>> C:\SCRIPTY.SCR echo 01AREA 1>> C:\SCRIPTY.SCR echo 01AREA 1>> C:\SCRIPTY.SCR echo %input3%>> C:\SCRIPTY.SCR exit I'm getting a new kind of error now, where the trailing '1' in your variables is being left off. Here's my script file when I run the .bat file: -ATTEDIT N N A$C49561ED3 AAAA 01AREA 01AREA one -ATTEDIT N N A$C49561ED3 AAAA 01AREA 01AREA two -ATTEDIT N N A$C49561ED3 AAAA 01AREA 01AREA three Also, it won't accept a single numerical input at the prompt.. if you enter, say, just '1' at the prompt, then the script file will have "ECHO IS OFF" instead of "1" for your replace variable. I'm sure there's an "if" statement out there that could cover this, but I don't know it. Quote
Freerefill Posted April 23, 2009 Posted April 23, 2009 Score! Yay for wild guesses! @echo off set /p input1=Enter input set /p input2=Enter input set /p input3=Enter input echo -ATTEDIT> C:\SCRIPTY.SCR echo N>> C:\SCRIPTY.SCR echo N>> C:\SCRIPTY.SCR echo A$C49561ED3>> C:\SCRIPTY.SCR echo AAAA>> C:\SCRIPTY.SCR echo 01AREA ^1>> C:\SCRIPTY.SCR echo 01AREA ^1>> C:\SCRIPTY.SCR echo %input1%>> C:\SCRIPTY.SCR echo -ATTEDIT>> C:\SCRIPTY.SCR echo N>> C:\SCRIPTY.SCR echo N>> C:\SCRIPTY.SCR echo A$C49561ED3>> C:\SCRIPTY.SCR echo AAAA>> C:\SCRIPTY.SCR echo 01AREA ^1>> C:\SCRIPTY.SCR echo 01AREA ^1>> C:\SCRIPTY.SCR echo %input2%>> C:\SCRIPTY.SCR echo -ATTEDIT>> C:\SCRIPTY.SCR echo N>> C:\SCRIPTY.SCR echo N>> C:\SCRIPTY.SCR echo A$C49561ED3>> C:\SCRIPTY.SCR echo AAAA>> C:\SCRIPTY.SCR echo 01AREA ^1>> C:\SCRIPTY.SCR echo 01AREA ^1>> C:\SCRIPTY.SCR echo %input3%>> C:\SCRIPTY.SCR exit Just needed a carrot before the '1' for whatever bloody reason! ^.^ Let me know how it works, maybe it can be improved further. Here's my output script file. It won't work on my machine because I don't have a block like yours. -ATTEDIT N N A$C49561ED3 AAAA 01AREA 1 01AREA 1 WON -ATTEDIT N N A$C49561ED3 AAAA 01AREA 1 01AREA 1 THE -ATTEDIT N N A$C49561ED3 AAAA 01AREA 1 01AREA 1 GAME Quote
Watson Posted April 23, 2009 Author Posted April 23, 2009 I keep getting an extra "enter" here: Edit attributes one at a time? [Yes/No] : So instead of entering "N" there, it defaults to "Y", which screws up the rest of the script. Quote
Lee Mac Posted April 23, 2009 Posted April 23, 2009 This would be the answer to your carat: http://www.robvanderwoude.com/redirection.php it seems that 1>> is a command in itself... Quote
Lee Mac Posted April 23, 2009 Posted April 23, 2009 I keep getting an extra "enter" here:So instead of entering "N" there, it defaults to "Y", which screws up the rest of the script. Sounds like a renegade space in the script. Quote
Watson Posted April 23, 2009 Author Posted April 23, 2009 Sounds like a renegade space in the script. YES!!! I found and killed the rogue. SUCESSSSSSSSS!!!!! Quote
Freerefill Posted April 23, 2009 Posted April 23, 2009 Sounds like a renegade space in the script. There was one, before the first '>' and after the first "-ATTEDIT" I corrected it in mine, is it fixed in yours? Quote
Lee Mac Posted April 23, 2009 Posted April 23, 2009 YES!!! I found and killed the rogue. SUCESSSSSSSSS!!!!! Thought so This batch file stuff is pretty sweet tbh... I may consider learning a bit Quote
Freerefill Posted April 23, 2009 Posted April 23, 2009 YES!!! I found and killed the rogue. SUCESSSSSSSSS!!!!! Ah, I'm so glad it worked. Give me some feedback, let me know if it's working properly, if you're having any trouble modifying it, that sort of thing. If there's one thing I've learned from a year of doing LISP (and the past two days on this forum, thank you very much Lee ^.^) is that there is always a better way to do something. Quote
Lee Mac Posted April 23, 2009 Posted April 23, 2009 Thats pretty much how I have learned LISP - I haven't really touched much on the tutorial sites, but rather just learnt from code that has been posted on here. I've only been writing LISP for about 9 months now, 8 of which have been spent on this forum - the learning curve has been pretty steep indeed to think that 9 months ago I hadn't even heard of LISP... Lee Quote
Watson Posted April 23, 2009 Author Posted April 23, 2009 It's working like a champ, the only issue I'm having now is that I have to highlight all the tabs in the drawing, then run the script... otherwise it just updates the F1 tab. I'm sure there is a "select all tabs" command I can build into the script... anybody know if off the top of their head? Quote
Freerefill Posted April 23, 2009 Posted April 23, 2009 I've only used the "ctab" system variable along with (nth var (layoutlist)) in order to switch tabs. I'm sure there's a VLA way to go about it, but I'm pretty sure the only thing that isn't exclusively LISP is "ctab". Try, however, typing (layoutlist) and see if that returns anything (while you're at it, try typing "ctab"). If (layoutlist) returns a list of layouts, there could be a way to write that to a file, and if you can do that, you can probably use a .bat file to mesh it into the .scr file. You'd have to do it that way, because I know of no way to manage it, other than a LISP loop. *tries something* Well.. there's a way to get the layout list using "LAYOUT", or sort of. It's a start. If you can write a .bat file to take that output and create a .scr file which cycles through the layout tabs.. then for each one, you can run the find and replace script. Or, you could just incorporate both into one.. but that's getting crazy. Quote
Watson Posted April 24, 2009 Author Posted April 24, 2009 I don't know what I did, but earlier today I swear could highlight all the tabs then run the script and it would update them all... I just tried it in a new drawing and it only updates the F-1 tab. I have to pick on each individual tab and run the script for the next (F-2) tab to get updated. Grrrr. "ctab" is working though, so I'll incorporate that into the script tomorrow. Thanks for all the help everyone. Quote
Recommended Posts
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.