Start-up Routines
- Last UpdatedMar 14, 2024
- 3 minute read
Taking advantage of the AutoCAD VBA interface, AVEVA P&ID automatically loads a VBA routine called "UserStartUp" located in the Users module.
By altering the start up routine users can easily modify toolbars and menus, and control whether the Engineering Explorer loads automatically or not. To access this routine, after AVEVA P&ID has been loaded, type VBAIDE at the command prompt.
In the VBA editor go to the VBA project explorer and double click the module Users" and select "UserStartUp".
Note: When a project is upgraded, by default, the users.dvb module is overwritten. However, the upgrade wizard includes an option to preserve it.
Listed below is an example of the start up routine:
Public Sub UserStartUp()
'' This macro will start up automatically with the application.
'' WARNING: Any routine placed here will be run every time a drawing loads...
Dim UsersClass As UserUtils
Dim BatchFile As String
Dim defdir As String
Dim SaveToModelFlag As Boolean
Dim UserPreferences As AcadPreferencesUser
Dim USerName As String
Dim Password As String
Dim Connection As String
Dim PlotfileName As String
Dim ErrorMode As Boolean
Dim FreezeNonPlotLayer As Boolean
Dim PrinterName As String
Dim f As Long
Dim Utils As Object
Dim AutoSave As String
Dim AutoSaveFlag As String
On Error Resume Next
' Get an instance of Public Class UserUtils
Set UsersClass = New UserUtils
' Set User preferences for right click menu, disable AutoCAD short cut menus...
Set UserPreferences = ThisDrawing.Application.Preferences.User
UserPreferences.ShortCutMenuDisplay = False
' Get ruth of Project directory using Directive DATDIR
defdir = UsersClass.GetDefaultDirectory
' Find out if there is a savetoModel bath file to run in batch mode...
If Right(defdir, 1) = "\" Then
BatchFile = defdir & "SaveToModel.Bat"
PlotFile = defdir & "PidPlot.Bat"
BatchConfig = defdir & "pidplot.txt"
Else
BatchFile = defdir & "\SaveToModel.Bat"
PlotFile = defdir & "\PidPlot.Bat"
BatchConfig = defdir & "\pidplot.txt"
End If
If UsersClass.FileExists(PlotFile) Then
'' User must set default values here...
PlotfileName = ""
PrinterName = ""
NumberOfCopies = 1
ErrorMode = False
FreezeNonPlotLayer = True
'' PlotConfig = defdir & "HP LaserJet 5Si.pc3"
PlotConfig = ""
BatchPlot.Show
If Len(PlotConfig) > 3 And InStr(UCase(PlotConfig), "PC3") <> 0 Then
UsersClass.PlotActiveDrawing PlotfileName, PlotConfig, NumberOfCopies, ErrorMode, FreezeNonPlotLayer, PlotPrinter
Set UsersClass = Nothing
Application.ActiveDocument.Close False
Application.Quit
Exit Sub
End If
End If
'' If save To Model Batch File exist then
'' Application will run in Save To Model Mode....
If UsersClass.FileExists(BatchFile) Then
' Save To Model -- SAVE TO DB SET TO: TRUE
' Create Output Files Only SET TO FALSE
SaveToModelFlag = False
'' USERNAME, PASSWORD AND CONNECTION STRING MUST BE SET HERE
If SaveToModelFlag Then
USerName = "SPROC"
Password = "SPROC"
Connection = "vpe53dev1"
End If
UsersClass.SaveToModelInBatchMode USerName, Password, Connection, SaveToModelFlag
Else
''Enable Right Click menu -- Default
UsersClass.EnableRightClickMenu
'' Load Explorer
Application.ActiveDocument.SendCommand "ASEXPLORER" & vbCr
DoEvents
'' Delete P&ID 2nd Toolbar Row
''Application.ActiveDocument.SendCommand "ASDELTOOLBARS" & vbCr
''DoEvents
'' LOADS P&ID 2nd Toolbar Row
''Application.ActiveDocument.SendCommand "ASLOADTOOLBARS" & vbCr
''DoEvents
'' Modify Toolbars ans rearreange P&ID Menus
'' UsersClass.ModStandardTBar
'' Modify Standard menus
''UsersClass.ModStandardMenu
' Set Right Click Menu Status...
'' Disable Rigth click Menu
''UsersClass.DisableRightClickMenu
'' Set return Key to Right Click Menu
''UsersClass.SetRightClickToReturnKey
'' Audit and fix errors in drawing as they are loaded...
''UsersClass.AuditActiveDrawing
'' Validate all pipes mark as invalid (RED) in the explorer
'' Could take a long time in "heavy" drawings...
''UsersClass.ValidateAllPipes
'' Set Drawing LImits to match Project setting for Drawing Length and Height
UsersClass.SetDrawingLimits
'' Set AutoSaveIntervals from project settings
UsersClass.SetProjectAutoSaveTimeSettings
End If