Is there a way to get the workflow state of a file in the SW PDM Vault, using a visual basic script? I am working on a macro to export STP-files, and I want it to perform the file naming based on whether the file is in state "Released" or not.
That was what I was initially thinking you meant. If you're on PDM standard, the only way to get this data card variable to the custom properties is having it be set during file transitions. Here you see an example of updating the engineer name in the file's custom properties during our revision transition (Released -> Work In Progress). I've highlighted where the state information is available to set to a variable.
This all has to be set up by the Administrator of the PDM database to work properly and even then, it may be quirky.
Without PDM Professional, there's no way to programatically get the state value directly.
Is there away to get the workflow state of a file in the SW PDM Vault, using a visual basic script? I am wokrin on a macro to export STP-files, and I want it to perform file naming based on whether the file is in state "Released" or not
Believe you're not using wPDM. I'm using PDM std and no API support for standard version
The only way I can do is to to get it from CusProp and it'd be a simple macro for it
Alright, sounds promising. Could you help me out with the syntax for getting the workflow state from custom properties?
I guess what I am trying to do, is to get to the PDM Variable "Local State" and use its value in my VBA programming. I don't think I can get to it directly, but there might be a way via the Custom Properties of the document? If so, how is that done?
If that's the case, I think you'll have to coordinate with your PDM administrator to add a variable to the data card and environment. You can then add an action during file transitions to update the value of that variable to the destination state. The default value will need to be set correctly on the data card and it can be made read-only. From there, the transitions should update the variable to the correct value if it's added to each transition of the workflow correctly.
That part is in place. I have a variable called "Local State", which is updated through transitions in the workflow. The problem I have is that I can't figure out how to read that variable from inside a SolidWorks VBA macro.
Understood. Is that variable visible in the custom properties, or just the data card? Do you have a macro started that we can help modify?
If you're looking how to get a custom property, you'll need to get something similar set up to the below example.
Dim Model As ModelDoc2 Dim swExt As ModelDocExtension Dim swCustPropMan As CustomPropertyManager Dim val As String Dim resVal As String
Set Model = swApp.ActiveDoc
Set swExt = Model.Extension Set swCustPropMan = swExt.CustomPropertyManager("")
swCustPropMan.Get4 "Local State", False, val, resVal
' resVal now holds the text definition of the custom property
Edit: This only accesses variables present in this dialog
Below is a draft of what I'm trying to do. Where it says 'State = "???"' is where I want to assign a value to the VBA variable "State" from the PDM variable "Local state", which is available on the data card, but is not available as a custom property of the part. Here is a snip of the data card:
Set swApp = Application.SldWorks Set swModel = swApp.ActiveDoc
'Exit if no model open If swModel Is Nothing Then MsgBox ("No Model Open") Exit Sub End If
Dim revision As String Dim PartNumber As String Dim State As String Dim swName As String Dim currName As String Dim newName As String ' Get Revision Part Number and State revision = swModel.Extension.CustomPropertyManager(Custom).Get("Revision") PartNumber = swModel.Extension.CustomPropertyManager(Custom).Get("Number") State = "???" 'Determine if part is Released and prepare naming accordingly If State = "Released" Then newExtension = "-" & revision & ".step" Else newExtension = "-WIP" & ".step" End If 'Get file name swName = Mid(swModel.GetPathName, InStrRev(swModel.GetPathName, "\") + 1) swName = Left(swName, InStrRev(swName, ".") - 1) 'Update file name currName = swName & ".sldprt" newName = PartNumber & newExtension 'Create the new path replacing the extension strNewPath = Replace(swModel.GetPathName, currName, newName, 1, 1, vbTextCompare) 'Export the part swModel.Extension.SaveAs strNewPath, 0, swSaveAsOptions_Silent, Nothing, lngErrors, lngWarnings
If you're using PDM Professional, there is an API that you can use. I wrote the code below in c# so you'd have to adapt it to VBA for your needs.
It's been a while but I believe this returns the info you are referring to.
I'm using PDM Standard, so I guess this wouldn't work.
Alright, we're getting closer, it seems..
I have admin rights for the PDM, so I tried to perform what you just described. However, my understanding is that the variables (in your example 'Engineer') are within the PDM. Right? I don't see the connection to the custom properties of the file in question.
Also; wouldn't updating the custom properties require that the file is checked out (which it won't be, when undergoing state changes in the workflow)?
That variable is within PDM, yes. The connection to the custom properties is done when the variable is set up initially. There are guides online that can explain that part better than I can.
Technically, you're right that the document isn't checked out during the transition and the changes are to the PDM values only. However, if your drawing template or variable mapping for that type of document is set up correctly to define that custom property by the data card value then the next time you open it, the values should show the updated definitions.
My fingers are bleeding from googling ways of mapping PDM variables to document custom properties, but I have found nothing. I have also tried everything I can think of to create the connection, to no avail. If you could point me in the direction of one of those online guides you mention, I would be very grateful...
OK, I think I figured out after all how to map certain PDM variables to Custom Properties. But my problem now, is that I don't know how to get the State variable. The State shown on the card is the selected from the "Special Values" dropdown in the card editor, where it is called "Current State". However, there is no PDM variable called "Current State". So how, do I access that "Special Value" and turn it into a variable, which I can then map to the custom properties?
Yeah, setting up the default variable on the data card is part of the solution which it sounds like you've done already. If you set it up as a Text variable with a default value of whatever your initial revision is then that should work.
The other part of the solution is to add the action to your file transitions to set that variable to the destination state like I showed in one of my previous replies. Any time the state changes, update the variable to match the current state.
Now, this is all speculation at this point and I think it will work, however I don't know if there are any scenarios that it may be less than reliable.
Alright - I'll keep trying. Thanks for your help!
Have you checked your reference library?
From what I understand, he has PDM Standard which does not allow the use of the API for automation. I've double checked on my end since we also have PDM Standard and it throws a COMException during the vault.LoginAuto line in my test program.
Is it not updating values?
Is this what you are trying to do?
Sub CurrentStatePDM() Dim swApp As SldWorks.SldWorks Dim swModel As SldWorks.ModelDoc2 Dim swModelDocExt As SldWorks.ModelDocExtension Dim sPath As String Dim pdmVault As EdmLib.EdmVault5 Dim aFile As EdmLib.IEdmFile5 Dim sPDMpath As String Set swApp = Application.SldWorks Set swModel = swApp.ActiveDoc Set swModelDocExt = swModel.Extension sPath = swModel.GetPathName Set pdmVault = New EdmVault5 pdmVault.LoginAuto "YOUR_VAULT_NAME_HERE", 0 If pdmVault.IsLoggedIn Then sPDMpath = pdmVault.RootFolderPath Else Err.Raise vbError, "Not connected to PDM" End End If Set aFile = pdmVault.GetFileFromPath(sPath) Debug.Print aFile.CurrentState.Name End Sub
That looks like exactly what I'm trying to do. I do get an error when testing it, though; "User defined type not defined" on the line with the edmlib.EdmVault5 type. My knowledge of VBA is only basic, so I don't know how to get past this. Any suggestions? And by the way; will your code work with my PDM Standard or does it require PDM Professional?
Not sure about PDM Standard but try to add PDM to the references.
Go to Tools-References and find/select the type library - it might not exist or have a different name for PDM Standard.
Btw. When I run the code, I get nothing in return - aFile is an empty string, but pdmVault.IsLoggedIn return True.
I have now added the PDMWorks reference, and gotten a bit further. I also get an error (like Alex Burnett) on the LoginAuto line, although my error is "Method 'loginauto' of object 'IEdmVault20' failed". The vault name is correct (changing it to another name, gives a "couldn't connect"-error).
Ideas? Madson Germano Silva
Guys. I managed to get it done. Using the solution proposed by Alex Burnett of mapping the state to the files Cust Props, I got the PDM and file to mirror each other in terms of what workflow state the file is in. Once the variable was in the Cust Props, I could access it through me VBA macro and then it's downhill from there. Thanks for all the help Alex Burnett, Madson Germano Silva and Thomas Voetmann
Retrieving data ...