Variable Formatting

This feature allows the properties of Entities, Projects and Groups to be formatted inside a string. The feature was primarily developed to allow user defined names to be specified that included dynamic content from model data.

e.g. when defining folder names for CNC output the number or name of the project could be included. C:\MyCNCData\@(ProjectNumber)

How the format string is defined

The format string is made up of constant text and variables. The variables take the form:

@(<VariableName>)

The variable names directly relate to the property names of the classes so any string, number, enumeration or boolean property can be specified. If the variable name cannot be found it will not be resolved and will stay inside the format string unchanged.

e.g. for a Beam using a format string of “@(Length) x @(Width) x @(Height)” would use the Length, Width and Height properties of the beam.

There are also a set of variable names that provide special functionality.

Parent variable names

The following variables represent data for parent objects that can be accessed from their children.

@(Variablename)Description
ElementNumberThe number of the element.
ElementTypeThe type or code of the element.
ElementLengthThe length of the element calculated using the bounds of the GenBeams in the element rounded to zero decimal places.
ElementHeightThe height (dimension in the elements Y direction) of the element calculated using the bounds of the GenBeams in the element rounded to zero decimal places.
ProjectNumberThe number of the project as defined in the project setttings and ProjectInfo class.
ProjectNameThe name of the project as defined in the project setttings and ProjectInfo class.
ProjectDirThe project directory.
ProjectCommentThe comment as defined in the project settings.
ProjectCityThe city as defined in the project settings.
ProjectDwgNameThe name of thw dwg file.
ProjectRevisionThe revision as defined in the project settings.
ProjectStreetThe street as defined in the project settings.
ProjectUserThe user as defined in the project settings.
ProjectCompanyThe company path in the project settings.​
ProjectWallDetailPathThe wall detail path in the project settings.​
ProjectFloorDetailPathThe floor detail path in the project settings.​
ProjectDirNameThe name of the folder where the source drawing file is located.​
GroupNameThe name of group. When used on child Entity it will be the name of the first deliverable group the Entity belongs to.
GroupFileNameThis is the same as GroupName except the name of the groups is changed so that the ‘\’ delimiters are replaced with ‘_’ characters so the output can be used as part of a file name.
GroupLevel1The first part of the hsbCAD group path.
GroupLevel2The second part of the hsbCAD group path.
GroupLevel3The third part of the hsbCAD group path.
GroupEquivalentStory GroupStoryGroup Equivalent Story.
GroupFloorHeight GroupHeightGroup Floor Height.
​ProjectExposes the Project Information including MapX for an Entity. e.g. Project.DwgName
​​Element​Exposes the Element an Entity belongs to. e.g. Element.Code
​​​Group​​Exposes the Group an Entity belongs to. e.g. Group.Name
​​​Date​​Returns the current date in the regional short date format.
​​​​Time​​​​Returns the current time in the regional short time format.
​DateTime​Returns the current date and time in the regional short date and time format without seconds.

e.g. including the element number a beam belongs to. 

string beamDescription = beam.Format(“@(Length) x @(Width) x @(Height) from @(ElementNumber)”); 

Multiwall Variable Name

A special variable name exists to list the single walls of a multiwall.

@(SingleWalls) or just @(SW) will list the names of the single walls.
@(ReverseSingleWalls) or just @(RSW) will list the names of the single walls in reverse order. This can be necessary where the orientation of the multiwall has changed.

An optional paramter can also be used to specify the delimiter.
@(SingleWalls:<delimiter>) where the can be one or more characters.


e.g. For a multiwall containing the walls FF1, FF2, FF3 and FF4 the following formats could be used:
@(SW) = FF1-FF2-FF3-FF4
@(SW:_) = FF1_FF2_FF3_FF4
@(SW:, ) = FF1, FF2, FF3, FF4

Formatting Functions

There are a number of functions that can be used to format string values.
E.g. To take the last two characters from the element number: @(ElementNumber:R2)

Possible functions are: 

AAliases: Aliases allow values to be replaced with another value, an alias.
​ANArchitectural Notation: Formats numbers into architectural notation, taking the precision as a parameter.
​CUChange Unit: Converts units for length, area and volume taking the target unit as a parameter. Supported target unit​s are: mm, cm, m, in, ft. 
DDefault Value: Specifies the value to use if the value can no be resolved. The default is an empty string or a constant can be specified.
DNDecimal Notation: Formats numbers into architectural notation, taking the precision as a parameter.​
RRight: Takes the specified number of characters from the right of the string.
LLeft: Takes the specified number of characters from the left of the string.
PLPad left: Pads the string to the left the specified number of characters with an optional parameter to specify the character to pad with.
PRPad Right: Pads the string to the right the specified number of characters with an optional parameter to specify the character to pad with.
RLRound Local: Rounds a number using the local regional settings.
RRRegex Replace: …. 
RXRegex: …. 
SSubString: Given one number will take all characters starting at the position (zero based).Given two numbers will start at the first number and take the second number of characters.
TTokeniser: Returns the member of a delimited list using the specified index (zero based). A delimiter can be specified as an optional parameter with the default delimiter being the semicolon character.
UUpper: Converts the string to upper case.
#Rounds a number. Specify the number of decimals to round to. Trailing zero’s are removed. 

