Use ModelCHECK to Customize Pro/ENGINEER Start Files

Most Pro/ENGINEER installations use start files as templates for creating new files. Examples include start_inch.prt, start_metic.prt, start_inch.asm, start_metric.asm, start_inch.drw and start_metric.drw. These files often contain parameters that users need to update every time they create a new file. Worst yet, some of the parameters are either set to the same value, such as DRAWN_BY or MODELED_BY, or vary in a predictable manner, such as DRAWN_DATE or MODELED_DATE. 

In these cases, wouldn’t it be great to customize start files for each user? This would ensure that everyone uses the same syntax and only approved and correct values. Of course, no administrators in their right mind would consider creating custom start files for each user and they certainly aren’t going to do it every day to make sure the value for DRAWN_DATE is correct.

But what if there is a way to automate it? A way that was invisible to the user? Well, there are in fact several ways to achieve this. The technique outlined here is a bit of “the road less traveled,” but quite slick.

First, The Big Picture

If you are a Pro/ENGINEER administrator, you probably give users a startup script to start Pro/ENGINEER. The technique discussed in this article runs ModelCHECK in batch mode from your startup script to update the latest version of the start file according to individual requirements.

  • The startup script creates a custom ModelCHECK start (.mcs) file on the fly. This file contains all PRT_PARAMETER, ASM_PARAMETER and DRW_PARAMETER options that have known values at the time the script runs.
  • The ModelCHECK condition file is set so that if ModelCHECK is run on the start files, the newly created .mcs file will be read.
  • The ModelCHECK check file should have the batch mode setting limited to Y for only those checks required to update the start files.
  • The config.pro option MODELCHECK_ENABLED must be set to YES.
  • The ModelCHECK config_init.mc file must have the option RUN_MODE set to Y and SHOW_REPORT  to N in batch mode.

 

Next, The Details

1. Copy the START_MODEL_DIR to users’ machines.

This should be done in your startup script. Use robocopy.exe with the /mir attribute to copy these files.  Robocopy.exe is a Windows Utility executable file that will copy files, directories, directory trees, etc. The /mir (as in mirror) option insures that files in the target but not in the source are deleted. Robocopy.exe should be copied to and run from the user machine for best performance. Put in C:\ptc\pro_stds\bin for example.  You may need the Windows Utility executable sleep.exe also.  You will learn why later in this article.  Put it in the same folder as robocopy.exe.

Note: Put a copy of the Pro/ENGINEER purge.bat file in the start model directory.  It will be used to purge this directory after it is copied to the user machine. The purge is done to limit the number of files ModelCHECK runs on to just the latest versions. In addition, this approach insures that users have access to only the latest versions. Be advised that it is possible to code your startup script to delete all but the latest version of a file without using purge.bat, but this works very well.

2. Copy the ModelCHECK standards to the users’ machine. 

Use robocopy.exe here as well.

3. Add code to create a batch_mode_start_files.mcs file on the fly. 

This file will contain all PRT_PARAMETER, ASM_PARAMETER and DRW_PARAMETER options that you want set for each user.

4. Create one text file named username-drawn_by.txt.

The files in the ModelCHECK text directory should have each user’s Windows login name, followed by the value they should be entering for DRAWN_BY or MODELED_BY.  This file will be used in your startup script to find the appropriate value for DRAWN_BY or MODELED_BY for each user.
For example:
jsmi        J. Smith
jdoe        J. Doe
           

 

5. Set the syntax for the date.

This allows the DRAWN_DATE to be entered automatically and per company standards. Yes, you could use the Pro/ENGINEER drawing system parameter todays_date; I have never liked todays_date and have always recommended not using it.  Why you ask, because it is not a static value. If the format gets replaced, todays_date will display the date the replacement was made rather than the date the drawing was created.  Not good.

