Unload all MVBA from Project Manager

How can I know if there is a project in the projects manager? I want to make a tool to read all projects and then unload all.

Thanks in advance

Parents
  • I created a hidden variable, for example _CLIENT_VBAAUTOLOADS and my PCF file builds the list of MVBA's that need to be loaded based upon client needs. In my Site.cfg file, I use

    MS_VBAAUTOLOADPROJECTS > $(_CLIENT_VBAAUTOLOADS) to setup the loading of the MVBA's.

    However, this did nothing to unload the MVBA already loaded when MicroStation first starts, since MicroStation always loads the last project used when it first opens. I was able to develop this mvba which is run via and OpenCloseEventHandler.

    ' Add reference to: Microsoft Visual Basic for Applications Extensibility 5.3 ' Module adapted from code appearing on Bentley Newsgroups ' Designed to unload and VBA projects not in the MS_VBAAUTOLOADPROJECTS variable. This project is ' expecting to be run from a Open/Close class module and expects the projects in the variable ' may have changed. It will loop through all open projects and unload any not in the list and then ' loop through again, loading any projects that are on the list, but not loaded. ' The logic requires two passes of two nested for each loops. The order of nesting, between the ' two loops is reversed in order to accomplish each step. 'Sub OnProjectLoad(Optional Dummy As Boolean) ' The dummy argument hides this from macros dialog Sub OnProjectLoad() ' To restore, reverse the comments of these lines Dim oVBE As VBIDE.VBE Set oVBE = VBE Dim oProject As VBIDE.VBProject Dim oProjects As VBIDE.VBProjects Set oProjects = VBE.VBProjects Dim vbaProjectsToKeep() As String Dim vbaProject As Variant ' VBA requires this to be a varient and not a string Dim vbaAutoloads As String Dim unload, mustLoad As Boolean unload = True ' Start with assumption that all loaded VBA's must be unloaded mustLoad = True ' Start with assumption that all AutoLoad MVBA's must be loaded With ActiveWorkspace If .IsConfigurationVariableDefined("MS_VBAAUTOLOADPROJECTS") Then vbaAutoloads = .ConfigurationVariableValue("MS_VBAAUTOLOADPROJECTS", True) End If If .IsConfigurationVariableDefined("MS_VBAREQUIREDPROJECTS") Then vbaAutoloads = vbaAutoloads & ";" & .ConfigurationVariableValue("MS_VBAREQUIREDPROJECTS", True) End If End With vbaProjectsToKeep = Split(vbaAutoloads, ";") ' Get an array of AutoLoad VBA Names ' If a user switches projects we need to clear out all VBA's not in the AutoLoad variable. For Each oProject In oProjects ' check each open VBA Project in all open VBA Projects For Each vbaProject In vbaProjectsToKeep ' check each VBA project from list of AutoLoad VBA's ' The Ucase(Cstr()) is used to make sure matches match. Without it, some did not. If UCase(CStr(vbaProject)) = UCase(oProject.Name) Then ' compare AutoLoad vs open VBA's unload = False ' We found a match - its a keeper: Open VBA is in List of AutoLoad VBA's End If Next vbaProject If unload = True Then ' If True, no match found: this one needs to be unloaded. ' Put message in message center to confirm unloading. ShowMessage "Unloading: " & oProject.Name, "Project Name: " & oProject.Name & _ " and Active Project Name: " & oVBE.ActiveVBProject.Name & _ ". Neither of which is in this list:" & vbCr & _ vbaAutoloads, msdMessageCenterPriorityInfo CadInputQueue.SendCommand "VBA UNLOAD " & oProject.Name Else ' Put message in message center to confirm VBA is supposed to remain loaded. ShowMessage oProject.Name, "Project Name: " & oProject.Name & " and Active Project Name: " & _ oVBE.ActiveVBProject.Name & ". Are in the list:" & _ vbCr & vbaAutoloads, msdMessageCenterPriorityInfo End If unload = True ' Reset the flag to make another loop Next oProject ' Force reload of VBA's as not all AutoLoad VBA's load when switching projects For Each vbaProject In vbaProjectsToKeep For Each oProject In oProjects If UCase(CStr(vbaProject)) = UCase(oProject.Name) Then mustLoad = False ' We found a match which means this one is already loaded End If Next oProject If mustLoad = True Then ' If True, no matches were found so we need to load this one. ' Put message in message center to confirm VBA is supposed to be loaded. ShowMessage "Loading " & vbaProject, "Project Name: " & vbaProject & " must be loaded as it" & _ "in one of the VBA in this AutoLoad list:" & _ vbCr & vbaAutoloads, msdMessageCenterPriorityInfo CadInputQueue.SendCommand "VBA LOAD " & vbaProject End If mustLoad = True ' Reset the flag to make another loop Next vbaProject ' HERE LOAD WHAT YOU NEED TO HAVE LOADED ' If you like to unload this project too, uncoment next statement... 'CadInputQueue.SendCommand "VBA UNLOAD " & oVBE.ActiveVBProject.Name ShowStatus "Finishing up in ResetClientAutoRunVBAs.OnProjectLoad" End Sub


    Charles (Chuck) Rheault
    CADD Manager

    MDOT State Highway Administration
    Maryland DOT - State Highway Administration User Communities Page

    • MicroStation user since IGDS, InRoads user since TDP.
    • AutoCAD, Land Desktop and Civil 3D, off and on since 1996
  • caddcop -

    It appears to me that you have already resolved the issue I am having: after exiting MicroStation, the client-based VBAs are not unloading - and are showing up after I restart MicroStation and select a different client-based workspace (project). If I exit MicroStation and select the same workspace the 2nd time, all is OK.

    I have looked at your VBA script - to figure out if I could do something similar but I do not have any programming experience that would guide me through the process :-(

    I am looking for something real basic (simple) - that will unload all (or specific) VBAs when running the PCF file, and then just load whatever new VBA files are specified in the PCF - using MS_VBAAUTOLOADPROJECTS =

    Even if the users have to completely exit MicroStation to switch workspaces (projects), that would be better than what we have going on now.

    Currently, I am in the "testing" mode for V8i workspaces - I am just suprised I have not had this issue while working with my V8 (2004) or V8-XM workspaces.

    I have a ticket in with Bentley on this issue [8001139852] - but so far they have not provided a solution.

    It seems like such a simple task that I am surprised there is not a simple work-around by now.

    Thnaks for any insight you could provide.

Reply
  • caddcop -

    It appears to me that you have already resolved the issue I am having: after exiting MicroStation, the client-based VBAs are not unloading - and are showing up after I restart MicroStation and select a different client-based workspace (project). If I exit MicroStation and select the same workspace the 2nd time, all is OK.

    I have looked at your VBA script - to figure out if I could do something similar but I do not have any programming experience that would guide me through the process :-(

    I am looking for something real basic (simple) - that will unload all (or specific) VBAs when running the PCF file, and then just load whatever new VBA files are specified in the PCF - using MS_VBAAUTOLOADPROJECTS =

    Even if the users have to completely exit MicroStation to switch workspaces (projects), that would be better than what we have going on now.

    Currently, I am in the "testing" mode for V8i workspaces - I am just suprised I have not had this issue while working with my V8 (2004) or V8-XM workspaces.

    I have a ticket in with Bentley on this issue [8001139852] - but so far they have not provided a solution.

    It seems like such a simple task that I am surprised there is not a simple work-around by now.

    Thnaks for any insight you could provide.

Children