For example:

Given a group name of “House\Floor\Walls”
@(GroupName:L5) = “House”
@(GroupName:R5) = “Walls”
@(GroupName:S7) = “Floor\Walls”
@(GroupName:S7;5) = “Floor”


It is also possible to chain them together.
@(GroupName:S7:R5:U) = “WALLS” 
@(GroupLevel3:PL7) = ”  Walls”
@(GroupLevel3:PR7;x) = “Wallsxxx”
@(GroupName:T1;\) = “Floor”


Or given a beam with a solid width of 29.499765 mm
        @(SolidWidth:0) = “29”
        @(SolidWidth:1) = “29.5”
        @(SolidWidth:2) = “29.5”

Same could be done for a beam using: @(Solidheight) or @(SolidWidth)

D default value if variable does not get resolved

if Information property is set to: Lion,Tiger,Frog

@(nokey) => @(nokey) // no default specified

@(nokey:D) =>  // empty default returns blank

@(nokey:D”bb”) => bb // default value must be enclosed in double brackets

@(nokey:D;”cc”) => cc // default value can also be second argument

@(nokey:D:PR4;A) => AAAA // After default substitution other commands can be applied

@(nokey:D”BB”:PR4;A) => BBAA // After default substitution other commands can be applied

@(nokey:PR7;a:D:PR4;b) => bbbb // Commands before default are ignored in case of default

@(Information:T1;,:PL6;a:D:PR7;b) => aTigerb // Default is ignored if variable is resolved

As you know, @(nokey:D) => // empty default returns blank

@(key1:D)@(key2:D) would always take key1 and key2, but this ends up as an ‘or’ if only one is present.

​ 

Unit Conversion and Form​atting

@(SolidLength:CU;mm) – change the value from drawing units to mm

@(SolidLength:CU;m) – change to m

@(SolidLength:CU;cm)

@(SolidLength:CU;in)

@(SolidLength:CU;ft)

@(Volume:CU;m) => change value to cubic meters

@(Len:DN3) => force decimal notation, rounding to 3

@(Len:AN3) => force architectural notation, rounding to 1/8

@(Len:CU;mm:DN3) => convert to mm, decimal notation​

@(SolidLength:AN3) – formatted to 1/8 inch

@(SolidLength:AN4) – formatted to 1/16 inch

@(SolidLength:AN5) – formatted to 1/32 inch​

Aliases

Aliases allow values to be replaced with another value, an alias.
The aliases are stored in files inside the company folder.
For more information see our article about Aliases. Alias Manager

PropertySets and MapX

Propertysets are groups of Properties that are added to objects.

MapX is a map (like a set of properties) that is available in the exporter.
MapX and PropretySet data can be accessed by simply specifying the path to data in the underlying map starting with the MapX key or PropertySet name.

The MapX data will take precendence over the PropertySet data.
     e.g. An entitty has MapX data with a key of “Hsb_ElementInfo” which contains a value “Weight”.
This could be accessed using the format:

@(Hsb_ElementInfo.Weight)

The path for MapX data can go as deep as necessary.
    e.g. @(Key.SubMap1.SubMap2.SubMap3.ValueKey).

Drawing Pr​​​operties

The Drawing Properties are specified as:

@(DrawingProperties.Title)
@(DrawingProperties.Author)
@(DrawingProperties.Subject)
@(DrawingProperties.KeyWords)
@(DrawingProperties.Comments)
@(DrawingProperties.LastSavedBy)
@(DrawingProperties.RevisionNumber)
@(DrawingProperties.HyperLink)

 Custom properties are access the same way:

@(DrawingProperties.<CustomPropertyName>)

e.g. @(DrawingProperties.HOI)

Standard names will always take precedence over customer ones, and the names are not case sensitive. ​

RX Regex RX;”expression”  or RXn;”expression”  or RXn;”expression”;”result”  

Learning regex you could use: https://qntm.org/files/re/re.html.

As a regex reference: https://docs.microsoft.com/en-us/dotnet/standard/base-types/regular-expression-language-quick-reference

