Configuration Variable Definition References
  • Table of Variable Definition References
  • Using Variable Definition References

Introduction

MicroStation uses configuration variables extensively. They are an essential tool for the CAD system administrator. Configuration variables allow you to define how MicroStation operates in your organisation, in your site and in your projects.

MicroStation defines a number of configuration variables by default. You can define new configuration variables, redefine existing configuration variables, or remove existing configuration variables.

Variable Definition References

MicroStation V8i introduced another way to create new variables: Variable Definition References. Variable Definition References let you create a file or folder specification by picking apart the components of an existing definition. See the MicroStation help manual topic Configuration Variable File Syntax for more information.

MicroStation recognizes the following kinds of variable definition references:

Variable Definition References
Reference Returns
dev() Device
dir() Directory
devdir() Device and directory
parentdir() Parent directory
parentdevdir() Device and parent directory
basename() Filename without extension
filename() Filename with extension
ext() File extension
noext() Complete file specification without extension
first() First path from a list of paths
concat() Concatenated string
build() Constructs a file definition from pieces of variables

Variable Definition Reference Examples

These examples are taken from the MicroStation help manual. For example, consider configuration variable MS_EXAMPLE_FILE with the definition
d:\Bentley\Workspace\MyProject\3dcells.cel.

$(dev (MS_EXAMPLE_FILE)) expands to d:

$(parentdir (MS_EXAMPLE_FILE)) expands to \Bentley\Workspace

$(filename (MS_EXAMPLE_FILE)) expands to 3dcells.cel

Now consider configuration variable MS_EXAMPLE_PATH with the definition
d:\cell\mycells\;c:\cell\;g:\mycells\

$(first (MS_EXAMPLE_PATH)) expands to d:\cell\mycells\

$(build ("c:",first (MS_EXAMPLE_PATH),"patterns", ext ( (MS_EXAMPLE_FILE)) expands to c:\cell\mycells\patterns.cel

Create a New File Name from the Active Design File Name

Q  A MicroStation user posted this question on the Be Communities website …

I am wondering how to modify key-in: $ ff=$(???) to get a file with, for example, a number on the end of file name. I have tried some obvious combinations but I can only get something before filename. I need to get file name from fence file keyin like this: filename_1.dgn.

To clarify the context of that question, the fence file (FF=) lets you save the contents of a fence to a new file. The user wants to name the new file after the active DGN file, but with a suffix to the file name. For example …

Active DGN File Name Required Fence File Name
abc.dgn abc_1.dgn
def.dgn def_2.dgn
C:\projects\project1\dgn\rst.dgn C:\projects\project1\dgn\rst_3.dgn

A  We can fulfill the user's requirements by applying Variable Definition References. Since the complete statement is complex, we'll break it into digestible pieces. Here's the final statement that implements the user requirement …

$(build (devdir(_dgnFile), concat (basename (_dgnFile), "_1"), ext(_dgnFile)))

Now let's examine each piece of that statement, starting with build.

build()

build as documented "constructs a definition from pieces of variables". What the documentation doesn't tell us is what those pieces should be. A bit of guessing leads us to the conclusion that there are four pieces: the device, path, file title and file extension. Where device is a drive letter (e.g. C:); path means a folder path without the drive letter (e.g. \projects\project1\); file title is the unadorned file name without path or extension; and file extension is the file extension (e.g. dgn).

concat()

concat concatenate (literally, "chains together") two or more strings. That is, concat("abc", "def") results in "abcdef".

basename()

basename extracts the file title from a full file specification. For example, basename("C:\projects\project1\file1.dgn") yields "file1".

ext()

ext (_dgnFile) extracts the file's extension. For example, if the active file is C:\projects\project1\file.dgn then the value of ext (_dgnFile) will be dgn

_dgnFile

_dgnFile is provided by MicroStation. It contains the full file name of the active design file. It has a leading underscore character.

Putting it all together

concat (basename (_dgnFile), "_1") takes the basename of the active design file and suffixes the string "_1". For example, if the active file is C:\projects\project1\file.dgn then the value of concat (basename (_dgnFile), "_1") will be file_1

devdir (_dgnFile) extracts the file's device and folder path. For example, if the active file is C:\projects\project1\file.dgn then the value of devdir (_dgnFile) will be C:\projects\project1

ext (_dgnFile) extracts the file's extension. For example, if the active file is C:\projects\project1\file.dgn then the value of ext (_dgnFile) will be dgn

build (devdir(_dgnFile), concat (basename (_dgnFile), "_1"), ext(_dgnFile)) builds a file path from pieces — which should now be clearer to you — and assembles them into a full path …

C:\projects\project1\file_1.dgn

Plug this into the answer to the original question: I am wondering how to modify key-in: $ ff=$(filename (_dgnFile)) to get a file with, for example, number on the end of file name.

The keyin for File Fence is FF (upper or lower case). The syntax $ FF is MicroStation-speak for "Get the value wanted by FF from a configuration variable". Wrapping our build statement like $(build (...)) converts it to a temporary configuration variable.

Voilà! We can now compute a new file name and pass it to the File Fence command …

$ ff = $(build (devdir(_dgnFile), concat (basename (_dgnFile), "_1"), ext(_dgnFile)))