Batch Process Series Part 1: Updating your DGN files

Updating design files is often a necessary but tedious task that can be prone to errors and irregularities. When individual files are touched “by hand”, repeated actions can easily be altered or even missed entirely. Automating the update process by scripting out the desired set of actions can streamline and speed the process with a consistent set of output files. This can be achieved through a Batch Process using a script containing the desired commands to be processed.

 

The Batch Process Utility

The Batch Process utility lets you create and run a script that can be performed on individual files or entire directories of files. The script is a text file that contains a series of MicroStation key-ins that can run commands, MicroStation VBA Macros, or MDL applications. For example, you could use the Batch Process utility to quickly remove the unused levels from a selection of design files. The Batch Process utility also lets you define and save a batch process job file. A job file defines the script (command file) and the files to be processed with it. The job file can then be opened, allowing the same batch process to easily be re-run in the future.

 

Accessing the Batch Process Utility

In the MicroStation CONNECT Edition, the Batch Process utility may be accessed from Tools in the Backstage view or activated from Search Ribbon.

When selected, the Batch Process dialog opens.

 (Batch Process dialog)

From Batch Process you may:

  • Create, Open, or Edit a command file
  • Add files or directories to process
  • Open or Save a Batch Process job file
  • Process a Batch Process job

 

The following steps are used to create a Batch Process:

  1. Select a Batch Process command file.
  2. Add files or directories to be processed.
  3. Set the value for Initial Model (using Apply to Selection button).
  4. Save a Batch Process job file (optional).
  5. Run the Batch Process.
  6. Review the results (including log file as desired).

 

The Command File

The Batch Process command file, or script, is used to process a sequence of commands on a selection of files. Command files may be composed to serve any variety of purposes. They can be created as a one off, used for a specific operation, or archived and used repeatedly across files, departments and disciplines, and projects. It can vary from very simple, consisting of but a single command, to quite complex where an extended series of commands are executed.

To create a command file, from Batch Process pick the icon: Create a new command file. You will then be prompted to provide a name and location for the new file, followed by picking Save to complete creating the file. The new command file then opens in a text editor, allowing the desired key-ins to be added.

 

(Batch Process command file)

 

When a new command file is generated, a template is used to provide a starting point for the new file being created. It is possible to modify the template to include a custom set of “default” comments and key-ins to be included in each new command file.

The command file is an ASCII text file containing one or more MicroStation Key-ins. Individual lines may consist of a single command (key-in) or contain a series of commands where each key-in contained in the line is separated by a semicolon.

When creating a command file, it is considered a “best practice” to document what is occurring within each line in the script. A liberal use of comments will assist with maintenance, updating, and in helping others to understand what is occurring. Comments begin with the “#” character. The comment symbol can be used at the beginning of a line or can occur at any point within the line. This can be seen in the example shown below.

(Use of commenting in Batch Process command file)

 

Comments can also be used to prevent a line from being executed without removing that line from the command file. Think of it as a way of “retiring” a command. The command still exists in the script and can be reactivated (by removing the comment symbol) when it is needed again.

Note: It is not necessary to access command files only through the Batch Process dialog. A command file can also be created/edited externally from MicroStation using the text editor of your choice.

 

Adding key-ins to the Command File

Virtually any valid MicroStation key-in can be added to a command file. This includes key-ins to control view attributes, update definitions such as levels and text styles, as well as run macros and MDL applications. The following are some sample key-ins that may be used in a command file:

 

Basic key-ins

Update all text fields in active model:

field update all model

Update a specific type of design library:

dgnlib update dimstyles

Turn off the display of construction elements in view 1 and update the display:

set construct off; selview 1; update 1

 

To run a macro (.bmr)

A MicroStation basic macro can be run using the following key-in syntax:

Run a macro:

macro play MacroNameHere

Note: For MicroStation to run a macro using this key-in, the macro must be located in a folder defined through the configuration variable MS_MACRO.

 

To load an MDL

An MDL application can be loaded using the following key-in syntax:

Load an MDL:

mdl load MDLNameHere

Note: This example will load an MDL application. The MDL must be located in a folder defined through the configuration variable MS_MDL. This will only load the MDL. Many MDL applications, once loaded, will have key-ins that then may be accessed. Many MDL’s only need to be loaded once, and once loaded stay loaded, and can be used across multiple files.

 

The following examples illustrate the use of key-ins and comments. Take a few moments and review the following command files:

5355.MicroStation CONNECT Upgrade.txt
#======================================================================
# Batch Process Command File
# File Name: MicroStation CONNECT Upgrade.txt
# Created/Updated: 01/01/2018
#======================================================================


# Update the file from existing DGNLib's
#----------------------------------------------------------------------
dgnlib update all


# Updates all Text Fields that may be present
#----------------------------------------------------------------------
field update all


# Associate to the active WorkSpace and Workset
#----------------------------------------------------------------------
file associateworkset


#======================================================================
# End of file
#======================================================================
         
8244.Project Archival.txt
#======================================================================
# Batch Process Command File
# File Name: Project Archivalal.txt
# Created/Updated: 01/01/2018
#======================================================================


# Updates all Text Fields that may be present
#----------------------------------------------------------------------
field update all


