Tim's Blog

Simple Transition Add-in and Tutorial

Written by Tim Webb | Sep 4, 2018 6:50:57 PM

 

Hello EPDM Developers!

Doing some work on a simple transition add-in and tutorial for one of my employees so I am writing a brief description of the work and posting the source code written in VB.Net 2008 express. The source code is commented heavily so there will be plenty of detail.

I use VB.Net 2008 express for development and recommend Jeff Cope’s EPDM add-in template generator found here

Use your preferred development platform.

Goal

The goal is to create an add-in written in vb.net that will be triggered during transitions and post a message box showing you the file name, folder, source state, destination state, and transition name being used. Also, the transition add-in should only be triggered by “PDF” files being transitioned.

The file is in a basic workflow (shown right).

Pseudo code

Here’s a generalization of how the code works. This is also known as the pseudo-code.

  1. The add-in hooks an event that EPDM raises during EPDM commands (i.e. check out/in, transition, deleted, etc.)
  2. When the add-in is triggered/called based on the what action is taken EPDM supplies the add-in with an array of data about the files or folders involved in the hooked action.
  3. Do something with the data EPDM passes to your add-in.

The source code will be shown at the bottom of this post. Paste the entire code below into your project after creating the necessary references to the EDM Library for EPDM if you choose not to use the EPDM VB.Net project template I recommended above.

In VB.Net, build the Project to create the DLL add-in (shown left). You will be able to find the output in your Project folder very much like the one shown.

 

 

Install the Add-in

Right click on the “Add-ins” container in the EPDM Administration Tool. Note there are two options for using an add-in, New and debug.

This concept took me a while to understand but it is really a fantastic server-distributed client philosophy and very powerful.
The “New Add-in” option will upload your compiled DLL to the server and will distribute the DLL to each client at their next login. This should be reserved for the time when your add-in has been thoroughly tested and validated by you and a few users/customers to ensure it is bug free (or at least has bug repellant). If you have to uninstall the add-in and reinstall due to code changes, every client computer will need to be restarted.
The “Debug Add-in” option will only upload the DLL to a memory space on your computer only, since the interop (collected into your project as a reference by vb.net but is a native interoperability library created by EPDM) already is installed. This means, if you upload this in debug mode, the add-in will only run on your computer and will not disrupt any other users in the system.

NOTE: I recommend developing all add-ins in a testbed or development vault for safety reasons.

Installing the add-in is fairly quick. Here are a few things you will see while installing.

Add using “New Add-in” mode

  1. Click “New Add-in”
  2. The first dialog you see is the “Debug Add-ins” and select “Add Add-in”
  3. Navigate to your DLL and select the “TransitionAddinSample.DLL”
  4. Then click “OK”

Quick video adding both the “Interop.EdmLib.dll” and the “TransitionAddinSample.dll” to the EPDM Administration tool

https://youtu.be/M_EB9lxGpsU

Add using Debug mode

Click “Debug Add-in”
The first dialog you see is the “Debug Add-ins” and select “Add Add-in”
Navigate to your DLL and select the “TransitionAddinSample.DLL”
Then click “OK”

Quick video adding ONLY the “TransitionAddinSample.DLL” to the EPDM Administration tool

https://youtu.be/6btULH27dgQ


Here’s a quick video showing it in use…

https://youtu.be/tUvHB2qLp2M


Note there is minimal lag time during the transition however beware of trying to do too many operations in the add-in because user experience could be jeopardized. If a user has to wait too long for a response, they will lose interest.

In fact, this add-in is running in debug mode on files in an EPDM archive server 85 miles away while I work over VPN. Not too bad.

This video shows the PDF being transitioned first and raising the message box. Next, the DWG is transitioned but the message box doesn’t appear so the goal of the program has been satisfied.
Here is the source code. Since I do not have a website with the capabilities to upload files, I am electing to paste the add-in code here:
Disclaimer of Warranty. Any software and any information provided or referred to on the this blog, whether in source or in binary forms, is only provided for non-corporate, non-commercial scientific research purpose on an “AS IS” basis, without warranty of any kind. The entire risk as to the quality and performance of the Software is born to you.