To determine the OS date format, open a command window and enter echo %DATE%. Figure 1 shows the date format is Day mm/dd/yyyy. This syntax probably does not match the syntax of the DRAWN_DATE parameter, so it will be necessary to extract portions of the variable DATE and then reorganize them or convert them to the match the company standard. For example, 05 in the image below represents the month.  To extract those two characters to the variable MONTH enter:
set MONTH=%DATE:~-10,2%
This instructs the system to go to the 10 character from the end of the string, the 0 in 05, and extract two characters moving rightward beginning with the 0 in 05:
MONTH=05
If you don’t want the 0 in 05, an “if statement” can be used to determine if that character is a 0:
 if %DATE:~-10,1% EQU 0 set MONTH=%DATE:~-9,1%.
MONTH=5
If the syntax requirement of DRAWN_DATE is to display three alpha characters rather than numeric characters, another if statement can be used:
if %MONTH% EQU 5 set MONTH=MAY
Finally, a variable, TODAYS_DATE, can be created to store the syntax:
set TODAYS_DATE=%DATE:~-7,2%-%MONTH%-%DATE:~-4,4%
TODAYS_DATE=25-MAY-2007

Figure 1 displays a command window with each these commands and the result of the command. In practice, this would all be done in the Pro/E startup script. It is displayed here only to illustrate how each command works.


Figure 1

In some companies the OS date format is not consistent from machine to machine even though the OS is the same.  This is particular true if the company has international sites.   If this is the case an if statement can be used to determine which date format is used and how to extract the appropriate characters from the date.

For example two date format possibilities in Windows are Day mm/dd/yyyy and yyyy-mm-dd. If statements, such as the ones below, can be used to determine which date format is currently active.

rem if OS date format = yyyy-mm-dd
set MONTH=
if "%DATE:~-3,1%" == "-" (set MONTH=%DATE:~5,2% && set YEAR=%DATE:~0,4% && set DAY=%DATE:~8,2%) else (goto date_format2)
if defined MONTH goto set_MONTH_format

 

:date_format2
rem if OS date format = Day mm/dd/yyyy
if "%DATE:~-5,1%" == "/" (set MONTH=%DATE:~-10,2% && set YEAR=%DATE:~-4,4% && set DAY=%DATE:~-7,2%)

if not defined MONTH cls & echo. & echo Your computer's DATE format, %DATE%, is not recognized by this startup script.  Please contact your ProE administrator. & echo. & pause
:set_MONTH_format

6. Edit the ModelCHECK Condition File.

This forces ModelCHECK to use the custom start file when it is run on the start files.
IF (MODELNAME EQ START_DRW) config=(check/start_model_checks.mch)(start/start_models.mcs)(constant/mm.mcn)
IF (MODELNAME EQ START_PRT_INCH) config=(check/start_model_checks.mch)(start/start_models.mcs)(constant/inch.mcn)
IF (MODELNAME EQ START_PRT_METRIC) config=(check/start_model_checks.mch)(start/start_models.mcs)(constant/mm.mcn)
IF (MODELNAME EQ START_ASM_METRIC) config=(check/start_model_checks.mch)(start/start_models.mcs)(constant/mm.mcn)
IF (MODELNAME EQ START_ASM_INCH) config=(check/start_model_checks.mch)(start/start_models.mcs)(constant/inch.mcn)

7. Edit the ModelCHECK Check File.

Create a start_model_checks.mch file.  Set only the check STARTCHECKS to Y in batch mode.

8. Edit the ModelCHECK config_init.mc file.

Set the option RUN_MODE to Y in batch mode.  If you do not want the users to use ModelCHECK other than for the purpose described in this article set all other modes for RUN_MODE to N.

To make the running of ModelCHECK invisible to the user set the config_init option SHOW_REPORT  to N in batch mode.  If left at the default Y a ModelCHECK report will open which may bewilder the user.

9. Edit the config.pro file.

Set the option MODELCHECK_ENABLED to YES.

 

The Pro/ENGINEER Startup Script

[Editor: Please note that some lines in the script shown below are "wrapping" to a second line due to length. You can download the script additions in this file.]

In the Pro/ENGINEER startup script add the following:

rem Set Pro/ENGINEER startup directory
set PROE_STARTUP_DIR=C:\pro_work\%USERNAME%
if not exist %PROE_STARTUP_DIR% mkdir %PROE_STARTUP_DIR%
cd /d %PROE_STARTUP_DIR%

