1 Reply Latest reply on Mar 8, 2016 7:17 AM by Simon Fritz

    Change  appearance of part in assembly via C# Addin

    Simon Fritz

      Hey guys,

       

      i try to change the color of a component (part) in a assembly via C# Addin. Iam already able to change the color of a part, but then all same parts change there color too. In my case, i want to be able to colorise all parts differently. Usally you can click on a part and change the color individually even when they are the same.

       

      This is how i change the color of a part.

       

      private void changeColor(ModelDoc2 model, string color)

           {

                  Color rgb = Color.FromName(color);

                  double[] properties = {rgb.R / 256, rgb.G / 256, rgb.B / 256, 0.5, 0.5, 0, 0, 0, 0 };

                  model.MaterialPropertyValues = properties;

           }

       

      What i want to do is to change the color of an "AssemblyDoc.component" in a assembly.

       

      This is how i get all components of the assemblydoc:

      object[] comps = swAssemblyDoc.GetComponents(true);

       

       

      Thx in advance!

      Simon

        • Re: Change  appearance of part in assembly via C# Addin
          Simon Fritz

          I fixt the problem:

           

          private void changeColor(ModelDoc2 model, Component2 comp, string color)

                  {

                      Color rgb = Color.FromName(color);

                      double[] properties = (double[])model.MaterialPropertyValues;

                      properties[0] = (double)rgb.R / 256;

                      properties[1] = (double)rgb.G / 256;

                      properties[2] = (double)rgb.B / 256;

                      comp.MaterialPropertyValues = properties;

                  }