Skip to main content
13-Aquamarine
December 1, 2016
Solved

Script to build trail file based on list of files?

  • December 1, 2016
  • 2 replies
  • 9880 views

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.

 


This thread is inactive and closed by the PTC Community Management Team. If you would like to provide a reply and re-open this thread, please notify the moderator and reference the thread. You may also use "Start a topic" button to ask a new question. Please be sure to include what version of the PTC product you are using so another community member knowledgeable about your version may be able to assist.
Best answer by psobejko

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.

2 replies

12-Amethyst
December 1, 2016

Have you looked at Trailmaker 0.3 ?

davehaigh13-AquamarineAuthor
13-Aquamarine
December 1, 2016

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. 

1-Visitor
December 2, 2016

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.

24-Ruby III
December 2, 2016

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

24-Ruby III
December 5, 2016

Additional information: My combine_trails.bas can be modified easily to extract information from mass-parameter-update.idx.

MH