mirror of
https://github.com/jeremytammik/RevitSdkSamples.git
synced 2026-08-19 19:53:49 +00:00
replaced Revit 2020 SDK by Revit 2021 SDK
This commit is contained in:
@@ -37,113 +37,123 @@ using RvtView = Autodesk.Revit.DB.View;
|
||||
|
||||
namespace Revit.SDK.Samples.CreateFillPattern.CS
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public partial class PatternForm : System.Windows.Forms.Form
|
||||
{
|
||||
/// <summary>
|
||||
/// Current UI document
|
||||
/// </summary>
|
||||
UIDocument docUI;
|
||||
/// <summary>
|
||||
/// Current revit document
|
||||
/// </summary>
|
||||
Document doc;
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public partial class PatternForm : System.Windows.Forms.Form
|
||||
{
|
||||
/// <summary>
|
||||
/// Current UI document
|
||||
/// </summary>
|
||||
UIDocument docUI;
|
||||
/// <summary>
|
||||
/// Current revit document
|
||||
/// </summary>
|
||||
Document doc;
|
||||
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
public PatternForm(ExternalCommandData commandData)
|
||||
{
|
||||
docUI = commandData.Application.ActiveUIDocument;
|
||||
doc = commandData.Application.ActiveUIDocument.Document;
|
||||
InitializeComponent();
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
public PatternForm(ExternalCommandData commandData)
|
||||
{
|
||||
docUI = commandData.Application.ActiveUIDocument;
|
||||
doc = commandData.Application.ActiveUIDocument.Document;
|
||||
InitializeComponent();
|
||||
|
||||
IniTreeView();
|
||||
}
|
||||
IniTreeView();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Select all elements in current document with specified element type filter
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Target element type</typeparam>
|
||||
/// <returns>List of the elements</returns>
|
||||
private List<T> GetAllElements<T>()
|
||||
{
|
||||
ElementClassFilter elementFilter = new ElementClassFilter(typeof(T));
|
||||
FilteredElementCollector collector = new FilteredElementCollector(doc);
|
||||
collector = collector.WherePasses(elementFilter);
|
||||
return collector.Cast<T>().ToList();
|
||||
}
|
||||
/// <summary>
|
||||
/// Select all elements in current document with specified element type filter
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Target element type</typeparam>
|
||||
/// <returns>List of the elements</returns>
|
||||
private List<T> GetAllElements<T>()
|
||||
{
|
||||
ElementClassFilter elementFilter = new ElementClassFilter(typeof(T));
|
||||
FilteredElementCollector collector = new FilteredElementCollector(doc);
|
||||
collector = collector.WherePasses(elementFilter);
|
||||
return collector.Cast<T>().ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Close the window after close button is clicked
|
||||
/// </summary>
|
||||
/// <param name="sender">This object</param>
|
||||
/// <param name="e">A object contains the event data</param>
|
||||
private void buttonCancel_Click(object sender, EventArgs e)
|
||||
{
|
||||
this.Close();
|
||||
}
|
||||
/// <summary>
|
||||
/// Close the window after close button is clicked
|
||||
/// </summary>
|
||||
/// <param name="sender">This object</param>
|
||||
/// <param name="e">A object contains the event data</param>
|
||||
private void buttonCancel_Click(object sender, EventArgs e)
|
||||
{
|
||||
this.Close();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initial nodes of treeviews
|
||||
/// </summary>
|
||||
private void IniTreeView()
|
||||
{
|
||||
this.treeViewLinePattern.Nodes.Clear();
|
||||
TreeNode iniNode2 = new TreeNode("LinePatterns");
|
||||
treeViewLinePattern.Nodes.Add(iniNode2);
|
||||
/// <summary>
|
||||
/// Initial nodes of treeviews
|
||||
/// </summary>
|
||||
private void IniTreeView()
|
||||
{
|
||||
this.treeViewLinePattern.Nodes.Clear();
|
||||
TreeNode iniNode2 = new TreeNode("LinePatterns");
|
||||
treeViewLinePattern.Nodes.Add(iniNode2);
|
||||
|
||||
List<LinePatternElement> lstLinePatterns = GetAllElements<LinePatternElement>();
|
||||
for (int i = 0; i < lstLinePatterns.Count; i++)
|
||||
{
|
||||
TreeNode node = new TreeNode(lstLinePatterns[i].Name);
|
||||
node.Name = lstLinePatterns[i].Id.IntegerValue.ToString();
|
||||
iniNode2.Nodes.Add(node);
|
||||
}
|
||||
List<LinePatternElement> lstLinePatterns = GetAllElements<LinePatternElement>();
|
||||
for (int i = 0; i < lstLinePatterns.Count; i++)
|
||||
{
|
||||
TreeNode node = new TreeNode(lstLinePatterns[i].Name);
|
||||
node.Name = lstLinePatterns[i].Id.IntegerValue.ToString();
|
||||
iniNode2.Nodes.Add(node);
|
||||
}
|
||||
|
||||
this.treeViewFillPattern.Nodes.Clear();
|
||||
TreeNode iniNode1 = new TreeNode("FillPatterns");
|
||||
treeViewFillPattern.Nodes.Add(iniNode1);
|
||||
this.treeViewFillPattern.Nodes.Clear();
|
||||
TreeNode iniNode1 = new TreeNode("FillPatterns");
|
||||
treeViewFillPattern.Nodes.Add(iniNode1);
|
||||
|
||||
List<FillPatternElement> lstFillPatterns = GetAllElements<FillPatternElement>();
|
||||
for (int i = 0; i < lstFillPatterns.Count; i++)
|
||||
{
|
||||
TreeNode node = new TreeNode(lstFillPatterns[i].Name);
|
||||
node.Name = i.ToString();
|
||||
iniNode1.Nodes.Add(node);
|
||||
}
|
||||
}
|
||||
List<FillPatternElement> lstFillPatterns = GetAllElements<FillPatternElement>();
|
||||
for (int i = 0; i < lstFillPatterns.Count; i++)
|
||||
{
|
||||
TreeNode node = new TreeNode(lstFillPatterns[i].Name);
|
||||
node.Name = i.ToString();
|
||||
iniNode1.Nodes.Add(node);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a fillpattern element
|
||||
/// </summary>
|
||||
/// <param name="patternName">The fillpattern name</param>
|
||||
/// <returns>Created fillpattern element</returns>
|
||||
private FillPatternElement CreateFacePattern(string patternName)
|
||||
{
|
||||
/// <summary>
|
||||
/// Create a fillpattern element
|
||||
/// </summary>
|
||||
/// <param name="patternName">The fillpattern name</param>
|
||||
/// <returns>Created fillpattern element</returns>
|
||||
private FillPatternElement GetOrCreateFacePattern(string patternName)
|
||||
{
|
||||
FillPatternTarget target = FillPatternTarget.Model;
|
||||
FillPatternElement fillPatternElement = FillPatternElement.GetFillPatternElementByName(doc, target, patternName);
|
||||
|
||||
if (fillPatternElement == null)
|
||||
{
|
||||
//Create a fillpattern with specified angle and spacing
|
||||
FillPattern fillPattern = new FillPattern(patternName, FillPatternTarget.Model,
|
||||
FillPattern fillPattern = new FillPattern(patternName, target,
|
||||
FillPatternHostOrientation.ToView, 0.5, 0.5, 0.5);
|
||||
|
||||
Transaction trans = new Transaction(doc);
|
||||
trans.Start("Create a fillpattern element");
|
||||
FillPatternElement fillPatternElement = FillPatternElement.Create(doc, fillPattern);
|
||||
fillPatternElement = FillPatternElement.Create(doc, fillPattern);
|
||||
trans.Commit();
|
||||
return fillPatternElement;
|
||||
}
|
||||
}
|
||||
return fillPatternElement;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a complex fillpattern element
|
||||
/// </summary>
|
||||
/// <param name="patternName">The fillpattern name</param>
|
||||
/// <returns>Created fillpattern element</returns>
|
||||
private FillPatternElement CreateComplexFacePattern(string patternName)
|
||||
{
|
||||
FillPatternElement fillPatternElement = null;
|
||||
/// <summary>
|
||||
/// Create a complex fillpattern element
|
||||
/// </summary>
|
||||
/// <param name="patternName">The fillpattern name</param>
|
||||
/// <returns>Created fillpattern element</returns>
|
||||
private FillPatternElement GetOrCreateComplexFacePattern(string patternName)
|
||||
{
|
||||
FillPatternTarget target = FillPatternTarget.Model;
|
||||
FillPatternElement fillPatternElement = FillPatternElement.GetFillPatternElementByName(doc, target, patternName);
|
||||
|
||||
if (fillPatternElement == null)
|
||||
{
|
||||
// Create the fill pattern
|
||||
FillPattern fillPattern = new FillPattern("API-created", FillPatternTarget.Model,
|
||||
FillPattern fillPattern = new FillPattern(patternName, target,
|
||||
FillPatternHostOrientation.ToHost);
|
||||
|
||||
// Add grids
|
||||
@@ -165,304 +175,306 @@ namespace Revit.SDK.Samples.CreateFillPattern.CS
|
||||
fillPatternElement = FillPatternElement.Create(doc, fillPattern);
|
||||
|
||||
t.Commit();
|
||||
return fillPatternElement;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a fillgrid
|
||||
/// </summary>
|
||||
/// <param name="origin"></param>
|
||||
/// <param name="offset"></param>
|
||||
/// <param name="angle"></param>
|
||||
/// <param name="shift"></param>
|
||||
/// <param name="segments"></param>
|
||||
/// <returns></returns>
|
||||
private FillGrid CreateGrid(UV origin, double offset, double angle,
|
||||
double shift, params double[] segments)
|
||||
{
|
||||
FillGrid fillGrid = new FillGrid();
|
||||
// The arguments: origin, offset (vertical distance between lines),
|
||||
// angle, shift (delta between location of start point per line)
|
||||
// The last two arguments are the segments: e.g. 1.0 units on,
|
||||
// 0.1 units off (units are Revit units (ft))
|
||||
fillGrid.Origin = origin;
|
||||
fillGrid.Offset = offset;
|
||||
fillGrid.Angle = angle;
|
||||
fillGrid.Shift = shift;
|
||||
List<double> segmentsList = new List<double>();
|
||||
foreach (double d in segments)
|
||||
{
|
||||
segmentsList.Add(d);
|
||||
}
|
||||
fillGrid.SetSegments(segmentsList);
|
||||
return fillPatternElement;
|
||||
}
|
||||
|
||||
return fillGrid;
|
||||
}
|
||||
/// <summary>
|
||||
/// Create a fillgrid
|
||||
/// </summary>
|
||||
/// <param name="origin"></param>
|
||||
/// <param name="offset"></param>
|
||||
/// <param name="angle"></param>
|
||||
/// <param name="shift"></param>
|
||||
/// <param name="segments"></param>
|
||||
/// <returns></returns>
|
||||
private FillGrid CreateGrid(UV origin, double offset, double angle,
|
||||
double shift, params double[] segments)
|
||||
{
|
||||
FillGrid fillGrid = new FillGrid();
|
||||
// The arguments: origin, offset (vertical distance between lines),
|
||||
// angle, shift (delta between location of start point per line)
|
||||
// The last two arguments are the segments: e.g. 1.0 units on,
|
||||
// 0.1 units off (units are Revit units (ft))
|
||||
fillGrid.Origin = origin;
|
||||
fillGrid.Offset = offset;
|
||||
fillGrid.Angle = angle;
|
||||
fillGrid.Shift = shift;
|
||||
List<double> segmentsList = new List<double>();
|
||||
foreach (double d in segments)
|
||||
{
|
||||
segmentsList.Add(d);
|
||||
}
|
||||
fillGrid.SetSegments(segmentsList);
|
||||
|
||||
return fillGrid;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Create a linepattern element
|
||||
/// </summary>
|
||||
/// <param name="patternName">The linepattern name</param>
|
||||
/// <returns>Created linepattern element</returns>
|
||||
private LinePatternElement CreateLinePatternElement(string patternName)
|
||||
{
|
||||
//Create list of segments which define the line pattern
|
||||
List<LinePatternSegment> lstSegments = new List<LinePatternSegment>();
|
||||
lstSegments.Add(new LinePatternSegment(LinePatternSegmentType.Dot, 0.0));
|
||||
lstSegments.Add(new LinePatternSegment(LinePatternSegmentType.Space, 0.02));
|
||||
lstSegments.Add(new LinePatternSegment(LinePatternSegmentType.Dash, 0.03));
|
||||
lstSegments.Add(new LinePatternSegment(LinePatternSegmentType.Space, 0.02));
|
||||
/// <summary>
|
||||
/// Create a linepattern element
|
||||
/// </summary>
|
||||
/// <param name="patternName">The linepattern name</param>
|
||||
/// <returns>Created linepattern element</returns>
|
||||
private LinePatternElement CreateLinePatternElement(string patternName)
|
||||
{
|
||||
//Create list of segments which define the line pattern
|
||||
List<LinePatternSegment> lstSegments = new List<LinePatternSegment>();
|
||||
lstSegments.Add(new LinePatternSegment(LinePatternSegmentType.Dot, 0.0));
|
||||
lstSegments.Add(new LinePatternSegment(LinePatternSegmentType.Space, 0.02));
|
||||
lstSegments.Add(new LinePatternSegment(LinePatternSegmentType.Dash, 0.03));
|
||||
lstSegments.Add(new LinePatternSegment(LinePatternSegmentType.Space, 0.02));
|
||||
|
||||
LinePattern linePattern = new LinePattern(patternName);
|
||||
linePattern.SetSegments(lstSegments);
|
||||
LinePattern linePattern = new LinePattern(patternName);
|
||||
linePattern.SetSegments(lstSegments);
|
||||
|
||||
Transaction trans = new Transaction(doc);
|
||||
trans.Start("Create a linepattern element");
|
||||
LinePatternElement linePatternElement = LinePatternElement.Create(doc, linePattern);
|
||||
trans.Commit();
|
||||
return linePatternElement;
|
||||
}
|
||||
Transaction trans = new Transaction(doc);
|
||||
trans.Start("Create a linepattern element");
|
||||
LinePatternElement linePatternElement = LinePatternElement.Create(doc, linePattern);
|
||||
trans.Commit();
|
||||
return linePatternElement;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a fillpattern element and apply it to target material
|
||||
/// </summary>
|
||||
/// <param name="sender">This object</param>
|
||||
/// <param name="e">A object contains the event data</param>
|
||||
private void buttonCreateFillPattern_Click(object sender, EventArgs e)
|
||||
{
|
||||
Wall targetWall = GetSelectedWall();
|
||||
if (targetWall == null)
|
||||
{
|
||||
TaskDialog.Show("Create Fill Pattern",
|
||||
"Before applying FillPattern to a wall's surfaces, you must firstly select a wall.");
|
||||
this.Close();
|
||||
return;
|
||||
}
|
||||
|
||||
FillPatternElement mySurfacePattern = CreateFacePattern("MySurfacePattern");
|
||||
Material targetMaterial = doc.GetElement(targetWall.GetMaterialIds(false).First<ElementId>()) as Material;
|
||||
Transaction trans = new Transaction(doc);
|
||||
trans.Start("Apply fillpattern to surface");
|
||||
targetMaterial.SurfaceForegroundPatternId = mySurfacePattern.Id;
|
||||
trans.Commit();
|
||||
/// <summary>
|
||||
/// Create a fillpattern element and apply it to target material
|
||||
/// </summary>
|
||||
/// <param name="sender">This object</param>
|
||||
/// <param name="e">A object contains the event data</param>
|
||||
private void buttonCreateFillPattern_Click(object sender, EventArgs e)
|
||||
{
|
||||
Wall targetWall = GetSelectedWall();
|
||||
if (targetWall == null)
|
||||
{
|
||||
TaskDialog.Show("Create Fill Pattern",
|
||||
"Before applying a FillPattern to a wall's surfaces, you must first select a wall.");
|
||||
this.Close();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a linepattern element and apply it to grids
|
||||
/// </summary>
|
||||
/// <param name="sender">This object</param>
|
||||
/// <param name="e">A object contains the event data</param>
|
||||
private void buttonCreateLinePattern_Click(object sender, EventArgs e)
|
||||
{
|
||||
List<ElementId> lstGridTypeIds = new List<ElementId>();
|
||||
GetSelectedGridTypeIds(lstGridTypeIds);
|
||||
if (lstGridTypeIds.Count == 0)
|
||||
{
|
||||
TaskDialog.Show("Apply To Grids",
|
||||
"Before applying LinePattern to Grids, you must firstly select at least one grid.");
|
||||
this.Close();
|
||||
return;
|
||||
}
|
||||
FillPatternElement mySurfacePattern = GetOrCreateFacePattern("MySurfacePattern");
|
||||
Material targetMaterial = doc.GetElement(targetWall.GetMaterialIds(false).First<ElementId>()) as Material;
|
||||
Transaction trans = new Transaction(doc);
|
||||
trans.Start("Apply fillpattern to surface");
|
||||
targetMaterial.SurfaceForegroundPatternId = mySurfacePattern.Id;
|
||||
trans.Commit();
|
||||
this.Close();
|
||||
}
|
||||
|
||||
LinePatternElement myLinePatternElement = CreateLinePatternElement("MyLinePattern");
|
||||
foreach (ElementId typeId in lstGridTypeIds)
|
||||
{
|
||||
Element gridType = doc.GetElement(typeId);
|
||||
//set the parameter value of End Segment Pattern
|
||||
SetParameter("End Segment Pattern", myLinePatternElement.Id, gridType);
|
||||
}
|
||||
/// <summary>
|
||||
/// Create a linepattern element and apply it to grids
|
||||
/// </summary>
|
||||
/// <param name="sender">This object</param>
|
||||
/// <param name="e">A object contains the event data</param>
|
||||
private void buttonCreateLinePattern_Click(object sender, EventArgs e)
|
||||
{
|
||||
List<ElementId> lstGridTypeIds = new List<ElementId>();
|
||||
GetSelectedGridTypeIds(lstGridTypeIds);
|
||||
if (lstGridTypeIds.Count == 0)
|
||||
{
|
||||
TaskDialog.Show("Apply To Grids",
|
||||
"Before applying a LinePattern to Grids, you must first select at least one grid.");
|
||||
this.Close();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set a parameter value of a target element
|
||||
/// </summary>
|
||||
/// <param name="paramName">The parameter name</param>
|
||||
/// <param name="eid">Id value of the parameter</param>
|
||||
/// <param name="elem">Target element</param>
|
||||
private void SetParameter(string paramName, ElementId eid, Element elem)
|
||||
{
|
||||
foreach (Parameter param in elem.Parameters)
|
||||
LinePatternElement myLinePatternElement = CreateLinePatternElement("MyLinePattern");
|
||||
foreach (ElementId typeId in lstGridTypeIds)
|
||||
{
|
||||
Element gridType = doc.GetElement(typeId);
|
||||
//set the parameter value of End Segment Pattern
|
||||
SetParameter("End Segment Pattern", myLinePatternElement.Id, gridType);
|
||||
}
|
||||
this.Close();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set a parameter value of a target element
|
||||
/// </summary>
|
||||
/// <param name="paramName">The parameter name</param>
|
||||
/// <param name="eid">Id value of the parameter</param>
|
||||
/// <param name="elem">Target element</param>
|
||||
private void SetParameter(string paramName, ElementId eid, Element elem)
|
||||
{
|
||||
foreach (Parameter param in elem.Parameters)
|
||||
{
|
||||
if (param.Definition.Name == paramName)
|
||||
{
|
||||
if (param.Definition.Name == paramName)
|
||||
{
|
||||
Transaction trans = new Transaction(doc);
|
||||
trans.Start("Set parameter value");
|
||||
param.Set(eid);
|
||||
trans.Commit();
|
||||
break;
|
||||
}
|
||||
Transaction trans = new Transaction(doc);
|
||||
trans.Start("Set parameter value");
|
||||
param.Set(eid);
|
||||
trans.Commit();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Apply fillpattern to surface
|
||||
/// </summary>
|
||||
/// <param name="sender">This object</param>
|
||||
/// <param name="e">A object contains the event data</param>
|
||||
private void buttonApplyToSurface_Click(object sender, EventArgs e)
|
||||
{
|
||||
Wall targetWall = GetSelectedWall();
|
||||
if (targetWall == null)
|
||||
{
|
||||
TaskDialog.Show("Apply To Surface",
|
||||
"Before applying FillPattern to a wall's surfaces, you must firstly select a wall.");
|
||||
this.Close();
|
||||
return;
|
||||
}
|
||||
|
||||
if (treeViewFillPattern.SelectedNode == null || treeViewFillPattern.SelectedNode.Parent == null)
|
||||
{
|
||||
TaskDialog.Show("Apply To Surface",
|
||||
"Before applying FillPattern to a wall's surfaces, you must firstly select one FillPattern.");
|
||||
return;
|
||||
}
|
||||
|
||||
List<FillPatternElement> lstPatterns = GetAllElements<FillPatternElement>();
|
||||
int patternIndex = int.Parse(treeViewFillPattern.SelectedNode.Name);
|
||||
Material targetMaterial = doc.GetElement(targetWall.GetMaterialIds(false).First<ElementId>()) as Material;
|
||||
Transaction trans = new Transaction(doc);
|
||||
trans.Start("Apply fillpattern to surface");
|
||||
targetMaterial.SurfaceForegroundPatternId = lstPatterns[patternIndex].Id;
|
||||
trans.Commit();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Apply fillpattern to surface
|
||||
/// </summary>
|
||||
/// <param name="sender">This object</param>
|
||||
/// <param name="e">A object contains the event data</param>
|
||||
private void buttonApplyToSurface_Click(object sender, EventArgs e)
|
||||
{
|
||||
Wall targetWall = GetSelectedWall();
|
||||
if (targetWall == null)
|
||||
{
|
||||
TaskDialog.Show("Apply To Surface",
|
||||
"Before applying a FillPattern to a wall's surfaces, you must first select a wall.");
|
||||
this.Close();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a selected wall
|
||||
/// </summary>
|
||||
/// <returns>Selected wall</returns>
|
||||
private Wall GetSelectedWall()
|
||||
{
|
||||
Wall wall = null;
|
||||
foreach (ElementId elemId in docUI.Selection.GetElementIds())
|
||||
{
|
||||
Element elem = doc.GetElement(elemId);
|
||||
wall = elem as Wall;
|
||||
if (wall != null)
|
||||
return wall;
|
||||
}
|
||||
return wall;
|
||||
}
|
||||
if (treeViewFillPattern.SelectedNode == null || treeViewFillPattern.SelectedNode.Parent == null)
|
||||
{
|
||||
TaskDialog.Show("Apply To Surface",
|
||||
"Before applying a FillPattern to a wall's surfaces, you must first select one FillPattern.");
|
||||
return;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Apply fillpatterns to cutting surface
|
||||
/// </summary>
|
||||
/// <param name="sender">This object</param>
|
||||
/// <param name="e">A object contains the event data</param>
|
||||
private void buttonApplyToCutSurface_Click(object sender, EventArgs e)
|
||||
{
|
||||
Wall targetWall = GetSelectedWall();
|
||||
if (targetWall == null)
|
||||
{
|
||||
TaskDialog.Show("Apply To CutSurface",
|
||||
"Before applying FillPattern to a wall's cutting surfaces, you must firstly select a wall.");
|
||||
this.Close();
|
||||
return;
|
||||
}
|
||||
List<FillPatternElement> lstPatterns = GetAllElements<FillPatternElement>();
|
||||
int patternIndex = int.Parse(treeViewFillPattern.SelectedNode.Name);
|
||||
Material targetMaterial = doc.GetElement(targetWall.GetMaterialIds(false).First<ElementId>()) as Material;
|
||||
Transaction trans = new Transaction(doc);
|
||||
trans.Start("Apply fillpattern to surface");
|
||||
targetMaterial.SurfaceForegroundPatternId = lstPatterns[patternIndex].Id;
|
||||
trans.Commit();
|
||||
|
||||
if (treeViewFillPattern.SelectedNode == null || treeViewFillPattern.SelectedNode.Parent == null)
|
||||
{
|
||||
TaskDialog.Show("Apply To CutSurface",
|
||||
"Before applying FillPattern to a wall's cutting surfaces, you must firstly select one FillPattern.");
|
||||
return;
|
||||
}
|
||||
this.Close();
|
||||
}
|
||||
|
||||
List<FillPatternElement> lstPatterns = GetAllElements<FillPatternElement>();
|
||||
int patternIndex = int.Parse(treeViewFillPattern.SelectedNode.Name);
|
||||
Material targetMaterial = doc.GetElement(targetWall.GetMaterialIds(false).First<ElementId>()) as Material;
|
||||
|
||||
Transaction trans = new Transaction(doc);
|
||||
trans.Start("Apply fillpattern to cutting surface");
|
||||
targetMaterial.CutForegroundPatternId = lstPatterns[patternIndex].Id;
|
||||
trans.Commit();
|
||||
/// <summary>
|
||||
/// Get a selected wall
|
||||
/// </summary>
|
||||
/// <returns>Selected wall</returns>
|
||||
private Wall GetSelectedWall()
|
||||
{
|
||||
Wall wall = null;
|
||||
foreach (ElementId elemId in docUI.Selection.GetElementIds())
|
||||
{
|
||||
Element elem = doc.GetElement(elemId);
|
||||
wall = elem as Wall;
|
||||
if (wall != null)
|
||||
return wall;
|
||||
}
|
||||
return wall;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Apply fillpatterns to cutting surface
|
||||
/// </summary>
|
||||
/// <param name="sender">This object</param>
|
||||
/// <param name="e">A object contains the event data</param>
|
||||
private void buttonApplyToCutSurface_Click(object sender, EventArgs e)
|
||||
{
|
||||
Wall targetWall = GetSelectedWall();
|
||||
if (targetWall == null)
|
||||
{
|
||||
TaskDialog.Show("Apply To CutSurface",
|
||||
"Before applying a FillPattern to a wall's cut surfaces, you must first select a wall.");
|
||||
this.Close();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Apply linepattern to grids
|
||||
/// </summary>
|
||||
/// <param name="sender">This object</param>
|
||||
/// <param name="e">A object contains the event data</param>
|
||||
private void buttonApplyToGrids_Click(object sender, EventArgs e)
|
||||
{
|
||||
List<ElementId> lstGridTypeIds = new List<ElementId>();
|
||||
GetSelectedGridTypeIds(lstGridTypeIds);
|
||||
if (lstGridTypeIds.Count == 0)
|
||||
{
|
||||
TaskDialog.Show("Apply To Grids",
|
||||
"Before applying LinePattern to Grids, you must firstly select at least one grid.");
|
||||
this.Close();
|
||||
return;
|
||||
}
|
||||
if (treeViewFillPattern.SelectedNode == null || treeViewFillPattern.SelectedNode.Parent == null)
|
||||
{
|
||||
TaskDialog.Show("Apply To CutSurface",
|
||||
"Before applying a FillPattern to a wall's cutting surfaces, you must first select a FillPattern.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (treeViewLinePattern.SelectedNode == null || treeViewLinePattern.Parent == null)
|
||||
{
|
||||
TaskDialog.Show("Apply To Grids",
|
||||
"Before applying LinePattern to Grids, you must firstly select a LinePattern.");
|
||||
return;
|
||||
}
|
||||
ElementId eid = new ElementId(int.Parse(treeViewLinePattern.SelectedNode.Name));
|
||||
foreach (ElementId typeId in lstGridTypeIds)
|
||||
{
|
||||
Element gridType = doc.GetElement(typeId);
|
||||
//set the parameter value of End Segment Pattern
|
||||
SetParameter("End Segment Pattern", eid, gridType);
|
||||
}
|
||||
List<FillPatternElement> lstPatterns = GetAllElements<FillPatternElement>();
|
||||
int patternIndex = int.Parse(treeViewFillPattern.SelectedNode.Name);
|
||||
Material targetMaterial = doc.GetElement(targetWall.GetMaterialIds(false).First<ElementId>()) as Material;
|
||||
|
||||
Transaction trans = new Transaction(doc);
|
||||
trans.Start("Apply fillpattern to cutting surface");
|
||||
targetMaterial.CutForegroundPatternId = lstPatterns[patternIndex].Id;
|
||||
trans.Commit();
|
||||
|
||||
this.Close();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Apply linepattern to grids
|
||||
/// </summary>
|
||||
/// <param name="sender">This object</param>
|
||||
/// <param name="e">A object contains the event data</param>
|
||||
private void buttonApplyToGrids_Click(object sender, EventArgs e)
|
||||
{
|
||||
List<ElementId> lstGridTypeIds = new List<ElementId>();
|
||||
GetSelectedGridTypeIds(lstGridTypeIds);
|
||||
if (lstGridTypeIds.Count == 0)
|
||||
{
|
||||
TaskDialog.Show("Apply To Grids",
|
||||
"Before applying a LinePattern to Grids, you must first select at least one grid.");
|
||||
this.Close();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get selected GridType Ids
|
||||
/// </summary>
|
||||
/// <param name="lstGridTypeIds">Selected GridType Ids</param>
|
||||
private void GetSelectedGridTypeIds(List<ElementId> lstGridTypeIds)
|
||||
{
|
||||
foreach (ElementId elemId in docUI.Selection.GetElementIds())
|
||||
{
|
||||
Element elem = doc.GetElement(elemId);
|
||||
Grid grid = elem as Grid;
|
||||
if (grid != null)
|
||||
{
|
||||
ElementId gridTypeId = grid.GetTypeId();
|
||||
if (!lstGridTypeIds.Contains(gridTypeId))
|
||||
lstGridTypeIds.Add(gridTypeId);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (treeViewLinePattern.SelectedNode == null || treeViewLinePattern.Parent == null)
|
||||
{
|
||||
TaskDialog.Show("Apply To Grids",
|
||||
"Before applying a LinePattern to Grids, you must first select a LinePattern.");
|
||||
return;
|
||||
}
|
||||
ElementId eid = new ElementId(int.Parse(treeViewLinePattern.SelectedNode.Name));
|
||||
foreach (ElementId typeId in lstGridTypeIds)
|
||||
{
|
||||
Element gridType = doc.GetElement(typeId);
|
||||
//set the parameter value of End Segment Pattern
|
||||
SetParameter("End Segment Pattern", eid, gridType);
|
||||
}
|
||||
this.Close();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// To create a brick-like patternss
|
||||
/// </summary>
|
||||
/// <param name="sender">This object</param>
|
||||
/// <param name="e">A object contains the event data</param>
|
||||
private void buttonCreateComplexFillPattern_Click(object sender, EventArgs e)
|
||||
{
|
||||
Wall targetWall = GetSelectedWall();
|
||||
if (targetWall == null)
|
||||
/// <summary>
|
||||
/// Get selected GridType Ids
|
||||
/// </summary>
|
||||
/// <param name="lstGridTypeIds">Selected GridType Ids</param>
|
||||
private void GetSelectedGridTypeIds(List<ElementId> lstGridTypeIds)
|
||||
{
|
||||
foreach (ElementId elemId in docUI.Selection.GetElementIds())
|
||||
{
|
||||
Element elem = doc.GetElement(elemId);
|
||||
Grid grid = elem as Grid;
|
||||
if (grid != null)
|
||||
{
|
||||
TaskDialog.Show("Create Fill Pattern",
|
||||
"Before applying FillPattern to a wall's surfaces, you must firstly select a wall.");
|
||||
this.Close();
|
||||
return;
|
||||
ElementId gridTypeId = grid.GetTypeId();
|
||||
if (!lstGridTypeIds.Contains(gridTypeId))
|
||||
lstGridTypeIds.Add(gridTypeId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FillPatternElement mySurfacePattern = CreateComplexFacePattern("MyComplexPattern");
|
||||
Material targetMaterial = doc.GetElement(targetWall.GetMaterialIds(false).First<ElementId>()) as Material;
|
||||
Transaction trans = new Transaction(doc);
|
||||
trans.Start("Apply complex fillpattern to surface");
|
||||
targetMaterial.SurfaceForegroundPatternId = mySurfacePattern.Id;
|
||||
trans.Commit();
|
||||
/// <summary>
|
||||
/// To create a brick-like patternss
|
||||
/// </summary>
|
||||
/// <param name="sender">This object</param>
|
||||
/// <param name="e">A object contains the event data</param>
|
||||
private void buttonCreateComplexFillPattern_Click(object sender, EventArgs e)
|
||||
{
|
||||
Wall targetWall = GetSelectedWall();
|
||||
if (targetWall == null)
|
||||
{
|
||||
TaskDialog.Show("Create Fill Pattern",
|
||||
"Before applying a FillPattern to a wall's surfaces, you must first select a wall.");
|
||||
this.Close();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
private void PatternForm_Load(object sender, EventArgs e)
|
||||
{
|
||||
FillPatternElement mySurfacePattern = GetOrCreateComplexFacePattern("MyComplexPattern");
|
||||
Material targetMaterial = doc.GetElement(targetWall.GetMaterialIds(false).First<ElementId>()) as Material;
|
||||
Transaction trans = new Transaction(doc);
|
||||
trans.Start("Apply complex fillpattern to surface");
|
||||
targetMaterial.SurfaceForegroundPatternId = mySurfacePattern.Id;
|
||||
trans.Commit();
|
||||
this.Close();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
private void PatternForm_Load(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user