Part color/opacity override in an assembly

[ Edited ]


i'm new here, i use solid edge at work and i really like customizing it with macros that speed up my work

i have already coded a few simple macros where everything i needed was already in the solid edge structure (Spy for Solid edge is my best friend Smiley Happy ) and i had little or no problem doing so

now i'm trying to override a part facestyle in an assembly, i want to change color and opacity to each part individually

observing what the command "face override" does, i get that it creates a new object FaceStyle and assings it to the SolidEdgeAssembly.Occurrence that i have selected


this is what i'm experimenting with, keep in mind this is just a proof of concept

this is the best i came out with and it almost does what i want, but i'm still in deep water

how should i create the new FaceStyle to assign to the Occurrence? is there a smarter way to do this?




    Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
        Dim ps As SolidEdgeAssembly.Occurrence
        ps = oApp.ActiveSelectSet.Item(1)
        Dim myfacestyle As SolidEdgeFramework.FaceStyle ' = ps.FaceStyle

        ps.FaceStyle = DirectCast(oApp.ActiveDocument.facestyles.item(5), SolidEdgeFramework.FaceStyle) 'oApp.ActiveDocument.facestyles.add(, "Gray") '("test1", "Gray")
        myfacestyle = ps.FaceStyle
        If myfacestyle.Opacity < 1 Then
            myfacestyle.Opacity = 1
            myfacestyle.Opacity = 0.5
        End If
    End Sub



Re: Part color/opacity override in an assembly

i was almost there

the key is to create a new facestyle object with Add("","Gray") using "" as first argument

The Add not only creates a new object, but it uses another style as a template

here is a working piece of code that switches opacity between 1 and 0.5, hope it helps someone



Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
        Dim aO As SolidEdgeAssembly.Occurrence
        On Error Resume Next
        oAss = oApp.ActiveSelectSet
        On Error Resume Next
        If oAss.Count > 0 Then
            For iAss As Integer = 1 To oAss.Count
                aO = oAss.Item(iAss)
                If aO.Type = -1879909117 Then
                    If IsNothing(aO.FaceStyle) Then 'create an override if there is not one style defined
                        Dim myfacestyle As SolidEdgeFramework.FaceStyle
                        myfacestyle = oApp.ActiveDocument.facestyles.add("", "Gray")
                        aO.FaceStyle = myfacestyle
                    End If
                    If IsNothing(aO.FaceStyle) Then 'facestyle or override not defined
                        oApp.StatusBar = "Impossibile creare uno stile di override!!!"
                        If aO.FaceStyle.Opacity < 1 Then
                            aO.FaceStyle.Opacity = 1
                            aO.FaceStyle.Opacity = 0.5
                        End If
                    End If
                End If
            oApp.StatusBar = "Non è stato selezionato nulla!!!"
        End If
    End Sub