‘Generated using the PDMWE_Addin_Template2 Wizard by Extensible CAD Technologies. Refer to PDMWE_Addin_Template2 Wizard End User License Agreement for usage limitations.
‘http://www.extensiblecad.com

‘NOTE: Make sure you sign your assembly with a strong name! See how here: http://weblogs.asp.net/hosamkamel/archive/2007/09/07/quickly-sign-your-assembly-with-strong-name-using-vs-2005.aspx

‘Enjoy!
‘Jeff Cope

‘As my own side note (aka Tim Webb); I use the template provided by Jeff Cope to create all my addins using vb.net 2008 express. Not sure if these templates are compatible with vb.net 2010 express

Imports EdmLib

Public Class TransitionAddin
Implements EdmLib.IEdmAddIn5

PublicSub GetAddInInfo(ByRef poInfo As EdmLib.EdmAddInInfo, ByVal poVault As EdmLib.IEdmVault5, ByValpoCmdMgr As EdmLib.IEdmCmdMgr5) Implements EdmLib.IEdmAddIn5.GetAddInInfo

‘Just some information for the Administrate Add-ins dialog box
poInfo.mbsAddInName = “Transition Addin”
poInfo.mbsCompany = “<My company name>”
poInfo.mbsDescription = “A custom EPDM Addin to monitor transitions.”
poInfo.mlAddInVersion = 2
poInfo.mlRequiredVersionMajor = 6
poInfo.mlRequiredVersionMinor = 4

‘EdmMenu_MustHaveSelection – The command is only available when the user has selected files or folders in the Windows Explorer file list.
‘EdmMenu_OnlyFiles – The command is not available for selections containing folders, only for files.
‘EdmMenu_OnlyFolders – The command is not available for selections containing files, only for folders.
‘EdmMenu_OnlySingleSelection – The command is only available if only one file or folder has been selected, not for multiple selections.
‘EdmMenu_OnlyMultipleSelection – The command is only available for multiple selections, not for single files or folders.
‘EdmMenu_OnlyInContextMenu – The command should only be present in the right-click context menu, not in the Windows Explorer Tools menu.
‘EdmMenu_NeverInContextMenu – The command should not be present in the right-click context menu, only in the Windows Explorer Tools menu.
‘EdmMenu_HasToolbarButton – The command has a button in the Windows Explorer toolbar. (See IEdmCmdMgr5::AddToolbarImage.)
‘EdmMenu_OwnerDrawToolbarButton – The command uses custom drawing of its toolbar button by implementing IEdmAddInDrawButton5 .
‘EdmMenu_Administration – The menu is displayed in Conisio Administration instead of the Explorer. (New in 6.4)

”Call me when a file has been added
‘poCmdMgr.AddHook(EdmCmdType.EdmCmd_PostAdd)

”Call me when a file has been checked out
‘poCmdMgr.AddHook(EdmCmdType.EdmCmd_PostLock)

”Call me when a file is about to be checked in
‘poCmdMgr.AddHook(EdmCmdType.EdmCmd_PreUnlock)

”Call me when a file has been checked in
‘poCmdMgr.AddHook(EdmCmdType.EdmCmd_PostUnlock)

‘Call me before a file has changed state
‘poCmdMgr.AddHook(EdmCmdType.EdmCmd_PreState)

‘Call me after a file has changed state
poCmdMgr.AddHook(EdmCmdType.EdmCmd_PostState)

End Sub

PublicSub OnCmd(ByRef poCmd As EdmLib.EdmCmd, ByRef ppoData As System.Array) ImplementsEdmLib.IEdmAddIn5.OnCmd

