Replacing multiple attributes in Tag Sets of multiple files


 Product(s):AECOsim Building Designer
 Version(s):V8i (08.11.09.866)
 Environment:N/A
 Area:Annotation
 Subarea:Tags

Problem

There are many files in which some specific attributes are to be deleted and some specific attributes are to be added in some specific Tag sets. This would take a lot of time to do if it is done file by file.

Solution

The fasted way to do it would be to automate this process for the required files. To do this, please run AECOsim Building Designer in Administrator mode and press Alt+F11 to open the Visual Basic Editor. In there, copy one MVBA module and rename it as per your convenience (say, ReplaceTagAtt). Remove all the modules and class modules within this and save it.

In a new module within ReplaceTagAtt.mvba, add the following code:

'Add a new Tag
Dim newtagsets As TagSets
Set newtagsets = MicroStationDGN.ActiveDesignFile.TagSets
Dim newtagset As TagSet
'The following statement is to add a new tag set within which a new tag definition will be created
'To create new tag definition in an existing tag set
'change the <tagset name> with the actual tag set name and uncomment 
'the following line and comment the next line
'Set newtagset = newtagsets.item("<tagset name>")
Set newtagset = newtagsets.Add("NewTagSet1")
Dim NewTagDefs As TagDefinitions
Set NewTagDefs = newtagset.TagDefinitions
Dim newTagDef As TagDefinition
Set newTagDef = NewTagDefs.Add("NewTagDef1", msdTagTypeCharacter)
newTagDef.Prompt = "This is a new Tag"

'Remove existing Tag with name NewTagDef1
Dim TagSets As TagSets
Dim TagSet As TagSet
Dim TagDefs As TagDefinitions
Dim TagDef As TagDefinition
Dim i As Integer
Dim j As Integer
Dim k As Integer

i = 1
k = 1
Set TagSets = MicroStationDGN.ActiveDesignFile.TagSets
'if a tagset name is not known use the following
For Each Item In TagSets
    Set TagSet = TagSets.Item(i)
    Set TagDefs = TagSet.TagDefinitions
    j = TagDefs.count
    For k = 1 To j
        Set TagDef = TagDefs.Item(k)
        If TagDef.Name = "NewTagDef1" Then
            TagDefs.Remove (k)
        End If
        k = k + 1
    Next
    i = i + 1
Next
'if a tagset and Tag set name is known 
'uncomment the following and put the name of the tag set in place of <TagSet Name> and 
'comment the from Dim TagDef as... to ...i= i+1 Next
'Set TagSet = TagSets.Item("<TagSet Name>")
'Set TagDefs = TagSet.TagDefinitions
'TagDefs.Remove("<TagDef Name>")

Things to note before the code is run:

After the code is added and is running successfully, save the MVBA file. To import this code in other files, open the file, go to the Visual Basic Editor (press Alt+F11), go to Tools > References >  Browse > Browse for the MVBA file ("Files of type" should show "All Reference Files") > Select the appropriate MVBA > Click Open. That would import the MVBA file. You can then run the Macro as per your requirement.