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

Community Tip - New to the community? Learn how to post a question and get help from PTC and industry experts! X

Batch file that runs same trail file on multiple parts

ptc-6458056
1-Newbie

Batch file that runs same trail file on multiple parts

Hi!

I registered here to ask this question. I've been working on it off and on for a week and can't quite figure out where I'm going wrong.

I'm going to have about 100 parts coming through that I need to populate parameters, recreate layers, and rename datums for (and a couple other tasks). So I recorded a trail file that will do the tasks. I tested it independently and it works no problem.

I then wrote a .BAT file that will go through the directory I give it (where the parts are located), it will export the list of parts to a text file.

Using this list, I set up a FOR loop to replace the part number in the trail file at each iteration.

The problem I'm running into is that when the batch file directs Creo to open a file, I get this message:

Cannot find C:\Users\%username%\Desktop\AutoCreo\Backup\PA.txa C:\Users\%username%\Desktop\AutoCreo\Backup\Test_Folder\%%a

Is Creo trying to open that as a single file, instead of opening %%a (Part from list) and running PA.txa (Trail File)?

I tried inserting pro_wait as well, as it was a separate command I ran across that may or may not help

Here is my code:

CODE:

@ECHO OFF

ECHO Brought to you by: ME

:: Prompts user for the directory

set /p pathName=Enter the File Path of the folder:

set /p username=Enter your username:

:: 1. Change to the location set above

:: 2. List all files in that directory and store in a text file desktop

cd %pathName%

dir /s /b *.* > c:\users\%username%\desktop\list.txt

:: 3. Opens Creo then runs 'for loop' to run script against each file in list.txt

:: This sets and populate parameters

:: 4. Add -g:no_graphics to run in non windows mode

for /f "delims=" %%a in (c:\users\%username%\desktop\list.txt) do ("c:\Program Files\PTC\Creo 2.0\Parametric\bin\parametric.bat" pro_wait "C:\Users\%username%\Desktop\PA.txa %%a")

Pause

In summary, the .bat file works up to a point. It stops when Creo is open/running and the OPEN FILE window is there asking for which part to open. The .bat file inputs (what looks to me to be the correct filepath) and then gives me that error.

I read something about a protk.dat file? Is this necesarry to get the .bat to communicate directly with Pro/E ?

I would really appreciate any help I can get. I've tried asking a few other places as well and haven't had much luck.

Thank you for your 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.
9 REPLIES 9

Try sending the output of the 'for' substitution to a file and see if it looks right.

I've been looking at the manual pages for 'for,' but haven't gotten far enough to see if your syntax is what you need.

Off topic: Awk, grep, VBA, C, AutoIT, FORTRAN, Postscript; these I get, but not windows command scripting. I think the goofy things like use % if you type it, but %% if it's in a batch file - for the same result - is what makes it hurt to read.

The problem, it seems to me, is that running Creo only takes input from the txa file. I think Pro/E & Creo do not read any information from the CMD.

I think you have to embed the name of the file in the .txa file.

I agree with David, you have to put specific part name into a trail file, before you ask Creo to replay the trail file. Also I suggest to use lowercase name for the trail file.

Martin Hanak


Martin Hanák

After reading your replies, I was thinking I would do this:

Set up a loop to have the batch file generate a new trail file for each iteration, that way the part number is embedded in the trail file as suggested. Then its just a matter of deleting/overwriting the previous trail file each time until it finishes the list.

I appreciate the help so far, and if anyone else has a suggestion, I'm all ears.

AutoIt. Create mapkeys to handle most of the changes and then use AutoIt to open files, run the mapkeys, and save and close. Mapkeys because AutoIt is asynchronous and it is tricky to monitor exactly what Creo is doing from moment to moment, but is capable of monitoring significant changes easily.

Reason to like it - capable of much greater flexibility because it is a programming language, rather than a pre-recording. No need to pick through the trail files.

Reason not to - aside from IT policies, only works with the graphics operating version. Trail files will work with or without graphics. Because of its interaction with graphics, it can be a mouse hog, though it can also play very nicely if correctly written.

Okay, so I went ahead and wrote the .bat file to actually create the trail files itself with the variables in it. Each iteration it should overwrite the previous one with the new file names.

Now I just need to figure out the appropriate syntax to get it to read it correctly and do what I want using a loop.

Hopefully this works out.

I appreciate the comments and help so far guys.

As for AutoIT, that's not an option for me. I also want this to run in the background in no_graphics mode, so that's downside number 2.

I've got to work with what I already have at hand.

It's too bad about AutoIt. I wonder if the bean counters and IT managers would like it if they were forced to give up the numbers 7 and 9 from all their calculations. Also, no times key. Much better to handicap the workers by limiting their tool choices.

Based on the days since you first posted your question, it would have taken about 2 days to create the mapkeys and the AutoIt software, one day for debugging, and would have had (guessing) 5 days*16 off hours + 2 days*24 hours = almost 130 hours to run.

For anyone else stuck using DOS commands, I did find http://ss64.com/nt/ as a good reference for CMD, the program that runs commands and batch files.

The following notation works well ...

call "C:\PTC\Creo2_M070\Creo 2.0\Parametric\bin\parametric.bat" "D:\tmp\creo\my_trail.txt" -g:no_graphics

Martin Hanak


Martin Hanák

Take a look on this post:

Load multiple drawings into session at once

Jose

Top Tags