MicroStation Project Security App

Big thanks to Barry Lothian for the basics of this code. 

In the past, firms I've worked for have had vb in place that checks where you open files from and alerts you based on a level or security.

Level 0

Nothing happens. Pretty much a free for all.

Level 1

If a user tries to open a file from a location that is not defined by the project then a message box will open up alerting them to the error and suggesting they use the correct location. This more of a reminder than anything else.

Level 2

If a user tries to open a file from a location that is not defined by the project then a message box will open up saying that this is not allowed and that they will be taken back to Microstation manager. This is a great way to close down a project and is used by some firms to stop users access files they shouldn't. 

The vb is simply called up from the Autorun vb app and runs each time a file is opened. The code is:

Option Explicit
'--------------------------------------------------------------
'Declare Local variables
'--------------------------------------------------------------
Dim Cfg_Var_ProjectName As String
Dim objDGNFile As DesignFile
Dim strProjectName As String
Dim strFullFileName As String
Dim My_Sec As String
Public Sub VerifyProject()
Cfg_Var_ProjectName = "$(_USTN_PROJECTNAME)"
strProjectName = ActiveWorkspace.ExpandConfigurationVariable(Cfg_Var_ProjectName)
My_Sec = ActiveWorkspace.ConfigurationVariableValue("MY_SECURITY")
strFullFileName = Application.ActiveDesignFile.Path
'MsgBox My_Sec
If My_Sec = 0 Then

End If

If My_Sec = 1 Then

If StrComp(strProjectName, "No Project", 1) = 0 Then
'MsgBox "working in no project mode"
Exit Sub
ElseIf InStr(1, strFullFileName, strProjectName, 1) = 0 Then
MsgBox "You have attempted to open a file not associated with the current project." & vbCrLf & "Please use the correct Project environment."
'CadInputQueue.SendCommand "CLOSE DESIGN"
Else
'MsgBox "Correct Project"
End If
End If

If My_Sec = 2 Then

If StrComp(strProjectName, "No Project", 1) = 0 Then
'MsgBox "working in no project mode"
Exit Sub
ElseIf InStr(1, strFullFileName, strProjectName, 1) = 0 Then
MsgBox "You have attempted to open a file not associated with the current project." & vbCrLf & "Now returning to the MicroStation manager, please select the correct project and re-open the file."
CadInputQueue.SendCommand "CLOSE DESIGN"
Else
'MsgBox "Correct Project"

End If
End If

End Sub

Enjoy and thanks again to Barry for sharing.