A couple of revit macros that sets halftone and some other graphic overrides.
public void SetHalftone()
{
UIDocument uidoc = this.ActiveUIDocument; //dont need this
Document doc = this.ActiveUIDocument.Document;
// Get the element selection of current document
Selection selection = uidoc.Selection;
//store element id's
ICollection<ElementId> selectedIds = uidoc.Selection.GetElementIds();
FilteredElementCollector fec = new FilteredElementCollector( doc ).OfClass( typeof( LinePatternElement ) );
LinePatternElement linePatternElem = fec.Cast<LinePatternElement>().First<LinePatternElement>( linePattern => linePattern.Name == @"Center 1/4""");
TaskDialog.Show("Revit Line Pattern", linePatternElem.Name.ToString());
try
{
foreach (ElementId eid in selectedIds)
{
Element e = doc.GetElement(eid);
using (Transaction trans = new Transaction(doc, "rotate"))
{
try
{
trans.Start();
//if(doc.ActiveView.GetElementOverrides(eid).Halftone==true)
//{
OverrideGraphicSettings ORGS = new OverrideGraphicSettings();
ORGS.SetHalftone(false);
Color white = new Color(0xFF, 0xFF, 0xFF);
Color black = new Color(0x00, 0x00, 0x00);
Color red = new Color(0xFF, 0x00, 0x00);
Color blue = new Color(0x00, 0x00, 0xFF);
Color green = new Color(0x00, 0xFF, 0x00);
//ORGS.SetProjectionLineColor(new Color(0x00, 0x00, 0x00));
ORGS.SetProjectionLineColor(blue);
ORGS.SetProjectionLinePatternId(linePatternElem.Id);
ORGS.SetProjectionLineWeight(5);
doc.ActiveView.SetElementOverrides(eid, ORGS);
TaskDialog.Show("Revit", "Set Color");
//}
//else if (doc.ActiveView.GetElementOverrides(eid).Halftone == false)
// {
// OverrideGraphicSettings ORGS = new OverrideGraphicSettings();
//ORGS.SetHalftone(true);
//ORGS.SetProjectionLineColor(new Color(0x00, 0x00, 0xFF));
//doc.ActiveView.SetElementOverrides(eid, ORGS);
//}
trans.Commit();
ICollection<ElementId> noneselected = new List<ElementId>();
uidoc.Selection.SetElementIds(noneselected);
uidoc.Selection.Dispose();
}
catch
{
}
}
}
}
catch
{
TaskDialog.Show("Revit C# Error", "Error setting halftone");
}
}
public void EmergencyWiring()
{
//Jan 09/2019 by swr
// program sets line style of emergency wiring to black, lineweight 5, and Center 1/4" line style
//select wires befor running program
UIDocument uidoc = this.ActiveUIDocument; //dont need this
Document doc = this.ActiveUIDocument.Document;
// Get the element selection of current document
Selection selection = uidoc.Selection;
//store element id's
ICollection<ElementId> selectedIds = uidoc.Selection.GetElementIds();
if (0 == selectedIds.Count)
{
IList<Reference> postselected = new List<Reference>();
postselected = uidoc.Selection.PickObjects(ObjectType.Element, "Select wires");
//if (postselected.Count > 0)
foreach (Reference r in postselected)
{
selectedIds.Add(r.ElementId);
}
}
FilteredElementCollector fec = new FilteredElementCollector( doc ).OfClass( typeof( LinePatternElement ) );
LinePatternElement linePatternElem = fec.Cast<LinePatternElement>().First<LinePatternElement>( linePattern => linePattern.Name == @"Center 1/4""");
//TaskDialog.Show("Revit Line Pattern", linePatternElem.Name.ToString());
try
{
using (Transaction trans = new Transaction(doc, "Set EM Wiring Line Style"))
{
trans.Start();
foreach (ElementId eid in selectedIds)
{
Element e = doc.GetElement(eid);
try
{
OverrideGraphicSettings ORGS = new OverrideGraphicSettings();
ORGS.SetHalftone(false);
Color black = new Color(0x00, 0x00, 0x00);
//Color red = new Color(0xFF, 0x00, 0x00);
//Color blue = new Color(0x00, 0x00, 0xFF);
//Color green = new Color(0x00, 0xFF, 0x00);
//ORGS.SetProjectionLineColor(new Color(0x00, 0x00, 0x00));
ORGS.SetProjectionLineColor(black);
ORGS.SetProjectionLinePatternId(linePatternElem.Id);
ORGS.SetProjectionLineWeight(5);
doc.ActiveView.SetElementOverrides(eid, ORGS);
//TaskDialog.Show("Revit", "Set Color");
}
catch
{
TaskDialog.Show("Revit Macro Error", "Error setting line style overrides.");
}
}// end for each
trans.Commit();
}// end using
}// end try
catch
{
TaskDialog.Show("Revit Macro Error", "Error getting element.");
}
ICollection<ElementId> noneselected = new List<ElementId>();
uidoc.Selection.SetElementIds(noneselected);
uidoc.Selection.Dispose();
}// end