cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Script to build trail file based on list of files?

SOLVED
Bedrock

Script to build trail file based on list of files?

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:

 

  1. Trail-1.txt
  2. Trail-2.txt with the word FAMILY-INSTANCE replace with the first line of file-list.txt
  3. Trail-2.txt with the word FAMILY-INSTANCE replace with the second line of file-list.txt
  4. Trail-2.txt with the word FAMILY-INSTANCE replace with the third line of file-list.txt
  5. Etc… until you get to the last line of file-list.txt 

  

Essentially a for each command with text replacement and append the new file with the modified trail-2.txt each time.

 

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Script to build trail file based on list of files?

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.

14 REPLIES 14

Re: Script to build trail file based on list of files?

Have you looked at Trailmaker 0.3 ?

Re: Script to build trail file based on list of files?

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:

  1. copy Trail-1.txt to a new file.
  2. Then for each line in file-list.txt:
    • Append the new file with Trail-2.txt while replacing the string FAMILY-INSTANCE with the current line of file-list.txt

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. 

Re: Script to build trail file based on list of files?

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.

Re: Script to build trail file based on list of files?

Hi,

you can test my gizmo.

  • unzip my 140525_2016-12-02.zip file, it contains following files

list.png

  • basic.exe ... Chipmunk Basic ... Chipmunk Basic Home Page
  • replace my File-list.txt, Trail-1.txt, Trail-2.txt files with yours
  • run combine_trails.bat

MH


Martin Hanák

Re: Script to build trail file based on list of files?

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.

  • User opens a generic and saves to disk in a new folder
    • That folder will contain two files, the generic.prt and the folder-name.idx file
    • I have two trail files. The one that starts the trail file session and the one that does the work.
  • I'd like to create a startup script the user can copy to the folder. That script will first create the trail file, and then start up Creo and run it.

I cobbled together some stuff from the internet today and have the concept working from the command line.

  • I grabbed the attached script from this site to do the find & replace step. DOS Batch - File Examples
  • From another post on some site I wrote the remove-last-line script that is attached. This is needed to clean up the instance list file generated from the .idx file.
  • The attached cmd-commands file are the commands that work from a command shell.

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.

  • setup-files.cmd creates the two files that contain the instances names and the name of the generic and copies the source start of the trail file to a new name.
  • start-instance-trail-file.cmd creates a new trail file that replaces the string GENERIC-PART with the name of the generic from the generic.txt file
  • complete-instance-trail-file.cmd uses the new trial file segment created by the script above to complete the script that was started by the setup-files script.

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.

Re: Script to build trail file based on list of files?

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.

  1. Finds the drawing name based on the print command Creo 3.0 sends to it via the print with command function in Creo.
  2. Unzips the zip file from Creo "Save as Zip" function.
  3. Finds all assembly files that contain the "Drawing Name" in their file name and adds the name to a list.
  4. Finds all part files that contain the "Drawing Name" in their file name and adds the name to a list.
  5. Parses the IDX file and finds all part files that contain the "Drawing Name" in their instance name and determines if the generic is a PRT or ASM file and adds the instance name to the appropriate list.
  6. Loops through the ASM and PRT lists to generate a single (sometimes very large) trail file that will:
    1. Generate eAssembly files of the assembly models (This is now commented out. We no longer use eAssemblies).
    2. Generate IGES and STEP files of the part models.
    3. Note: the batch file requires some "escape" characters to make things work when writing the trail file. Hence, what you see in the script is not what you get in the trail file.

Please let me know if this is of any help.

At least you should find some working (in Windows 7) "for" commands.

Kevin

Re: Script to build trail file based on list of files?

That's an inspired use of the print function.

Re: Script to build trail file based on list of files?

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

Re: Script to build trail file based on list of files?

Per the linked item, you might need a real programmer to help xkcd: Real Programmers