rem Set Pro/ENGINEER loadpoint
set PRO_DIRECTORY=C:\ptc\proeWildfire3.0

rem Set location of Company’s Pro_Stds
rem set PRO_STDS=\\server name\share name
set PRO_STDS=\\SERVER01\pro_stds

rem Set location of  local Pro_Stds on user’s machine
set PRO_STDS_LOCAL= C:\ptc\pro_stds

rem Set ModelCHECK’s location
rem MCDIR is a special variable used by Pro/ENGINEER to find ModelCHECK standards.
set MCDIR=%PRO_STDS_LOCAL%\modelcheck

rem Copy ModelCHECK standards to user machine
%PRO_STDS_LOCAL%\bin\robocopy.exe %PRO_STDS%\modelcheck %MCDIR% /mir

rem Set START_MODEL_DIR location
rem For consistency, set config.pro option START_MODEL_DIR $START_MODEL_DIR
set START_MODEL_DIR=%PRO_STDS_LOCAL%\start_models

rem Copy START FILES to user machine
%PRO_STDS_LOCAL%\bin\robocopy.exe %PRO_STDS%\start_models %START_MODEL_DIR% /mir

rem *********************************************
rem  1. Create custom .mcs file
rem  2.  Run ModelCHECK in batch mode on start models

rem Set the value of the Pro/ENGINEER parameter DRAWN_BY and MODELED_BY in all start models based on the environment variable USERNAME and username-drawn_by.txt
setlocal
set DRAWN_BY=
for /f "tokens=1*" %%a in (%MCDIR%\config\text\username-drawn_by.txt) do if /i “%%a” == “%USERNAME%” set DRAWN_BY=%%b

rem Prompt the user to notify their administrator that there is a problem.
if not defined DRAWN_BY cls & echo. & echo Pro/ENGINEER parameter DRAWN_BY value is NOT defined please contact your Pro/E Administrator &echo. & pause & goto eof

rem Set value for DRAWN_DATE based on OS variable DATE
rem Company std for Syntax for DRAWN_DATE is dd-MMM-yyyy

set DRAWN_DATE=
set MONTH=
set YEAR=
set DAY=

rem if OS date format = yyyy-mm-dd
if "%DATE:~-3,1%" == "-" (set MONTH=%DATE:~5,2% && set YEAR=%DATE:~0,4% && set DAY=%DATE:~8,2%) else (goto date_format2)
if defined MONTH goto set_MONTH_format

:date_format2
rem if OS date format = Day mm/dd/yyyy
if "%DATE:~-5,1%" == "/" (set MONTH=%DATE:~-10,2% && set YEAR=%DATE:~-4,4% && set DAY=%DATE:~-7,2%)

if not defined MONTH cls & echo. & echo Your computer's DATE format, %DATE%, is not recognized by this startup script.  Please contact your ProE administrator. & echo. & pause

 

rem Convert month to three alpha characters
set MONTH=%DATE:~-10,2%

if %MONTH% EQU 01 set MONTH=JAN
if %MONTH% EQU 02 set MONTH=FEB
if %MONTH% EQU 03 set MONTH=MAR
if %MONTH% EQU 04 set MONTH=APR
if %MONTH% EQU 05 set MONTH=MAY
if %MONTH% EQU 06 set MONTH=JUN
if %MONTH% EQU 07 set MONTH=JUL
if %MONTH% EQU 08 set MONTH=AUG
if %MONTH% EQU 09 set MONTH=SEP
if %MONTH% EQU 10 set MONTH=OCT
if %MONTH% EQU 11 set MONTH=NOV
if %MONTH% EQU 12 set MONTH=DEC

set TODAYS_DATE=%DATE:~-7,2%-%MONTH%-%DATE:~-4,4%
rem If the first character of the day is 0 remove it from %TODAYS_DATE%
if %DATE:~-7,1% EQU 0 set TODAYS_DATE=%DATE:~-6,1%-%MONTH%-%DATE:~-4,4%

 

 

