Community Tip - When posting, your subject should be specific and summarize your question. Here are some additional tips on asking a great question. X
Wondering if anyone has a batch file that will work with a trail file segment and a list of files to build a long trail file.
I have the following files:
Trail-1.txt
Trail-2.txt
File-list.txt
In the new file I want:
Essentially a for each command with text replacement and append the new file with the modified trail-2.txt each time.
Solved! Go to Solution.
Ok, I see your problems and how the last two for /f statements didn't work.
Try this version:
for /F "tokens=2 skip=1 delims= " %%A IN (mass-parameter-update.idx) DO @echo %%A >> instance-list.txt
call remove-last-line.cmd instance-list.txt
for /F "tokens=3 skip=1 delims= " %%A IN (mass-parameter-update.idx) DO (set generic_name=%%A)
copy trail-1.txt big-trail-test.txt
echo Ready to start the substitution - replacing GENERIC-PART...
call batchsubstitute.bat GENERIC-PART %generic_name% trail-2.txt >> trail-3.txt
echo Ready to start the substitution - replacing FAMILY-INSTANCEs...
for /F "tokens=1" %%A IN (instance-list.txt) DO (call batchsubstitute.bat FAMILY-INSTANCE %%A trail-3.txt >> big-trail-test.txt)
echo Finished...
I also shortened up some of the code that extracts the name of the generic from the .idx file.
And removed the first of the problematic for /f statements - no need for it as you are calling batchsubstitute.bat just once.
But the key problem was that you were missing the CALL keyword - see line 8.
Not sure that's really what I was after. I need a function to replace a string in one of the trail files because I'm opening instances of a family table and doing something to each one then backing it up. I don't want to have to pick the instance manually when running the trail file. We could have hundreds or thousands of instances.
Attached is Edwin Muirhead's original Trail Maker.htm, which in reality is just a java script. You can view it in notepad++. I've use this in the past, but it's not working for what I need to do now. Not sure why, I think there's too much hard coded in it to work with the current rev of Creo.
Also attached are my sample files and the resulting file I made manually to test the function of the longer trail file. The file list came from idx file when I backed up the generic to the folder. I just opened it in notepad++ and use alt select to select a box with just the instance names and saved that as file-list.txt
Essentially I think this can all be done in perl, or even a cmd file. The simpler the better.
The core of the script would do the following:
Ideally the script would have a set command at the top where you could specify the string to search for and replace.
To me the more basic this script is, all text based the better, then it's uber flexible to be modified to any use I want.
I'm sure I could figure this out if I had the time, but right now I don't have the time, and I was hoping someone had done something like this in the past.
I used autohotkey for this task in the past, because of the clipboard functionality. But i'm sure it is easy to convert to work with files. In the top is the header, in the left text field the trail content and in the right text field you can put the list of files. File list can also be in clipboard. But you need autohotkey (opensource tool) to run or compile it to an executable.
I haven't had a chance to test the other two ideas from Andreas or Martin yet. I was playing with this today. I have commands that work, but they bomb out when I combine them into a full script.
Work flow I'm trying to achieve.
I cobbled together some stuff from the internet today and have the concept working from the command line.
Now I know I need to have call in front of some of these commands in a script and I have to double up the %'s in the for statements.
Eventually I should add a command to figure out what the name of the folder is.
My problem is it's failing on the last two for /f commands when combined into one.
I tried breaking them out into separate scripts and then calling them from a master script that continues to fail on the last two for commands.
The thing is, each script works on it's own. They are attached.
The problem, I'm sure, all has to do with the syntax in the for /f command, but I'm unsure how to fix it.
I'm sure this could all be cleaned up with something slicker. But I want to keep it flexible enough so it can be reused on other projects with different trial files. And I want to avoid complied programs. My preference is to stick with native windows scripting.
Hi David,
I didn't look through your scripts but I do want to help so I attached my batch file that:
This script is just part of our all-in-one release mapkey.
Please let me know if this is of any help.
At least you should find some working (in Windows 7) "for" commands.
Kevin
That's an inspired use of the print function.
I've looked at your script files, but frankly I'm confused about your statement about "My problem is it's failing on the last two for /f commands when combined into one", because I don't know where that is, or for that matter, what is failing. Is the file cmd-commands.txt in an editor and you are copying and pasting its lines into a separate command window?
I'd like to help, but I need to have these:
sample of the input files: trail-1.txt, mass-parameter-update.idx
the "desired" intermediate files: instance-list.txt, generic.txt, trail-2.txt, trail-3.txt
the "desired" output file: Modify-family-table.txt (or is it big-trail-test.txt?)
Per the linked item, you might need a real programmer to help xkcd: Real Programmers
Here, I'll add the script text to the posting.
this is the content of my first script after I broke them up into three separate scripts.
for /F "tokens=2 skip=1 delims= " %%A IN (mass-parameter-update.idx) DO @echo %%A >> instance-list.txt
call remove-last-line.cmd instance-list.txt
for /F "tokens=3 skip=1 delims= " %%A IN (mass-parameter-update.idx) DO @echo %%A >> generic.txt
set /p texte=< generic.txt
echo %texte% > generic.txt
copy trail-1.txt Modify-family-table.txt
This is the content of the second script the first for command that will not run when combined with the script above.
for /F "tokens=1" %%A IN (generic.txt) DO (batchsubstitute.bat GENERIC-PART %%A trail-2.txt >> trail-3.txt)
This is the content of the last script the second for command that will not run when combined into one script.
for /F "tokens=1" %%A IN (instance-list.txt) DO (batchsubstitute.bat FAMILY-INSTANCE %%A trail-3.txt >> Modify-family-table.txt)
Attached are the source files.
If I run each of the scripts above in order it does what it's supposed to do. If I combine the last two commands into the first script it will not run those.
These last two scripts use the batchsubstitue.bat also attached.
I have to run to an all day workshop, so I won't get to respond to any comments today.
Ok, I see your problems and how the last two for /f statements didn't work.
Try this version:
for /F "tokens=2 skip=1 delims= " %%A IN (mass-parameter-update.idx) DO @echo %%A >> instance-list.txt
call remove-last-line.cmd instance-list.txt
for /F "tokens=3 skip=1 delims= " %%A IN (mass-parameter-update.idx) DO (set generic_name=%%A)
copy trail-1.txt big-trail-test.txt
echo Ready to start the substitution - replacing GENERIC-PART...
call batchsubstitute.bat GENERIC-PART %generic_name% trail-2.txt >> trail-3.txt
echo Ready to start the substitution - replacing FAMILY-INSTANCEs...
for /F "tokens=1" %%A IN (instance-list.txt) DO (call batchsubstitute.bat FAMILY-INSTANCE %%A trail-3.txt >> big-trail-test.txt)
echo Finished...
I also shortened up some of the code that extracts the name of the generic from the .idx file.
And removed the first of the problematic for /f statements - no need for it as you are calling batchsubstitute.bat just once.
But the key problem was that you were missing the CALL keyword - see line 8.
Paul, thanks for the solution! So obviously without the call statement embedded into the for command it's not going to pass the variable to the other program.
Last week was crazy busy, so I didn't get around to testing this until today.
I've added a few things to make this a bit more automated.
The intended workflow is the user will run a script that will setup a folder inside the normal Creo startup folder. (attached as Setup-Mass-Param-Update-Folder.cmd)
That script prompts the user for a folder name.
When the user enters a name it then copies all the required files from a folder on the server to the new folder.
The user then opens a generic and does a save backup and saves it to the new folder. That folder now has two additional files. The generic part and an .idx file with the folders name.
After this step the user will exit Creo and double click on the Updated-Mass-Parameters.cmd script in the folder.
I modified the script to figure out the name of the folder it resides in and then use that elsewhere in the script. And finally in the last line I have the script startup Creo and run the trail file.
for %%* in (.) do set FOLDER=%%~nx*
for /F "tokens=2 skip=1 delims= " %%A IN (%FOLDER%.idx) DO @echo %%A >> instance-list.txt
call remove-last-line.cmd instance-list.txt
echo Ready to start the substitution - replacing GENERIC-PART...
for /F "tokens=3 skip=1 delims= " %%A IN (%FOLDER%.idx) DO (set GENERIC_NAME=%%A)
copy trail-1.txt Modify-family-table.txt
call batchsubstitute.bat GENERIC-PART %GENERIC_NAME% trail-2.txt >> trail-3.txt
echo Ready to start the substitution - replacing FAMILY-INSTANCEs...
for /F "tokens=1" %%A IN (instance-list.txt) DO (call batchsubstitute.bat FAMILY-INSTANCE %%A trail-3.txt >> Modify-family-table.txt)
echo Ready to start Creo and run the trail file
call "C:\ptc\Creo 2.0\Parametric\bin\parametric0.bat" Modify-family-table.txt
After Creo is done the user can replace the generic in the library with the latest one in the folder.
Obviously this process can now be modified for many other tasks.
Hi,
just one tip for you .
Example:
You can merge setup-files.cmd and remove-last-line.cmd files into one cmd file. See attached file containing following code.
@echo off
for /F "tokens=2 skip=1 delims= " %%A IN (mass-parameter-update.idx) DO @echo %%A >> instance-list.txt
call:remove-last-line instance-list.txt
for /F "tokens=3 skip=1 delims= " %%A IN (mass-parameter-update.idx) DO @echo %%A >> generic.txt
set /p texte=< generic.txt
echo %texte% > generic.txt
copy trail-1.txt Modify-family-table.txt
goto:eof
::--------------------------------------------------------
::-- remove-last-line
::--------------------------------------------------------
:remove-last-line
setlocal enabledelayedexpansion
set count=
for /f %%x in ('type %1 ^| find /c /v ""') do set /a lines=%%x-1
copy /y nul %tmp%\tmp.zzz > nul
for /f "tokens=*" %%x in ('type %1 ^| find /v ""') do (
set /a count=count+1
if !count! leq %lines% echo %%x>>%tmp%\tmp.zzz
)
move /y %tmp%\tmp.zzz %1 > nul
goto:eof
MH
Hi,
you can test my gizmo.
MH
Additional information: My combine_trails.bas can be modified easily to extract information from mass-parameter-update.idx.
MH