# Removes unused levels, dimstyles and textstyles from the file
#----------------------------------------------------------------------
delete unused levels
delete unused dimstyles
delete unused textstyles


# Set view attributes (attributes will be updated, but may not dislpay
#    in final file processed until the view window is updated)
#----------------------------------------------------------------------
set ed off;selview 1			# Turn off the display of data fields
set nodes off;selview 1			# Turn off the display of text nodes
set construct off;selview 1		# Turn off the display of construction elements
set grid off;selview 1			# Turn off the display of the grid
set fill on;selview 1			# Enable the display of fill


# Compress the active file and references
#----------------------------------------------------------------------
compress options off			# Turn off Compress Options
compress design includerefs		# Compress active file and all references


# Save settings in the DGN
#----------------------------------------------------------------------
filedesign


#======================================================================
# End of file
#======================================================================
         
1488.Project Submittal.txt
#======================================================================
# Batch Process Command File
# File Name: Project Submittal.txt
# Created/Updated: 01/01/2018
#======================================================================


# Updates all Text Fields that may be present
#----------------------------------------------------------------------
field update all


# Update the file from existing DGNLib's
#----------------------------------------------------------------------
dgnlib update all


# Removes unused levels, dimstyles and textstyles from the file
#----------------------------------------------------------------------
delete unused levels
delete unused dimstyles
delete unused textstyles


# Set view window parameters
#----------------------------------------------------------------------
view off all			# Closes all view windows
view on 1			# Opens view 1
window cascade			# maximizes the open view window
fit all;selview 1		# Fits the content of the model in view 1


# Set view attributes
#----------------------------------------------------------------------
set ed off;selview 1		# Turn off the display of data fields
set nodes off;selview 1		# Turn off the display of text nodes
set construct off;selview 1	# Turn off the display of construction elements
set grid off;selview 1		# Turn off the display of the grid
set fill on;selview 1		# Enable the display of fill



# Compress the active file and references
#----------------------------------------------------------------------
compress options off		# Turn of Compress Options
compress design includerefs	# Compress active file and all references


# Remove the active WorkSpace/Workset information
#----------------------------------------------------------------------
file disassociateworkset


# Save settings in the DGN
#----------------------------------------------------------------------
filedesign


#======================================================================
# End of file
#======================================================================

 

 

Creating and Running a Batch Process

To create and run a Batch Process job is simple, consisting of a few basic steps as outlined earlier. We will now walk through these steps in greater detail.

  1. Select a Batch Process command file.

The first step is to create or select a command file to use for the Batch Process. Here, the Browse button is being used to locate an existing Command File.

  1. Add files or directories to be processed.

After the command file has been chosen, it is time to add files. In the lower left corner of the Select Files and Directories to process dialog, click the arrow to expand the dialog, displaying Selected Files. Browse the folder containing the files you wish to add. Select the files, pick Add, repeating this process until all desired files have been added. Pick Done.

Once the files have been added, the files can be reordered using the “Move” commands located in the Edit menu in the Batch Process dialog.

  1. Set the value for Initial Model (using Apply to Selection button).

It is now time to set the value for Initial. This was initially set as “All Models” and is what is applied to files that are added to the Batch Process. It can be set before files are added or modified on a selection of files already listed in the Batch Process dialog. This is done by selecting one or more files, picking the desired setting, and clicking the button Apply to Selection.  

  1. Save a Batch Process job file (optional).

If the same Batch Process will need to be run again at some point in the future, it is possible to save the existing Batch Process configuration as a Batch Process Job file. The Job file may then be opened, with the Batch Process automatically loading all the required information to run the Batch Process including the Command File, files to be processed, order, model settings, etc.

  1. Run the Batch Process.

When the Batch Process has been configured as desired, it can then be ran using Process Batch Process Job. When selected, the Files to Process dialog opens. Pick Process to begin the Batch Process job.

The files are processed in the order shown in the dialog, with Status displaying the current position in the job.

  1. Review the results (including log file as desired).

Once the Batch Process has completed, the results can then be viewed. In the Files to Process dialog the Status has updated, and processing time displayed.

It is also possible to display the content of the log file. The name and location of the log file can be determined from the Batch Process dialog by picking Edit > Log File Options… and viewing what is displayed in the Log File Options dialog.

Note: The location of the log file is determined by the value of the configuration variable _USTN_OUT.

 

The log file is an ASCII text file, viewable with any text editor. It displays the start time, files processed, processing time, and end time.

(Log file displaying the results of a completed Batch Process)

 

Note: The Batch Process opens each file in MicroStation. The amount of time required can vary depending upon the number of files to process, individual file size, or if the command file includes a more involved set of key-ins.

Additional Uses

You may wonder what the Batch Process utility can be used for. It is certainly not limited to just what was presented within this blog. The following list provides a few possible uses for the Batch Process utility and command file:

  • Assist in migrating project files from a previous version of MicroStation to the MicroStation CONNECT Edition
  • Updating existing CAD Standards in files
  • Preparing to transfer a set of files to someone else
  • Prepare a project for archival

 The uses are limited only by your imagination!

 

In part 2 of this series we will examine ways to obtain the required key-ins for use in command files.

 

 Happy LEARNing!