Reply

C# : Modifying 3D color

Hello ,

I want to modify a 3D geometry color (a 2D geometry after an extrusion).

Can someone help me please ?

My code change only the 2D geometry :

 

***

colorDialog1.ShowDialog();

double x1 = Convert.ToDouble(textBox1.Text);
double x2 = Convert.ToDouble(textBox2.Text);
double y1 = Convert.ToDouble(textBox3.Text);

application = (SolidEdgeFramework.Application)
Marshal.GetActiveObject("SolidEdge.Application");
// Get a reference to the documents collection
documents = application.Documents;
// Create a new part document
part = (SolidEdgePart.PartDocument)
documents.Add("SolidEdge.PartDocument", Missing.Value);
// Get a reference to the profile sets collection
profileSets = part.ProfileSets;
// Add a new profile set
profileSet = profileSets.Add();
// Get a reference to the profiles collection
profiles = profileSet.Profiles;
// Get a reference to the ref planes collection
refplanes = part.RefPlanes;
// Add a new profile
profile = profiles.Add(refplanes.Item(3));

// Get a reference to the circles2d collection

cirs = profile.Circles2d;
cirs.AddByCenterRadius(x1, x2, y1);
cirs.Item(1).Style.LinearColor = colorDialog1.Color.ToArgb();

aProfiles = Array.CreateInstance(typeof(SolidEdgePart.Profile), 1);
aProfiles.SetValue(profile, 0);

// Get a reference to the models collection
models = part.Models;

// Create the extended protrusion.
model = models.AddFiniteExtrudedProtrusion(aProfiles.Length, ref aProfiles,
SolidEdgePart.FeaturePropertyConstants.igRight, 0.05, Missing.Value, Missing.Value, Missing.Value, Missing.Value);

 

****

Best regards.

Mahbouba

 

2 REPLIES

Re: C# : Modifying 3D color

If you look at the "Part Painter" command, you have Face, Feature or Body options. Here is some code to access the style.

 

using SolidEdgeCommunity;
using SolidEdgeCommunity.Extensions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace StyleDemo
{
    class Program
    {
        [STAThread]
        static void Main(string[] args)
        {
            OleMessageFilter.Register();

            var application = SolidEdgeUtils.Connect();
            var partDocument = application.GetActiveDocument<SolidEdgePart.PartDocument>();
            var model = partDocument.Models.Item(1);
            var protrusion = model.ExtrudedProtrusions.Item(1);

            // Feature styles
            var featureSstyle = protrusion.GetStyle();
            
            // Body styles
            var body = (SolidEdgeGeometry.Body)model.Body;
            var bodyStyle = body.Style;;

            // Face styles
            var faces = (SolidEdgeGeometry.Faces)protrusion.get_Faces(SolidEdgeGeometry.FeatureTopologyQueryTypeConstants.igQueryAll);

            foreach (var face in faces.OfType<SolidEdgeGeometry.Face>())
            {
                var faceStyle = face.Style;
            }

            OleMessageFilter.Unregister();
        }
    }
}

 

 

 

Jason Newell
Applications Architect
www.jasonnewell.net

Re: C# : Modifying 3D color

Hello,

@jnewell 

I add these lines to my last code :

 

***

var body = (SolidEdgeGeometry.Body)models.Item(1).Body; //Line 1
var bodyStyle = body.Style;// Line 2
bodyStyle.SetDiffuse(0, 0.99F, 0); // Line 3
bodyStyle.SetAmbient(0, 0.99F, 0); // Line 4
bodyStyle.SetEmission(0, 0.99F, 0); // Line 5

 

***

but unfortunately I get this error :

 

NullReferenceException: Object reference not set to an instance of an object. (In line 3 )

 

Could you help me please to resolve this problem ?

Regards.

Mahbouba