web
counter

Good Evening EPDM Developers!

equivaq-solidworks-software-app-store-tim-webb-developer-blog

Good Evening EPDM Developers!

Today is November 13, 2012 and its about 11pm. Had a fantastic day today because I worked from the home office and got to take my daughters to school.

Today I spent the day coding a small vb.net addin which hooks a data card button. Here’s a screen capture of the data card editor. The image is out of whack a bit and I was hoping it would be like the ones on SolidWorks forums that shows a thumbnail but when clicked zooms to original. Can’t argue with FREE! 🙂

equivaq-blog-tim-webb-card-button-in-card-editor

It is kinda cute, the source file has a datacard button that pops up a browseforfile box, user selects a destination file, and the addin grabs the document number, description, and revision from the drawing selected and adds the values to the data card the button was executed from. Not too bad.

There isn’t a lot of additional error handling built in as this is just getting the prototype into demo mode.

Decided to test my boundaries a bit because operations needs the ability to reference the two files easily so….I also AddFileShared into the destination folder. Tomorrow I plan to add more code to paste a reference just for grins.

Oh, forgot to mention the button also works on a template card while the template is running. That was a minor challenge hooking the interface to populate the variables since there isn’t too much documentation on how this is done in vb.net.

Here’s the source code. Enjoy!

Tim

Imports EdmLib
‘This addin was created using Jeff Cope’s vb.net addin template builder! Thank you Jeff, I’ve learned a great deal from you.

Public Class DRFCardButton
Implements EdmLib.IEdmAddIn5

Public Sub GetAddInInfo(ByRef poInfo As EdmLib.EdmAddInInfo, ByVal poVault As EdmLib.IEdmVault5, ByVal poCmdMgr As EdmLib.IEdmCmdMgr5) Implements EdmLib.IEdmAddIn5.GetAddInInfo

‘Just some information for the Administrate Add-ins dialog box
poInfo.mbsAddInName = “Card Button Addin”
poInfo.mbsCompany = “<your company>”
poInfo.mbsDescription = “A custom EPDM Addin created to hook a file and template data card button and” & vbNewLine & “return variables from the selected file.”
poInfo.mlAddInVersion = 26
poInfo.mlRequiredVersionMajor = 6
poInfo.mlRequiredVersionMinor = 4

‘Tell EPDM to call us when a card button is pressed.
poCmdMgr.AddHook(EdmCmdType.EdmCmd_CardButton)
‘Tell EPDM to call us when a card variable changes
‘poCmdMgr.AddHook(EdmCmdType.EdmCmd_CardInput)
End Sub

Public Sub OnCmd(ByRef poCmd As EdmLib.EdmCmd, ByRef ppoData As System.Array) Implements EdmLib.IEdmAddIn5.OnCmd
On Error GoTo ErrHand

Dim vars As IEdmEnumeratorVariable8
Dim VariantPath As Object
Dim varDesc As Object
Dim varREV As Object
Dim varDocNum As Object
Dim refFileID As IEdmFile5
Dim vault As IEdmVault5
Dim iCard As IEdmCard6
Dim VarName As String
Dim PathList As IEdmStrLst5
Dim iFile As IEdmFile5
Dim path As String
Dim refFolderID As IEdmFolder5

‘Only react to the file card when the button is pressed.
‘Check the button command so we don’t react to buttons that aren’t ours.
‘We will also get called when the user presses the OK button AND on undo
‘checkout if datacard variables were change because the card variables
‘are changing to either new values or reverting to the original values.
‘The card button title is currently set to “DRFCardButton:UsedIn”. The string length of “DRFCardButton:”
‘is 14 characters long, thus use the Left method to see if this is the specific button we want to act upon
If poCmd.meCmdType = EdmCmdType.EdmCmd_CardButton And Left(poCmd.mbsComment, 14) = “DRFCardButton:” Then
vault = poCmd.mpoVault ‘inherit the vault object

‘Get the name of the variable to update.
VarName = Right(poCmd.mbsComment, Len(poCmd.mbsComment) – 14)