Try
‘If poCmd.meCmdType = EdmCmdType.EdmCmd_PostAdd Then ‘Call me when a file has been added
‘If poCmd.meCmdType = EdmCmdType.EdmCmd_PostLock Then ‘Call me when a file has been checked out
‘If poCmd.meCmdType = EdmCmdType.EdmCmd_PreUnlock Then ‘Call me when a file is about to be checked in
‘If poCmd.meCmdType = EdmCmdType.EdmCmd_PostUnlock Then ‘Call me when a file has been checked in
‘If poCmd.meCmdType = EdmCmdType.EdmCmd_PreUndoLock Then ‘Call me when a file is about to change state
‘If poCmd.meCmdType = EdmCmdType.EdmCmd_PostState Then ‘Call me when a file has changed state
‘If poCmd.meCmdType = EdmCmdType.EdmCmd_PostUndoLock Then ‘Call me when a file is about to change state
‘If poCmd.meCmdType = EdmCmdType.EdmCmd_Menu Then ‘Call me when a menu is selected
If poCmd.meCmdType = EdmCmdType.EdmCmd_PostState Then
‘Call me when a file has changed state

‘Dimension some variables
Dim iFile As IEdmFile5
Dim iFileName As String
Dim iFolder As IEdmFolder5
Dim iFolderName As String
Dim iTransition As IEdmTransition5
Dim iTransitionName As String
Dim iDstState As IEdmState5
Dim iDstStateName As String
Dim iSrcState As IEdmState5
Dim iSrcStateName As String
Dim intIndex, intLast As Long
Dim iVault As IEdmVault11

‘Set some values
iVault = poCmd.mpoVault ‘Capture the incoming vault object to get its name
intIndex = LBound(ppoData) ‘Lower bound of the array holding the files to be processed
intLast = UBound(ppoData) ‘Upper bound of the array holding the files to be processed

‘Loop through the incoming array of files ppoData
While intIndex <= intLast ‘Process the files that changed state.

‘Objects: Get source state, transition, parent Folder, and File objects
iSrcState = iVault.GetObject(EdmObjectType.EdmObject_State, ppoData(intIndex).mlLongData1)
iDstState = iVault.GetObject(EdmObjectType.EdmObject_State, ppoData(intIndex).mlLongData2)
iTransition = iVault.GetObject(EdmObjectType.EdmObject_Transition, ppoData(intIndex).mlObjectID3)
iFile = iVault.GetObject(EdmObjectType.EdmObject_File, ppoData(intIndex).mlObjectID1)
iFolder = iVault.GetObject(EdmObjectType.EdmObject_Folder, ppoData(intIndex).mlObjectID2)

‘Strings: Get the name of the states, transition, file, and folder
iSrcStateName = iSrcState.Name
iDstStateName = iDstState.Name
iTransitionName = iTransition.Name
iFolderName = iFolder.Name
iFileName = iFile.Name

‘Only post a message box for PDF files
If LCase(Right(iFileName, 3)) = “pdf” Then
‘Post a message box for the user to see details about the file being transitioned
MsgBox(“Source State: “ & iSrcStateName & vbLf & _
“Destination State: “ & iDstStateName & vbLf & _
“Transition Name: “ & iTransitionName & vbLf & _
“Filename: “ & iFileName & vbLf & _
“Folder: “ & iFolder.LocalPath, MsgBoxStyle.OkOnly)
‘Place additional code inside this IF statement to make other operations
End If

‘Process next iFile
intIndex = intIndex + 1
End While
End If

Catch ex As Exception
MsgBox(“An Error has occurred.” + vbLf + “Error: “ + System.Reflection.MethodBase.GetCurrentMethod.Name + vbLf + ex.Message, MsgBoxStyle.Exclamation)
End Try

End Sub

End Class
Disclaimer of Warranty. Any software and any information provided or referred to on the this blog, whether in source or in binary forms, is only provided for non-corporate, non-commercial scientific research purpose on an “AS IS” basis, without warranty of any kind. The entire risk as to the quality and performance of the Software is born to you.