Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How change the color a element?

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
Anonymous
8647 Views, 7 Replies

How change the color a element?

Hello everyone:

 

I am trying change the color a element but the following code not work. I am using Revit 2015. The element is "Parts".

 

For to change to color I am using a foreach:

 

 

FilteredElementCollector collector = new 

FilteredElementCollector(m_revit.ActiveUIDocument.Document).OfClass(typeof(FamilyInstance));


foreach (FamilyInstance fi in collector)
                    {
Color color = m_revit.ActiveUIDocument.Application.Application.Create.NewColor();
                                      color.Blue = ( byte ) 150;
                                      color.Red = ( byte ) 200;
                                      color.Green = ( byte ) 200;

doc.ActiveView.set_ProjColorOverrideByElement(fi.Id, color);

}

set_ProjColoOverrideByElement is deprecate in Revit 2015?

 

Thank's for you help.

 

Regards,

 

David

 

7 REPLIES 7
Message 2 of 8
sanjaymann
in reply to: Anonymous

Here goes:

 

UIApplication uiapp = commandData.Application;
UIDocument uidoc = uiapp.ActiveUIDocument;
Application app = uiapp.Application;
Document doc = uidoc.Document;

Color color = app.Create.NewColor();
color.Blue = (byte)150;
color.Red = (byte)0;
color.Green = (byte)0;

Selection sel = uidoc.Selection;

Reference ref1 = sel.PickObject(
ObjectType.Element,
"Pick element to change its colour");

Element elem = doc.GetElement(ref1.ElementId);

List<ElementId> ids = new List<ElementId>(1);
ids.Add(elem.Id);

Transaction trans = new Transaction(doc);
trans.Start("ChangeColor");

doc.ActiveView.set_ProjColorOverrideByElement(ids, color);

trans.Commit();

 

Thanks & Regards

Sanjay Pandey

Message 3 of 8
augusto.goncalves
in reply to: Anonymous

On 2015 this method was replaced with

uiDoc.ActiveView.SetElementOverrides(....)
Regards,



Augusto Goncalves
Twitter @augustomaia
Autodesk Developer Network
Message 4 of 8
Anonymous
in reply to: augusto.goncalves

Hello,

 

I am using this code and not works with the parameters element Id and color. I'm doing wrong?.

 

if (category == "Parts")
{
FilteredElementCollector collector = new FilteredElementCollector(m_revit.ActiveUIDocument.Document).OfClass(typeof(FamilyInstance));

int i = 0;foreach (FamilyInstance fi in collector) { //Get parameters //Perforacion y cableado Parameter perforacion = fi.LookupParameter("Dia Planeado de Perforacion e Inyeccion"); //Perfilado Parameter perfilado = fi.LookupParameter("Dia Planeado de Perfilado"); //Acero Parameter acero = fi.LookupParameter("Dia Planeado de Colocacion de Acero"); //Encofrado Parameter encofrado = fi.LookupParameter("Dia Planeado de Encofrado"); //Concreto Parameter concreto = fi.LookupParameter("Dia Planeado de Concreto"); //Tensado Parameter tensado = fi.LookupParameter("Dia Planeado de Tensado");
if (ParameterToString(perforacion).Equals(day))
{
//change to color: Celeste
Color color = m_revit.ActiveUIDocument.Application.Application.Create.NewColor();
color.Blue = ( byte ) 150;
color.Red = ( byte ) 200;
color.Green = ( byte ) 200;

m_revit.ActiveUIDocument.Document.ActiveView.SetElementOverrides(fi.Id, color);
                            }
}
}
}

 

 


Regards,

 

David

 

 

Message 5 of 8
augusto.goncalves
in reply to: Anonymous

I believe you need to:

OverrideGraphicSettings ogs= new OverrideGraphicSettings();
ogs.SetProjectionLineColor(color); // or other here

And then

m_revit.ActiveUIDocument.Document.ActiveView.SetElementOverrides(fi.Id, ogs);
Regards,



Augusto Goncalves
Twitter @augustomaia
Autodesk Developer Network
Message 6 of 8
Anonymous
in reply to: augusto.goncalves

Hello Augusto:

 

Thank's very much for respond.

 

The code not have errores but the execute in Revit displays the following message:

 

change_color_1.png


I not understand the problem in this point.


The Code:

foreach (Part fi in collector){ ...........
if (ParameterToString(perforacion) == day)
 {
TaskDialog.Show("GYM-BIM", "Color Celeste = " + day);
//change to color: light blue
Color color = m_revit.ActiveUIDocument.Application.Application.Create.NewColor();
color.Blue = (byte)255;
color.Red = (byte)0;
color.Green = (byte)255;

OverrideGraphicSettings ogs = new OverrideGraphicSettings();
ogs.SetProjectionLineColor(color); // or other here

m_revit.ActiveUIDocument.Document.ActiveView.SetElementOverrides(fi.Id, ogs);

                            }

 

 


Regards,

 

David

 

Message 7 of 8
augusto.goncalves
in reply to: Anonymous

Please try create the color with:

Color color = new Color(0, 255, 255); // RGB
Regards,



Augusto Goncalves
Twitter @augustomaia
Autodesk Developer Network
Message 8 of 8
Anonymous
in reply to: augusto.goncalves

Augusto:

 

Thank's very much. Now works very good.

 

Regards,

 

David

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community