‘This interface does not work. Switching to the mpoExtra because I need an interface to the card to
‘try to share the file later and the only way to ensure the type of interaction going on here is
‘a file card being edited and not a template card being edited (since the template hasn’t created’
‘a file yet), the card interface is used.
‘iCard = vault.GetObject(EdmObjectType.EdmObject_Card, ppoData(0).mlObjectID4) ‘Get the card object

‘Note: You will also receive a pointer to the IEdmEnumeratorVariable5 and IEdmCard5 interfaces via
‘the EdmCmd::mpoExtra argument. The contents of the EdmCmd::mbsComment member is the button command
‘string entered in the Card Editor.
iCard = poCmd.mpoExtra

‘Let the user select a file.
PathList = vault.BrowseForFile(poCmd.mlParentWnd, EdmBrowseFlag.EdmBws_ForOpen + EdmBrowseFlag.EdmBws_PermitVaultFiles, “Adobe PDF Files (*.pdf)|*.pdf||”, “PDF”, “”, “”, “Select file for “ + VarName)

iFile = Nothing
If iCard.CardType = EdmCardType.EdmCard_File Then
‘get the file object
iFile = vault.GetObject(EdmObjectType.EdmObject_File, ppoData(0).mlObjectID1)
‘MsgBox(“This is a file card for file: ” & iFile.Name) ‘debugging only
End If

‘If the user didn’t press Cancel…
If Not PathList Is Nothing Then
path = PathList.GetNext(PathList.GetHeadPosition) ‘get the first member of the returned list
‘MsgBox(“You selected this file:” & vbLf & path) ‘debugging only

‘Store the path in the variable the user pointed out in the button string.
refFolderID = Nothing ‘this is a stupid way to ensure the vb.net IDE does not nag me with warnings 🙂
refFileID = vault.GetFileFromPath(path, refFolderID) ‘Output is the refFolderID as the parent folder object.

VariantPath = path ‘Note this contains the filename

‘Get the variables from the selected destination file
varDesc = GetDataCardVarValue(“Description”, refFileID) ‘get the description
varREV = GetDataCardVarValue(“Revision”, refFileID) ‘get the revision
varDocNum = GetDataCardVarValue(“Document Number”, refFileID) ‘get the document number

vars = poCmd.mpoExtra ‘nestled in there somewhere is a nice enumeratorvariable array exposing the variables for modification
vars.SetVar(VarName, “”, VariantPath) ‘set the “used in” variable
vars.SetVar(“Document Number”, “”, varDocNum) ‘set the document number
vars.SetVar(“Description”, “”, varDesc) ‘set the description
vars.SetVar(“Revision”, “”, varREV) ‘set the revision
vars.Flush() ‘release

‘MsgBox(“Variables have been set on the data card”) ‘debugging only
‘The only reason to have this IF in here is to ensure this code doesn’t run while an epdm template is running
‘because the epdm template would not have created the new file yet.
If iCard.CardType = EdmCardType.EdmCard_File Then
‘MsgBox(“ShareFile: This is a file card” & vbLf & “Destination Folder: ” & refFolderID.LocalPath) ‘debugging only
‘Share the file
refFolderID.AddFileShared(iFile.ID, 0)
‘Make sure the result shows in open Explorer windows
vault.RefreshFolder(refFolderID.LocalPath)
‘nom nom nom nom!
End If
End If
End If

Exit Sub
‘basic error handling but would be better handled with error handling suited for vb.net vs. vb6! oh well, it works ok.
ErrHand:
Dim ErrName As String
Dim ErrDesc As String
vault.GetErrorString(Err.Number, ErrName, ErrDesc)
vault.MsgBox(poCmd.mlParentWnd, “Error in my card button.” + vbLf + ErrDesc)
End Sub

Private Function GetDataCardVarValue(ByVal mVar As String, ByRef file As IEdmFile5) As String
‘Function to return the value of a datacard variable for the specified file or return “EMPTY”
Try
Dim varEnum As IEdmEnumeratorVariable8
varEnum = file.GetEnumeratorVariable
‘Debugging only
Dim value As Object
value = “”
If varEnum.GetVar(mVar, “”, value) Then
Return value
Else
Return “[EMPTY]”
End If
Catch ex As Exception
Return “[EMPTY]”
End Try
End Function

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.

Leave a Reply

Your email address will not be published. Required fields are marked *