I am having some issues with the code i have shown below. When i run it it returns color as "". My custom property in my part is name Color so i dont know if that has anythign to do with it. I dont really know enough about this stuff to find the problem so i am hoping someone can help me out.
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swPart As SldWorks.PartDoc
Dim vMatProps As Variant
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swPart = swModel
Dim Color As String
If Color = "White" Then
vMatProps = swPart.MaterialPropertyValues
vMatProps(0) = 255 / 256
vMatProps(1) = 255 / 256
vMatProps(2) = 255 / 256
ElseIf Color = "Tan" Then
vMatProps = swPart.MaterialPropertyValues
vMatProps(0) = 210 / 256
vMatProps(1) = 180 / 256
vMatProps(2) = 140 / 256
End If
swPart.MaterialPropertyValues = vMatProps
End Sub
Function Get3(ByVal FieldName As String, ByVal UseCached As Boolean, ByRef ValOut As String, ByRef ResolvedValOut As String) As Boolean
Dim instance As ICustomPropertyManager
Dim FieldName As String
Dim UseCached As Boolean
Dim ValOut As String
Dim ResolvedValOut As String
Dim value As Boolean
value = instance.Get3(FieldName, UseCached, ValOut, ResolvedValOut)
Color = value
End Function
SolidworksApi macros