Cancel
Showing results for 
Search instead for 
Did you mean: 

ST9 - how to change the color of the first body in a part?

Gears Esteemed Contributor Gears Esteemed Contributor
Gears Esteemed Contributor

Hi edgers,


although I have searched for the infos about changing part body color via API, the answers I have found will not work with ST9

 

So again my qeustion:

 

Can anybody help me, giving me the hint how to change the body color of e.g. the first body in a part model?

 

Thanks in advance and regards

 

Wolfgang

 



regards
Wolfgang
16 REPLIES

Re: ST9 - how to change the color of the first body in a part?

Gears Honored Contributor Gears Honored Contributor
Gears Honored Contributor

Hi Wolfgang:

 

Not sure if this is the best way but worked for me (tested in ST9):

 

        Dim seApp As SolidEdgeFramework.Application = GetActiveObject("SolidEdge.Application")
        Dim seDoc As SolidEdgePart.PartDocument = seApp.ActiveDocument

        Dim seModel As SolidEdgePart.Model = seDoc.Models(0)
        Dim seBody As SolidEdgeGeometry.Body = seModel.Body
        Dim seFaces As SolidEdgeGeometry.Faces = seBody.Faces(SolidEdgeGeometry.FeatureTopologyQueryTypeConstants.igQueryAll)

        Dim seFaceStyles As SolidEdgeFramework.FaceStyles = seDoc.FaceStyles
        Dim seFaceStyle As SolidEdgeFramework.FaceStyle = seFaceStyles.Add("Test", "")

        seFaceStyle.SetDiffuse(0, 0.9, 0)
        seFaceStyle.SetAmbient(0, 0.4, 0)
        seFaceStyle.SetEmission(0, 0.1, 0)

        Dim seFacesArray(seFaces.Count - 1) As Object 'SolidEdgeGeometry.Face
        Dim seFace As SolidEdgeGeometry.Face
        For i As Integer = 0 To seFaces.Count - 1
            seFace = seFaces.Item(i)
            seFacesArray.SetValue(seFace, i)
        Next
        seBody.SetFacesStyle(seFacesArray.Count, seFacesArray, seFaceStyle)

        seDoc.Recompute()

 

 

Best Regards,

Tushar

Re: ST9 - how to change the color of the first body in a part?

Gears Esteemed Contributor Gears Esteemed Contributor
Gears Esteemed Contributor

Hi @Tushar

 

 

 

thanks for this first answer.

 

I will give it a try but the problem seems to become the issue that there are certain faces which should not be changed, only the original body color.

 

Maybe there is a command available to change the model color itself as I can do it interactively.

But I have not found any API command to do so.

 

20170123_1231.PNG



regards
Wolfgang

Re: ST9 - how to change the color of the first body in a part?

Gears Esteemed Contributor Gears Esteemed Contributor
Gears Esteemed Contributor

Hi,




I just did it myself!

 

 

The hint and the point was to use a SolidEdge PartDocument rather then a SolidEdge Document only.

There I can use the face styles and the SetBaseStyle method

 

 



regards
Wolfgang

Re: ST9 - how to change the color of the first body in a part?

Gears Honored Contributor Gears Honored Contributor
Gears Honored Contributor

Hi Wolfgang,

 

In that case, see the line in bold in snippet below.

This is perhaps what you want.

 

        Dim seApp As SolidEdgeFramework.Application = GetActiveObject("SolidEdge.Application")
        Dim seDoc As SolidEdgePart.PartDocument = seApp.ActiveDocument

        Dim seModel As SolidEdgePart.Model = seDoc.Models(0)
        Dim seFeatures As Features = seModel.Features

        Dim seFaceStyles As SolidEdgeFramework.FaceStyles = seDoc.FaceStyles
        Dim seFaceStyle As SolidEdgeFramework.FaceStyle = seFaceStyles.Add("Sample01", "Blau")

        seFaceStyle.SetDiffuse(0, 0.9, 0)
        seFaceStyle.SetAmbient(0, 0.4, 0)
        seFaceStyle.SetEmission(0, 0.1, 0)

        seDoc.SetBaseStyle(PartBaseStylesConstants.sePartBaseStyle, seFaceStyle)
        seDoc.Recompute()

 

Regards,

Tushar

Re: ST9 - how to change the color of the first body in a part?

Gears Honored Contributor Gears Honored Contributor
Gears Honored Contributor

OOPS, looks like I we were working in real time but you responded earlier Smiley Happy

Anyway, Congrats !!

 

Regards,

~Tushar

 

Re: ST9 - how to change the color of the first body in a part?

Gears Esteemed Contributor Gears Esteemed Contributor
Gears Esteemed Contributor

Hi @Tushar

 

 

 

nevertheless, the hint with PartDocument did it!

 

Thanks for assistance and help.

 

Again:

"This is a great forum with great users!"

 

It is a pleasure to work with and to use Solid Edge together with such wonderfull colleges!

 



regards
Wolfgang

Re: ST9 - how to change the color of the first body in a part?

Builder
Builder

hi @Tushar@hawcad

 

how to do this for Solid Edge ST8 with C# ?

 

 

Regards,

sonny

Re: ST9 - how to change the color of the first body in a part?

Gears Honored Contributor Gears Honored Contributor
Gears Honored Contributor

Re: ST9 - how to change the color of the first body in a part?

Builder
Builder

Hi @Tushar

but code converter is not able to convert this code.

 

cc.JPG I tried to write this without conversion I have this error

 

xx.JPG