We're in the process of changing over our ERP system and now the filename needs to be assigned to the Document Number property on the Project tab. Managemenet has concerns about designers forgetting to populate it and causing issues downstream.
I'm curious if anyone has done a program to retrieve the filename of a part or assembly and auto-populate the same name into the Document Number property (less the extension)? I'm guessing it would have to be an add-in to be able to capture the "after-save" event. I would have to add logic to it because some of our customers have goofy filenaming practices that would need parsed.
Any thoughts, ideas, or points in the right direction would be appreciated
Making this is not difficult.
You can perform the action with this :
Public Sub Populate_DocumentNumber() Dim objApp As SolidEdgeFramework.Application = Nothing Dim ObjDoc As SolidEdgeFramework.SolidEdgeDocument = Nothing Dim ObjProps As SolidEdgeFramework.Properties = Nothing Try objApp = CType(Marshal.GetActiveObject("SolidEdge.Applicati
on"), SolidEdgeFramework.Application) Catch ex As Exception If Not (objApp Is Nothing) Then Marshal.ReleaseComObject(objApp) objApp = Nothing End If Return End Try If Not (objApp Is Nothing) Then ObjDoc = objApp.ActiveDocument Dim FileName As String = System.IO.Path.GetFileNameWithoutExtension(ObjDoc. FullName) 'You can Parse the Filename there ObjProps = ObjDoc.Properties.Item("ProjectInformation") ObjProps.Item("Document Number").Value = FileName End If If Not (objApp Is Nothing) Then Marshal.ReleaseComObject(objApp) objApp = Nothing End If If Not (ObjDoc Is Nothing) Then ObjDoc = Nothing If Not (ObjProps Is Nothing) Then ObjProps = Nothing End Sub
I think of two methods to perform this action :
On save event for the new document - You can perform this using the Addin sample from Jason.
With OpenSave from the existing data - You can modify the OpenSave program installed in the Custom folder of Solid Edge installation.
Hope that would help.
For sure an addin is where you want the functionality to enforce business practices like this. I do similar things at my company. The only tricky part with your requirement is that the filename does not exist until AFTER the document is saved. You then take the filename (minus extension) and assign it to the document number. That will cause the Document.Dirty flag to get set and require ANOTHER save. That workflow is not ideal (I don't have another suggestion) and may cause confusion to a user. The user will be thinking "I just saved the file, why do I have to save it again?". Keep in mind that they could decline the 2nd save and your document number would not be saved. Could just be a training issue but something to keep in mind.
Regarding existing documents that need to be updated, I would recommend using the Solid Edge File Properties API to process these documents.
Just my random thoughts.
Thanks Romuald and Jason,
Great stuff. I hadn't even considered the fact that setting the property would trigger the need for another file save. This will definately take some more discussions on our end to decide if we want to go down that road.