Ask and answer engineering questions

Learn from millions of experts

Missing feed

Is there a way where model changes color based excel values

By Yuvraj Naikavde on 12 Aug 14:11 2 answers 440 views 0 comments

I have a part on which have two data sets and i want to do a comparison of one data A to data set B. If the ration A/B is greater than 1 I want that part to be red if not then green. This will be a way to do visual data representation which will help a lot if you have a complex assembly.

2 answers

  • Samu Suojanen
    Samu Suojanen almost 3 years ago

    I don't think there's a way to do this with Expressions tool or similar. Only thing I can think of is NX Open coding, but I'm no use in that.

  • John Cournoyer
    John Cournoyer over 1 year ago

    I believe you can use an API in solidworks. I really don't know anything about API's but I know they have functions for those types of problems.

    API that was online for changing color in solidworks

    Change Color of Face Example (VBA)

    This example shows how to change the color of the selected face to blue.
    '-----------------------------------------------------
    ' Preconditions:
    ' 1. Open a part and select a face.
    ' 2. Open the Immediate window.
    '
    ' Postconditions:
    ' 1. Changes the color of the selected face to blue.
    ' 2. Examine the Immediate window.
    '------------------------------------------------------
    Option Explicit
    Sub main()
    Dim swApp As SldWorks.SldWorks
    Dim swModel As SldWorks.ModelDoc2
    Dim swSelMgr As SldWorks.SelectionMgr
    Dim swFace As SldWorks.Face2
    Dim vFaceProp As Variant
    Dim bRet As Boolean
    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    Set swSelMgr = swModel.SelectionManager
    Set swFace = swSelMgr.GetSelectedObject6(1, -1)
    vFaceProp = swFace.MaterialPropertyValues
    If IsEmpty(vFaceProp) Then
    ' Is empty if face-level colors were not specified,
    ' so get them from underlying model
    vFaceProp = swModel.MaterialPropertyValues
    End If
    'Current color
    Debug.Print "RGB = [" & vFaceProp(0) * 255# & ", " & vFaceProp(1) * 255# & ", " & vFaceProp(2) * 255# & "]"
    Debug.Print "Ambient = " & vFaceProp(3)
    Debug.Print "Diffuse = " & vFaceProp(4)
    Debug.Print "Specular = " & vFaceProp(5)
    Debug.Print "Shininess = " & vFaceProp(6)
    Debug.Print "Transparency = " & vFaceProp(7)
    Debug.Print "Emission = " & vFaceProp(8)
    ' New color
    bRet = swModel.SelectedFaceProperties(RGB(0, 0, 255), vFaceProp(3), vFaceProp(4), vFaceProp(5), vFaceProp(6), vFaceProp(7), vFaceProp(8), False, "")

    ' Deselect face to see new color
    swModel.ClearSelection2 True
    End Sub

Add your answer to: "Is there a way where model changes color based excel values"

Save Cancel