For the life of me I cant find anything or figure out how to edit a tag's value using VBA.
It seems like it would be easy enough but its got me stumped! Can this be done with VBA?
Jonathan N said:I cant find anything or figure out how to edit a tag's value using VBA
This article about Reading and Writing Tag Data with VBA may help.
Regards, Jon Summers LA Solutions
I got bluemax57's code to work, but I have to select a tag first.
Is it possible to have VBA change the tag value without having to select anything?
Jonathan N said:Is it possible to have VBA change [an element] without having to select anything?
There are several ways that a user can instruct a macro about the object of her desires...
Write a VBA class that Implements ILocateCommandEvents. There are examples in VBA help.
Implements ILocateCommandEvents
ModelReference.GetSelectedElements returns an ElementEnumerator
ModelReference.GetSelectedElements
ElementEnumerator
Fence.GetContents returns an ElementEnumerator
Fence.GetContents
MicroStation's scanner lets you examine every element in a DGN model. See ModelReference.Scan. You can filter the elements using various criteria.
ModelReference.Scan
Hi Jonathan,
Jonathan N said:Is it possible to have VBA change the tag value without having to select anything?
Yes. A standard way is to use ElementScanCriteria to define what type of element want to search and to scan model reference (ActiveModelReference in this case) using the criteria.
See ElementScanCriteria and Scan methods documentation in VBA help, there are several examples available how to use them to find a specific elements in a model.
Regards,
Jan
Bentley Accredited Developer: iTwin Platform - AssociateLabyrinth Technology | dev.notes() | cad.point
Hello Yes, it is possible use
Sub DoExample() Dim ts As TagSet Dim ee As ElementEnumerator Dim sc As New ElementScanCriteria Dim counter As Long Dim eleTag As TagElement Dim today As Date today = Date Set ts = GetTagSet Set ee = ActiveModelReference.GetSelectedElements Do While ee.MoveNext TagElementWithSet ee.Current, ts Loop sc.ExcludeAllTypes sc.IncludeType msdElementTypeTag Set ee = ActiveModelReference.Scan(sc) Do While ee.MoveNext Set eleTag = ee.Current If eleTag.TagSetName = "TagElementExample" Then eleTag.Redraw msdDrawingModeErase If eleTag.TagDefinitionName = "TagNumber" Then counter = counter + 1 eleTag.Value = counter ElseIf eleTag.TagDefinitionName = "DateCounted" Then eleTag.Value = "Counted on " & today End If eleTag.Redraw msdDrawingModeNormal eleTag.Rewrite End If Loop End Sub
look at help scan method
Ciao
Thank you, that was exactly what I was looking for!