Some of us use a tool called expresso when validating regex expressions: http://www.ultrapico.com/Expresso.htm.

Find a match using a regex expression. By default the matching expression is returned. Since in an input string multiple matches might be found, the n-th match can be returned by specifying a first argument. By default the first match is returned. When the result string is added as third argument, the match is used to build the result string. In this case regex indexed groups and named groups can be used.

The regex expression as well as the result are encapsulated in double quotes “. The consequence of that is when you want to use double quotes inside them, you have to escape it. The escape character is back slash \. So besides the other special regex characters that need escaping, the double quote needs it too.

If Information property is set to: Lion,Tiger,Frog

The following regex will return the following result:

            @(Information:RX;”[^,]+”) => Lion

            @(Information:RX0;”[^,]+”) => Lion

            @(Information:RX1;”\\w+“) => Tiger

            @(Information:RX2;”\\w+“) => Frog

            @(Information:RX3;”\\w+“) =>

For an Information property: Lion,Tiger():”Elephant”;Frog

The following regex will return the following result:

            @(Information:RX;”[^,]+”) => Lion

            @(Information:RX;”\\w+“) => Lion

            @(Information:RX0;”\\w+“) => Lion

            @(Information:RX1;”\\w+“) => Tiger

            @(Information:RX;”[^,]*”) => Lion // @(Animals:RX”[^,]*”)

            @(Information:RX;”[^)]*”) => Lion,Tiger( // ) chars inside regex string are allowed

            @(Information:RX;”[^:]*”) => Lion,Tiger() // : chars inside regex string are allowed

            @(Information:RX;”[^\\”]*”) => Lion,Tiger(): // ” but escaped as ” inside regex string are allowed

            @(Information:RX;”[^;]*”) => Lion,Tiger():”Elephant” // ; chars inside regex string are allowed

            @(Information:RX;”[^;]*”:RX;”[^,]*”) => Lion // concatenate multiple

If Information property is set to: Lion,Tiger,Frog

The following regex will return the following result:

@(Information:RX0;”([^,]+),”) => Lion

@(Information:RX0;”([^,]+)(,)”;”$1″) => Lion // group index 1

@(Information:RX0;”([^,]+)(,)”;”$2″) => , // second index group

@(Information:RX0;”([^,]+)(,)”;”$3″) => $3 // $3 not found, so not substituted

@(Information:RX0;”(?<key>[^,]+)(,)”;”${key}”) => Lion

@(Information:RX1;”(?<key>[^,]+)(,)”;”${key}$1″) => Tiger, // because first group is named, group index 1 is,

 ​

RR Rege​​x Replace RR;”expression”;”substitute” or RRn;”expression”;” substitute”  

For regex see: https://docs.microsoft.com/en-us/dotnet/standard/base-types/regular-expression-language-quick-reference or https://qntm.org/files/re/re.html.

Find and replace all regex matches. The string with the substituted matches is returned. Since in an input string multiple matches might be found, the first n-th matches will be substituted by specifying a first argument. By default all matches are replaced. The substitute string can contain regex indexed groups and named groups.

The regex expression as well as the substitute are encapsulated in double quotes “. The consequence of that is when you want to use double quotes inside them, you have to escape it. The escape character is back slash \. So besides the other special regex characters that need escaping, the double quote needs it too.

With the Information property set to: Lion,Tiger,Frog

the following regex replace will return the following result:

            @(Information:RR;”[^,]+”;”pussy”) => pussy,pussy,pussy

            @(Information:RR0;”[^,]+”;”pussy”) => Lion,Tiger,Frog

            @(Information:RR1;”\\w+“;”pussy”) => pussy,Tiger,Frog

            @(Information:RR2;”\\w+“;”pussy”) => pussy,pussy,Frog

            @(Information:RR3;”\\w+“;”pussy”) => pussy,pussy,pussy

            @(Information:RR4;”\\w+“;”pussy”) => pussy,pussy,pussy

            @(Information:RR4;”\\w+“;””) => ,, // replace with nothing

With the Information property set to: a lion, a tiger, a frog

the following regex replace will return the following result:

            @(Information:RR;”\\s*\\w+\\s*([^,]+)“;”$1”) => lion,tiger,frog // can use group by one based index

            @(Information:RR;”\\s*\\w+\\s*(?<key>[^,]+)“;”${key}”) => lion,tiger,frog // can use named group

            @(Information:RR1;”\\s*\\w+\\s*[^,]+“;”\\””) => \\”, a tiger, a frog // can substitute into “​

Updated on 01/02/2021

Was this article helpful?

Related Articles

Need Support?
Can’t find the answer you’re looking for? Don’t worry we’re here to help!
Contact Support