Color in SolidEdge (C#)

Experimenter
Experimenter

Hello everyone,

 

I'm new to this forum and to the development in SE and i'm building an small AddIn for Parts.

This creates a block such as the one in the .NET Programmer’s Guide.

I want to give this part a green color but i have no idea how to do it. I'm searching all day long but the only thing I find is Visual Basic code. I'm relatively new to programming so i'm not able to read/ translate these this code. Can you guys help me with a simple code for a green color/material on a part in C#?

Thank you!

3 REPLIES

Re: Color in SolidEdge (C#)

Phenom
Phenom

Here is some little code that should help you get started in your pursuit to make a block in Solid Edge appear green. I won't be able to add much about creating an addin in this post but save your block and put it into an assembly and run this code:

 

Dim oApp As SolidEdgeFramework.Application = Marshal.GetActiveObject("SolidEdge.Application")

Dim oDoc As AssemblyDocument = oApp.ActiveDocument

Dim oOccu As SolidEdgeAssembly.Occurrence
oOccu = oDoc.Occurrences.Item(1)

Dim oFS As SolidEdgeFramework.FaceStyle = oOccu.FaceStyle
oFS = oOccu.FaceStyle

oFS.SetDiffuse(0, 0.99, 0)
oFS.SetAmbient(0, 0.99, 0)
oFS.SetEmission(0, 0.99, 0)

The FaceStyle object is the one to focus on for appearance.

The SetDiffuse and other color setter functions take float arguments, which are used to specify the RGB (Red, Green Blue) components of a color in a clamped format i.e. the normal range of 0-255 is clamped to a range of 0 to 1

So a color in RGB which is [255, 128, 64] will be clamped to [1, 0.5, 0.25]

As you said you are new to programming, its right time to invest some time in learning a language like VB.Net which is relatively easier unless C# is a requirment, though translating the above code to C# should not be much difficult.

Re: Color in SolidEdge (C#)

Experimenter
Experimenter

Hi tushar,

 

Sorry for my late response, but I was busy.

Thank you very much for your quick answer.

It helped my a lot!

 

 

Re: Color in SolidEdge (C#)

Experimenter
Experimenter

HI,

 

SolidEdgeFramework.Application app = null;
SolidEdgePart.PartDocument sePart = null;
SolidEdgePart.CurvesByTables objCBTables = null;
SolidEdgePart.CurveByTable objCBTable = null;
SolidEdgePart.RefPlanes objRefPlanes = null;
SolidEdgePart.RefPlane objRefPlane = null;
SolidEdgePart.Profile objCurve;
object[] objTraceprofile = new object[3];
object[] objCSProfile = new object[3];
long[] lngTraceCurveTypes = new long[3];
long[] lngCrossSectionTypes = new long[3];
object[] vOriginArray = new object[3];
SolidEdgeGeometry.Edges edges1 = null;
SolidEdgeGeometry.Edge edge1 = null;
SolidEdgePart.Model model1 = null;
double[] startPoint = new double[3];
double[] endPoint = new double[3];

app = (SolidEdgeFramework.Application)Marshal.GetActiveObject("SolidEdge.Application");
sePart = app.Documents.Add("SolidEdge.PartDocument");

//ViewStyles(SolidEdgeConstants.ColorConstants.seColorGreen);
objCBTables = sePart.Constructions.CurvesByTables;
objCBTable = objCBTables.Add(@"D:\Lead_OF_W1.xls");
objRefPlanes = sePart.RefPlanes;
edges1 = (SolidEdgeGeometry.Edges)objCBTable.get_Edges(SolidEdgeGeometry.FeatureTopologyQueryTypeConstants.igQueryAll);
edge1 = edges1.Item(1);
objTraceprofile[0] = edge1;
edge1.GetEndPoints(startPoint, endPoint);

// Create ref Plane
objRefPlane = objRefPlanes.AddNormalToCurve(edge1, SolidEdgePart.ReferenceElementConstants.igCurveStart, objRefPlanes.Item(2), SolidEdgePart.ReferenceElementConstants.igCurveStart);
objRefPlane.Visible = true;

// create circle on plane
objCurve = sePart.ProfileSets.Add().Profiles.Add(objRefPlane);


objCSProfile[0] = objCurve;
objCurve.Circles2d.AddByCenterRadius(x: 0.0, y: 0.0, Radius: 0.01);

lngTraceCurveTypes[0] = (long)SolidEdgeConstants.FeaturePropertyConstants.igProfileBasedCrossSection;
lngCrossSectionTypes[0] = (long)SolidEdgeConstants.FeaturePropertyConstants.igProfileBasedCrossSection;
vOriginArray[0] = 0;


model1 = sePart.Models.AddSweptProtrusion(1, objTraceprofile, lngTraceCurveTypes, 1, objCSProfile, lngCrossSectionTypes, vOriginArray, 0, SolidEdgePart.FeaturePropertyConstants.igLeft,SolidEdgePart.FeaturePropertyConstants.igNone, 0, null, SolidEdgePart.FeaturePropertyConstants.igNone, 0, null);

 

 

THIS IS THE WAY I AM GETTING SWEEP PROTUCTION USING CODE AFTER GETTING PROTUSION, I WANT TO ADD COLOUR TO PROTUCTION BY GOING TO VIEW-COLUR MANAGER-CONSONENTS -COLOUR .

SO HOW TO DO IT