Help with solidworks macro

CAD

I have a bit of problem with my solidworks macro. So I want it to read one of my custom properties. When I go to file -> properties -> custom and configuration properties, I can find it there, but when I run a code sometimes it doesn't recognize it or sometimes it takes it from one of old templates which isn't current one anymore (and I can't see that when I go to file -> properties) Also when I go with only ReferencedConfiguration or ActiveConfiguration, I can't get a desired result. The part of the code goes:

(The thing I want it to read is Šifra)

Function HasDrawingNumber(comp As Variant) As Boolean ' Variant zbog ByRef!

On Error Resume Next: HasDrawingNumber = False

Dim refDoc As SldWorks.ModelDoc2: Set refDoc = comp.GetModelDoc2

If Not refDoc Is Nothing Then

Dim custProps As SldWorks.CustomPropertyManager

Dim valOut As String, valResolved As String

Dim activeConfig As String: activeConfig = refDoc.ConfigurationManager.ActiveConfiguration

Set custProps = refDoc.Extension.CustomPropertyManager(activeConfig)

If Not custProps Is Nothing Then

custProps.Get4 "drawing_no", False, valOut, valResolved

If Len(Trim(valOut)) > 0 Or Len(Trim(valResolved)) > 0 Then ' ‹ FIX!

HasDrawingNumber = True: Exit Function

End If

End If

Set custProps = refDoc.Extension.CustomPropertyManager("")

If Not custProps Is Nothing Then

custProps.Get4 "drawing_no", False, valOut, valResolved

If Len(Trim(valOut)) > 0 Or Len(Trim(valResolved)) > 0 Then

HasDrawingNumber = True: Exit Function

End If

End If

'

Set custProps = refDoc.Extension.CustomPropertyManager("Default")

If Not custProps Is Nothing Then

custProps.Get4 "drawing_no", False, valOut, valResolved

If Len(Trim(valOut)) > 0 Or Len(Trim(valResolved)) > 0 Then

HasDrawingNumber = True: Exit Function

End If

End If

End If

On Error GoTo 0

End Function

Posted Mar 5, 2026, 11:39 AM UTC

310
Loading comments…