<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://communities.bentley.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Check For Existence of View Group using VBA</title><link>https://communities.bentley.com/products/programming/microstation_programming/f/microstation-programming---forum/231353/check-for-existence-of-view-group-using-vba</link><description>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&amp;#39;t seem to find examples of this. Looking to delete the View Group if it exists. 
 
 Thanks!</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: Check For Existence of View Group using VBA</title><link>https://communities.bentley.com/thread/717006?ContentTypeID=1</link><pubDate>Thu, 16 Jun 2022 18:09:14 GMT</pubDate><guid isPermaLink="false">6dad98f5-dbc9-4c4d-a9ba-e9da8dc6aa8e:119dcb2d-cfc2-4358-adc1-2fa86c1909ae</guid><dc:creator>Matt Kovach</dc:creator><description>&lt;p&gt;This actually makes sense to me. Thanks for the explanation...and again, your help.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Check For Existence of View Group using VBA</title><link>https://communities.bentley.com/thread/717004?ContentTypeID=1</link><pubDate>Thu, 16 Jun 2022 17:57:32 GMT</pubDate><guid isPermaLink="false">6dad98f5-dbc9-4c4d-a9ba-e9da8dc6aa8e:5a296861-b71b-426e-88a9-588b156043ed</guid><dc:creator>Jan Šlegr</dc:creator><description>[quote userid="1024582" url="~/products/programming/microstation_programming/f/microstation-programming---forum/231353/check-for-existence-of-view-group-using-vba/717002"]It should be noted that after making the above &lt;span&gt;oViewGroup Declaration&amp;nbsp;&lt;/span&gt;change, a &lt;strong&gt;Bentley Exception Error&lt;/strong&gt; was generated upon running the module (reproduceable)[/quote]
&lt;p&gt;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.&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;&amp;nbsp; Jan&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Check For Existence of View Group using VBA</title><link>https://communities.bentley.com/thread/717002?ContentTypeID=1</link><pubDate>Thu, 16 Jun 2022 17:54:09 GMT</pubDate><guid isPermaLink="false">6dad98f5-dbc9-4c4d-a9ba-e9da8dc6aa8e:b807c3b3-8020-46d2-96c9-050f48c04269</guid><dc:creator>Matt Kovach</dc:creator><description>&lt;p&gt;Strangely enough, after&amp;nbsp;changing the oViewGroup Declaration to&amp;nbsp;&lt;strong&gt;Dim oViewGroup As ViewGroup&lt;/strong&gt;, the applicable View Group can now be deleted. I originally had the&amp;nbsp;&lt;span&gt;oViewGroup Declaration set to&amp;nbsp;&lt;/span&gt;&lt;strong&gt;Dim oViewGroup As MicroStationDGN.ViewGroup&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;It should be noted that after making the above &lt;span&gt;oViewGroup Declaration&amp;nbsp;&lt;/span&gt;change, a &lt;strong&gt;Bentley Exception Error&lt;/strong&gt; was generated upon running the module (reproduceable). However, your code includes the &lt;strong&gt;Exit For&lt;/strong&gt; line, which my code did not. Adding this resolved the&amp;nbsp;&lt;span&gt;Bentley Exception Error issue.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Thank you so much for your help!&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Check For Existence of View Group using VBA</title><link>https://communities.bentley.com/thread/717000?ContentTypeID=1</link><pubDate>Thu, 16 Jun 2022 17:40:04 GMT</pubDate><guid isPermaLink="false">6dad98f5-dbc9-4c4d-a9ba-e9da8dc6aa8e:f814bf93-f828-4af0-a839-cf85adf4d249</guid><dc:creator>Jan Šlegr</dc:creator><description>&lt;p&gt;I do not see any problem in VBA code:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;Public Sub DeleteViewGroup()
    Dim vgs As ViewGroups: Set vgs = ActiveDesignFile.ViewGroups
    Dim vg As ViewGroup
       
    For Each vg In vgs
        If vg.name = &amp;quot;Multi-Model Views&amp;quot; Then
            vg.Delete
            Exit For
        End If
    Next
