Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Element.cs #1

Open
wants to merge 1 commit into
base: Revit2015
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion src/Libraries/RevitNodes/Elements/Element.cs
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ public object GetParameterValueByName(string parameterName)
/// <summary>
/// Override the element's color in the active view.
/// </summary>
/// <param name="color">The color to apply to a solid fill on the element.</param>
/// <param name="color">The color to apply to a solid fill and projection lines on the element.</param>
public Element OverrideColorInView(Color color)
{
TransactionManager.Instance.EnsureInTransaction(DocumentManager.Instance.CurrentDBDocument);
Expand All @@ -398,7 +398,47 @@ public Element OverrideColorInView(Color color)
TransactionManager.Instance.TransactionTaskDone();
return this;
}

/// <summary>
/// Override only the element's surface color in the active view.
/// </summary>
/// <param name="color">The color to apply to a solid fill on the element.</param>
public Element OverrideSurfaceColorInView(Color color)
{
TransactionManager.Instance.EnsureInTransaction(DocumentManager.Instance.CurrentDBDocument);

var view = DocumentManager.Instance.CurrentUIDocument.ActiveView;
var ogs = view.GetElementOverrides(InternalElementId);

var patternCollector = new FilteredElementCollector(DocumentManager.Instance.CurrentDBDocument);
patternCollector.OfClass(typeof(FillPatternElement));
FillPatternElement solidFill = patternCollector.ToElements().Cast<FillPatternElement>().First(x => x.GetFillPattern().IsSolidFill);

var overrideColor = new Autodesk.Revit.DB.Color(color.Red, color.Green, color.Blue);
ogs.SetProjectionFillColor(overrideColor);
ogs.SetProjectionFillPatternId(solidFill.Id);
view.SetElementOverrides(InternalElementId, ogs);

TransactionManager.Instance.TransactionTaskDone();
return this;
}

/// <summary>
/// Reset the element's overrides in the active view.
/// </summary>
public void ResetViewOverrides()
{
TransactionManager.Instance.EnsureInTransaction(DocumentManager.Instance.CurrentDBDocument);

var view = DocumentManager.Instance.CurrentUIDocument.ActiveView;

var ogs = new OverrideGraphicSettings();

view.SetElementOverrides(InternalElementId, ogs);

TransactionManager.Instance.TransactionTaskDone();
}

/// <summary>
/// Set one of the element's parameters.
/// </summary>
Expand Down