Background:
I am a Solidworks 2019 user, and our company does not have a PDM system. I would like to streamline the saving convention and make the BOM data extraction process quicker. I am not very familiar with APIs.
Requirement: An equation that can be run to detect and assign a combination of text within a part's title, to automatically compile MATERIAL and DESCRIPTION properties.
Example:
- After modelling, I would like to save a part as "M30405 Gusset". I would manually type all text, and save the file in the applicable folder.
- I would then like to run an equation that detects the first 6 characters in the title, and assign them to the 'PART NUMBER' property of the current file.
- If possible, the same equation should be able to detect all characters after the space, and assign them to the 'DESCRIPTION' property of the file.
What I have done so far:
"dummy"= part.Extension.CustomPropertyManager("").Set("partno", Left(part.GetTitle,6))
"dummy2"= part.Extension.CustomPropertyManager("").Set("description", Mid(part.GetTitle,8,50))
However, when pasting these lines into the File Properties -> Summary Information table, I am not getting any solution.
There are a few resources I investigated, but I can't make it function properly using SolidWorks 2019/2020:
How do I use a PART name and pieces of it to populate Drawings and BOM's?
https://forum.solidworks.com/message/174200#174200#174200
Any help would be appreciated!!
Jan-Hendrik
This is hard set to a 6 digit part number, if your part number length varies you'll have to adjust the code. I did test it for file name 123456 Test1.SLDPRT
Dim swApp As SldWorks.SldWorks
Dim swModel As ModelDoc2
Dim swPart As PartDoc
Dim swCustProp As CustomPropertyManager
Dim PartNumber As Variant
Dim Description As Variant
Dim CurrentFileName As Variant
Option Explicit
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swPart = swModel
Set swCustProp = swModel.Extension.CustomPropertyManager("")
CurrentFileName = Mid(swModel.GetPathName, InStrRev(swModel.GetPathName, "\") + 1)
PartNumber = Left(CurrentFileName, 6)
Description = Left(CurrentFileName, InStrRev(CurrentFileName, ".SLD") - 1)
Description = Right(Description, Len(Description) - 7)
Debug.Print PartNumber
Debug.Print Description
swModel.AddCustomInfo3 "", "partno", swCustomInfoText, PartNumber
swModel.AddCustomInfo3 "", "description", swCustomInfoText, Description
Debug.Print CurrentFileName
End Sub