rem Create custom mc start file
if exist %MCDIR%\config\start\start_models.mcs attrib –r %MCDIR%\config\start\start_models.mcs
echo PRT_PARAMETER         MODELED_BY           STR     EQ       %DRAWN_BY%> %MCDIR%\config\start\start_models.mcs
echo ASM_PARAMETER       MODELED_BY           STR     EQ       %DRAWN_BY% >> %MCDIR%\config\start\start_models.mcs
echo DRW_PARAMETER       DRAWN_BY   STR     EQ       %DRAWN_BY% >> %MCDIR%\config\start\start_models.mcs
echo DRW_PARAMETER       DRAWN_DATE          STR     EQ       %TODAYS_DATE% >> %MCDIR%\config\start\start_models.mcs

 

endlocal
rem Create list to run MC on
rem Add to list file only the latest iteration of each file in %START_MODEL_DIR%
cd /d %START_MODEL_DIR%
call %START_MODEL_DIR%\purge.bat
dir /b /o:-d %START_MODEL_DIR%\start_*.*> parts.lst

rem Run ModelCHECK in batch mode on 32 bit machines
if exist %PRO_DIRECTORY%\i486_nt\obj\modelcheck.exe %PRO_DIRECTORY%\i486_nt\obj\modelcheck.exe %PRO_DIRECTORY%\bin\proe1.bat -f parts.lst

rem Run ModelCHECK in batch mode on 64 bit machines
if exist %PRO_DIRECTORY%\x86e_win64\obj\modelcheck.exe %PRO_DIRECTORY%\x86e_win64\obj\modelcheck.exe %PRO_DIRECTORY%\bin\proe1.bat -f parts.lst

rem Optional pause to allow ModelCHECK to run and Pro/ENGINEER license to be released prior to starting the user’s Pro/ENGINEER session.  Uncomment (rem) the line below if a pause is required.
rem % PRO_STDS_LOCAL %\bin\sleep.exe 20

rem Start user’s ProE session
cd /d %PROE_STARTUP_DIR%

 

call %PRO_DIRECTORY%\bin\proe1.bat
rem End Startup Script
:eof

 

Buyer Beware

One thing to consider before implementing this technique is the number of Pro/ENGINEER licenses available. ModelCHECK in batch mode requires a license, as does the user's Pro/ENGINEER session. There will be a very short period of time that the two licenses will be necessary. If you have plenty of licenses, this is not a problem. If you get down to one license available and a user want to run that license, however, they will not be able to access it using the startup script as is.

Here are a few ways to get around this problem.  The only one I recommend however is option 1.  The others work but they have down sides that make them less attractive options.

  1. Run Windows Resource Utility sleep.exe for a few seconds after ModelCHECK is started. This gives ModelCHECK time to finish before the user’s Pro/ENGINEER session starts.  This is included in the code above.
  2. In the startup script, reverse the order that the user grabs the two required licenses.  This will allow the user to get a license so that they can work if a second license is not available but it will not update the start models unless the script is paused until a license becomes available. A pause can be built into the script to run ptcstatus.bat. The output of ptcstatus.bat can then be queried to see if a license is available. If it is, ModelCHECK would run. If a license is not available, ptcstatus.bat would run again. This logic would be set to loop until a license becomes available.  This will work but running ptcstatus.bat can be time consuming.
  3. Rather than run ModelCHECK to do this, incorporate the same logic to create a trail file that runs when Pro/ENGINEER is started.  This takes a bit longer for Pro/ENGINEER to start but it does work.
  4. Rather than run ModelCHECK to do this, incorporate the same logic into start part, start asm and start drw mapkeys.  There is no way to force a user to use a mapkey to start new files; therefore this approach does have a down side.

David Graham is a Pro/ENGINEER / PDMLink Administrator at Emhart Glass in Enfield, CT.

Using ModelCHECK to Customize Start Files

Putting Science Education FIRST

In the Studio with Pro/ENGINEER

Shift from Physical to Virtual Prototyping

World Event 2007 Recap

Integrating Full-Text Search and Windchill 8.0

Developing Custom J-Link Applications

Go Interactive with Pro/INTRALINK Scripts

Creative
Capturing—
Converting Ideas to Parts

A Quick End to Duplicate Naming Problems

Using Trail Files to Save the Day