I needed to change the update sequence of the active design file. There was a very helpful VBA posted years ago here:
Attachment Sequence Order VBA - [Archived] MicroStation V8i VBA Forum - MicroStation Programming - Bentley Communities
But while noodling on that I realized that the update sequence is a stack and you can just basically just push/pop items in the stack to force the active design file to be first or last. This resulted in a much shorter vba so I thought I'd post it here if anyone wants to use it. I assume V8i works the same but have not tested it.
'-- Update Order is a stack, if you set an attachment's Update Order to a number greater than '-- the total number of attachments, MicroStation will move all elements to fill the hole of '-- where the original attachment was, and set the changed attachment's number to be last in the list. '-- So if we go through the attachments in update order order (lol), skipping the active '-- design file, you'll end up with an update order where the attachments retain the same order '-- as before, but the active design file is first '-- e.g. '-- Before Update Order '-- UO 0 => Attachment 2 '-- UO 1 => Attachment 1 '-- UO 2 => Active Design File '-- UO 3 => Attachment 3 '-- Move UO 0 to UO 5, end result: '-- UO 0 => Attachment 1 '-- UO 1 => Active Design File '-- UO 2 => Attachment 3 '-- UO 3 => Attachment 2 '-- Move UO 0 to UO 5, end result: '-- UO 0 => Active Design File '-- UO 1 => Attachment 3 '-- UO 2 => Attachment 2 '-- UO 3 => Attachment 1 '-- Move UO 1 to UO 5, end result: '-- UO 0 => Active Design File '-- UO 2 => Attachment 2 '-- UO 3 => Attachment 1 '-- UO 1 => Attachment 3 Public Sub SetUpdateSeqActiveDesignFirst() Dim allAtt As Attachments Dim attCount As Integer Dim i As Integer Dim curUO() As Integer ' Current Update Order array, index is the update order #, contents is attachment index number ShowMessage "SetUpdateSeqActiveDesignFirst started", "", msdMessageCenterPriorityInfo, False Set allAtt = ActiveModelReference.Attachments attCount = allAtt.Count ' no attachments? all done If (attCount = 0) Then ShowMessage "No attachements, exiting", "", msdMessageCenterPriorityInfo, False Exit Sub End If ' size the array and init all elements to zero ReDim curUO(attCount) As Integer ShowMessage "Saving current update order", "", msdMessageCenterPriorityInfo, False For i = 1 To attCount ' save the attachment index in it's update order position curUO(allAtt(i).UpdateOrder) = i Next ShowMessage "Adjusting update order", "", msdMessageCenterPriorityInfo, False For i = 0 To UBound(curUO) ' array element that is zero is the active design file, skip it If (curUO(i) > 0) Then ' set attachment's update order to the end of the list (plus some) allAtt(curUO(i)).UpdateOrder = attCount + 2 allAtt(curUO(i)).Rewrite End If Next ' save it all SaveSettings RedrawAllViews ShowMessage "SetUpdateSeqActiveDesignFirst finished", "", msdMessageCenterPriorityInfo, False End Sub
Thanks for your sharing!
Thank you for sharing! I was just looking for this sort of thing. Your solution works perfectly for me.
MaryB
Power GeoPak 08.11.09.918Power InRoads 08.11.09.918OpenRoads Designer 2021 R2