Hello MicroStation Programming Community,
How would one check for the existence of a View Group within the active Design File using VBA code? I can't seem to find examples of this. Looking to delete the View Group if it exists.
Thanks!
This actually makes sense to me. Thanks for the explanation...and again, your help.
ProjectWise Explorer CONNECT Edition, Version 10.00.03.453
ProjectWise Drive, Version 2022.1.328
OpenRoads Designer CONNECT Edition, Version 10.09.00.91
OpenRoads Designer CE 202 Release 2, Version 10.10.21.4
Power GEOPAK V8i (SELECTseries 10), Version 08.11.09.918
Matt Kovach said:It should be noted that after making the above oViewGroup Declaration change, a Bentley Exception Error was generated upon running the module (reproduceable)
It is expected behavior. Many languages do not allow to change enumerated collection (iterated using foreach, without explicit index). It is allowed in VBA, but it can lead to invalidation of the collection. So when a member is deleted, that is the last valid operation and the enumeration should be left.
Regards,
Jan
Bentley Accredited Developer: iTwin Platform - AssociateLabyrinth Technology | dev.notes() | cad.point
Strangely enough, after changing the oViewGroup Declaration to Dim oViewGroup As ViewGroup, the applicable View Group can now be deleted. I originally had the oViewGroup Declaration set to Dim oViewGroup As MicroStationDGN.ViewGroup.
It should be noted that after making the above oViewGroup Declaration change, a Bentley Exception Error was generated upon running the module (reproduceable). However, your code includes the Exit For line, which my code did not. Adding this resolved the Bentley Exception Error issue.
Thank you so much for your help!
I do not see any problem in VBA code:
Public Sub DeleteViewGroup() Dim vgs As ViewGroups: Set vgs = ActiveDesignFile.ViewGroups Dim vg As ViewGroup For Each vg In vgs If vg.name = "Multi-Model Views" Then vg.Delete Exit For End If Next End Sub
Is there anything special in your DGN file? Can be the view group deleted manually?
With regards,
The matching View Group is not deleted. Per your suggestion, I revised the code to use oViewGroup.Delete. The result is the same (View Group not deleted).
' Declare variables. Dim oViewGroup As MicroStationDGN.ViewGroup ' Loop through each View Group. For Each oViewGroup In ActiveDesignFile.ViewGroups ' View Group Name is "Multi-Model Views". If (oViewGroup.Name = "Multi-Model Views") Then ' Run command to delete "Multi-Model Views" View Group. ' CadInputQueue.SendKeyin "viewgroup delete " & Chr(34) & "Multi-Model Views" & Chr(34) ' Delete View Group. oViewGroup.Delete End If Next
Matt Kovach said:I've tried this with no luck:
And where the problem is? Your code does not iterate the collection or does not delete the view group?
To use key-ins in code should always be the last solution, when no other option exists. In this case, the ViewGroup object has Delete method.
Hello Jan,
Thanks for your reply. I am attempting to develop a VBA app for OpenRoads Designer CE 2021 Release 2 (Version 10.10.21.40). I checked the VBA Help. However, I cannot find any examples of ViewGroups collection. Therefore, I don't know how to structure the code to cycle through View Groups.
I've tried this with no luck:
' Declare variables. Dim oViewGroup As MicroStationDGN.ViewGroup ' Loop through each View Group. For Each oViewGroup In ActiveDesignFile.ViewGroups ' View Group Name is "Multi-Model Views". If (oViewGroup.Name = "Multi-Model Views") Then ' Run command to delete "Multi-Model Views" View Group. CadInputQueue.SendKeyin "viewgroup delete " & Chr(34) & "Multi-Model Views" & Chr(34) End If Next
Hi Matt,
please respect the best practices and always specify the used product and its exact version. Even though VBA is stable API, not too much different in different products and versions, they are mandatory information that should be shared always.
Matt Kovach said:How would one check for the existence of a View Group within the active Design File using VBA code?
See ViewGroups object, which is a collection containing ViewGroup objects.