Why are you trying to get the custom properties, I guess how will the macro to know what file to open?
I run a macro that will transfer the properties from the model into the drawing file, using the following:
propName = vName
swCustProp.Get5 propName, False, ValOut, ResolvedValOut, wasResolved
swCustPropMgr.Add3 propName, swCustomInfoText, ResolvedValOut, swCustomPropertyReplaceValue
I ran your code without issue. How do you know the code is not working? I see no output. To access the variables PartType, PartMaterial and Description, they need to be declared in the declarations area of the macro; not inside the function.
Have you tried stepping through you code one line at time using F8?
Here is your code with a couple of debug.print statements in it so I can see what is being returned in the immediate window (press ctrl+g to turn on the immediate window if you do not have it active already).
As Peter pointed out, the statement GetCustomInfoValues is obsolete (see SW API help for replacement).
Public Function GetCustomProperties()
Dim FileError As Long
Dim FileWarning As Long
Set swApp = Application.SldWorks
swApp.DocumentVisible False, swDocumentTypes_e.swDocPART
Set oDoc = swApp.OpenDoc6("C:\Test.sldprt", swDocPART, swOpenDocOptions_Silent, "", FileError, FileWarning)
PartType = oDoc.GetCustomInfoValue("", "Part: Type")
PartMaterial = oDoc.GetCustomInfoValue("", "Part: Material")
Description = oDoc.GetCustomInfoValue("", "Part: Description")
Debug.Print PartType, PartMaterial, Description
swApp.DocumentVisible True, swDocumentTypes_e.swDocPART
Hi Darren ,
You can make use of this API which will load the model only in the memory and access all informations.Refer the link for further details.
If you're on subscription then request for your SW Document Manager key and use the Document Manager API to get the custom properties of the files even without opening them.