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 StringDim objDGNFile As DesignFileDim strProjectName As StringDim strFullFileName As StringDim My_Sec As StringPublic 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_SecIf My_Sec = 0 ThenEnd IfIf My_Sec = 1 ThenIf StrComp(strProjectName, "No Project", 1) = 0 Then'MsgBox "working in no project mode"Exit SubElseIf InStr(1, strFullFileName, strProjectName, 1) = 0 ThenMsgBox "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 IfEnd IfIf My_Sec = 2 ThenIf StrComp(strProjectName, "No Project", 1) = 0 Then'MsgBox "working in no project mode"Exit SubElseIf InStr(1, strFullFileName, strProjectName, 1) = 0 ThenMsgBox "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 IfEnd IfEnd Sub
Enjoy and thanks again to Barry for sharing.