I have several custom properties that are being set via VBA. I would like to add code to read out existing custom properties. The ultimate purpose of this is to be able to avoid asking the user to re-enter custom properties that have already been previously entered. I am currently using the code below to set the properties:
Dim longstatus As Long, longwarnings As Long Dim swConfigMgr As SldWorks.ConfigurationManager, swConfig As SldWorks.Configuration, swCustPropMgr As SldWorks.CustomPropertyManager Set swApp = Application.SldWorks Set swModel = swApp.OpenDoc6(ServPath & PartNum & ".sldprt", swDocPART, swOpenDocOptions_LoadModel, "", longstatus, longwarnings) Set swPart = swModel With swModel .AddCustomInfo3 "", "Part Number", swCustomInfoText, UserFormImportPart.TextBoxPartNum .AddCustomInfo3 "", "Part Name", swCustomInfoText, UserFormImportPart.TextBoxPartName .AddCustomInfo3 "", "Part Description", swCustomInfoText, UserFormImportPart.TextBoxPartDesc .AddCustomInfo3 "", "Source URL", swCustomInfoText, UserFormImportPart.TextBoxSrcURL .AddCustomInfo3 "", "Vendor Part Number", swCustomInfoText, UserFormImportPart.TextBoxVendPartNum .AddCustomInfo3 "", "Image URL", swCustomInfoText, UserFormImportPart.TextBoxImgURL .AddCustomInfo3 "", "Procurement Type", swCustomInfoText, UserFormImportPart.TextBoxProcType If UserFormImportPart.CheckBoxRoHS.Value Then .AddCustomInfo3 "", "RoHS", swCustomInfoText, "Checked" Else .AddCustomInfo3 "", "RoHS", swCustomInfoText, "Unchecked" End If If UserFormImportPart.CheckBoxITAR.Value Then .AddCustomInfo3 "", "ITAR Restricted", swCustomInfoText, "Checked" Else .AddCustomInfo3 "", "ITAR Restricted", swCustomInfoText, "Unchecked" End If End With
This seems to work fine, but in the course of trying to figure out what command reads those properties out, I found that the AddCustomInfo3 method is obsolete, and has been superseded by the CustomPropertyManager. Ultimately, the documentation doesn't seem to provide much information about the difference between these functions and how they should be used. Can someone here explain what the simplest and best means of setting and getting these custom properties currently is? Specifically, it seems like the method most similar to AddCustomInfo3 for getting custom properties is GetCustomInfoType3. Is this correct, and should I avoid using it?
The obsoleted APIs will still work just fine. That said, GetCustomInfoType3 will get, well, the type of custom info (number, text, yes/no, etc), not the value. You are looking for CustomInfo2. The CustomPropertyManager has more functionality and is a bit easier to use, but if you can figure out CustomInfo2 you should be OK.