End Sub
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Is there anything special in your DGN file? Can be the view group deleted manually?&lt;/p&gt;
&lt;p&gt;With regards,&lt;/p&gt;
&lt;p&gt;&amp;nbsp; Jan&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Check For Existence of View Group using VBA</title><link>https://communities.bentley.com/thread/716993?ContentTypeID=1</link><pubDate>Thu, 16 Jun 2022 16:59:30 GMT</pubDate><guid isPermaLink="false">6dad98f5-dbc9-4c4d-a9ba-e9da8dc6aa8e:290427cf-994b-4b7e-b916-5b0b02b634e4</guid><dc:creator>Matt Kovach</dc:creator><description>&lt;p&gt;The matching View Group is not deleted. Per your suggestion, I revised the code to use&amp;nbsp;&lt;strong&gt;oViewGroup.Delete&lt;/strong&gt;. The result is the same (View Group not deleted).&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;&amp;#39; Declare variables.
 Dim oViewGroup As MicroStationDGN.ViewGroup
 
 &amp;#39; Loop through each View Group.
 For Each oViewGroup In ActiveDesignFile.ViewGroups
     &amp;#39; View Group Name is &amp;quot;Multi-Model Views&amp;quot;.
     If (oViewGroup.Name = &amp;quot;Multi-Model Views&amp;quot;) Then
         &amp;#39; Run command to delete &amp;quot;Multi-Model Views&amp;quot; View Group.
         &amp;#39; CadInputQueue.SendKeyin &amp;quot;viewgroup delete &amp;quot; &amp;amp; Chr(34) &amp;amp; &amp;quot;Multi-Model Views&amp;quot; &amp;amp; Chr(34)
         
         &amp;#39; Delete View Group.
         oViewGroup.Delete
     End If
 Next&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Check For Existence of View Group using VBA</title><link>https://communities.bentley.com/thread/716991?ContentTypeID=1</link><pubDate>Thu, 16 Jun 2022 16:54:52 GMT</pubDate><guid isPermaLink="false">6dad98f5-dbc9-4c4d-a9ba-e9da8dc6aa8e:9dee9236-f2d0-467c-a153-79cb44146c75</guid><dc:creator>Jan Šlegr</dc:creator><description>[quote userid="1024582" url="~/products/programming/microstation_programming/f/microstation-programming---forum/231353/check-for-existence-of-view-group-using-vba/716990"]I&amp;#39;ve tried this with no luck:[/quote]
&lt;p&gt;And where the problem is? Your code does not iterate the collection or does not delete the view group?&lt;/p&gt;
&lt;p&gt;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.&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;&amp;nbsp; Jan&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Check For Existence of View Group using VBA</title><link>https://communities.bentley.com/thread/716990?ContentTypeID=1</link><pubDate>Thu, 16 Jun 2022 16:52:12 GMT</pubDate><guid isPermaLink="false">6dad98f5-dbc9-4c4d-a9ba-e9da8dc6aa8e:7ae0bf6e-ba20-42fa-97db-3a354f44a912</guid><dc:creator>Matt Kovach</dc:creator><description>&lt;p&gt;Hello Jan,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks for your reply. I am attempting to develop a VBA app for &lt;strong&gt;OpenRoads Designer CE 2021 Release 2&lt;/strong&gt; (Version &lt;strong&gt;10.10.21.40&lt;/strong&gt;). I checked the VBA Help. However, I cannot find any examples of ViewGroups collection. Therefore, I don&amp;#39;t know how to structure the code to cycle through View Groups.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve tried this with no luck:&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;&amp;#39; Declare variables.
Dim oViewGroup As MicroStationDGN.ViewGroup

&amp;#39; Loop through each View Group.
For Each oViewGroup In ActiveDesignFile.ViewGroups
    &amp;#39; View Group Name is &amp;quot;Multi-Model Views&amp;quot;.
    If (oViewGroup.Name = &amp;quot;Multi-Model Views&amp;quot;) Then
        &amp;#39; Run command to delete &amp;quot;Multi-Model Views&amp;quot; View Group.
        CadInputQueue.SendKeyin &amp;quot;viewgroup delete &amp;quot; &amp;amp; Chr(34) &amp;amp; &amp;quot;Multi-Model Views&amp;quot; &amp;amp; Chr(34)
    End If
Next&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Check For Existence of View Group using VBA</title><link>https://communities.bentley.com/thread/716986?ContentTypeID=1</link><pubDate>Thu, 16 Jun 2022 16:38:39 GMT</pubDate><guid isPermaLink="false">6dad98f5-dbc9-4c4d-a9ba-e9da8dc6aa8e:491afe97-8e48-4646-a56d-b5aa6f5022da</guid><dc:creator>Jan Šlegr</dc:creator><description>&lt;p&gt;Hi Matt,&lt;/p&gt;
&lt;p&gt;please respect &lt;a href="/products/programming/microstation_programming/f/microstation-programming---forum/77384/please-read-microstation-programming-forum-best-practices" rel="noopener noreferrer" target="_blank"&gt;the best practices&lt;/a&gt; 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.&lt;/p&gt;
[quote userid="1024582" url="~/products/programming/microstation_programming/f/microstation-programming---forum/231353/check-for-existence-of-view-group-using-vba"]How would &lt;strong&gt;one&amp;nbsp;check for the existence of a View Group within the active Design File&lt;/strong&gt; using VBA code?[/quote]
&lt;p&gt;See ViewGroups object, which is a collection containing ViewGroup objects.&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;&amp;nbsp; Jan&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>