formatting link
if you go to this link you can search this usergroup for anything that has been discussed for the last couple of years even.
Here is a bit of code that should get you going Remember that custom info is case sensitive. If you have old drawings that case wasn't controlled in you might have to make provisions. What worked for me was to delete the custom prop that I wanted to replace and then start from scratch. This was the only way I could change a custom field that was already there.
'if you declare your swApp and Part variables like this it will help you know what options you have for each object.
Dim swApp As SldWorks.SldWorks Dim SetPart as SldWorks.ModelDoc2 Dim Description as String Dim Material As String
Set swApp = Application.SldWorks
Set SetPart = swApp.ActiveDoc
Description = "My Custom Description"
Material = "My Custom Material
partTitle = SetPart.GetTitle If Description = "" Then 'nothing Else 'delete the old description retval = SetPart.DeleteCustomInfo2("", "Description") 'Just incase it was set with caps on delete it that way too retval = SetPart.DeleteCustomInfo2("", "DESCRIPTION") 'add the new custom info 30 stands for the text type of field retval = SetPart.AddCustomInfo3("", "Description", 30, Description) 'delete custom info for configuration specific retval = SetPart.DeleteCustomInfo2("Default", "Description") 'just incase retval = SetPart.DeleteCustomInfo2("Default", "DESCRIPTION") 'set config specific custom info 30 stands for the text type of field retval = SetPart.AddCustomInfo3("Default", "Description", 30, Description) End If If MaterialNo = "" Then Else retval = SetPart.DeleteCustomInfo2("", "Material#") retval = SetPart.DeleteCustomInfo2("", "MATERIAL#") retval = SetPart.AddCustomInfo3("", "Material#", 30, MaterialNo) retval = SetPart.DeleteCustomInfo2("Default", "Material#") retval = SetPart.DeleteCustomInfo2("Default", "MATERIAL#") End If
'I found that if you wanted a custom info with multiple lines you could set a multiline string to it so I made a second description that could have 2 lines. This one I knew wouldn't have been set by anyone so I didn't have to worry about case. If Description2 = "" Then 'Nothing Else retval = SetPart.DeleteCustomInfo2("", "Description2") retval = SetPart.AddCustomInfo3("", "Description2", 30, Description2) End If