应用程序名称: GridCreation
Revit 平台: 所有版本
Revit 版本: 2011.0
首次发布版本: 2009.0
编程语言: C#
技能要求: 高级水平
类别: 元素
类型: ExternalCommand
主题: 创建网格。
概要:
这个示例展示了如何通过 Revit API 创建网格并修改网格的属性。
类:
Autodesk.Revit.UI.IExternalCommand
Autodesk.Revit.DB
项目文件:
Command.cs
包含类 Command,该类继承自接口 IExternalCommand,并实现了 Execute 方法。
CreateGridsData.cs
网格创建数据类的基类,包含了共同的数据和操作。
GridCreationOptionData.cs
数据类,存储创建网格的方法信息。
GridCreationOptionForm.cs
包含对话框,允许用户选择创建网格的方式。
CreateWithSeletedCurvesData.cs
存储使用选择的线/弧创建网格的信息的数据类。
CreateWithSelectedCurvesForm.cs
包含对话框,提供使用选择的线/弧创建网格的选项。
CreateOrthogonalGridsData.cs
存储创建正交网格信息的数据类。
CreateOrthogonalGridsForm.cs
包含对话框,提供创建正交网格的选项。
CreateRadialAndArcGridsData.cs
存储创建径向和弧形网格的信息的数据类。
CreateRadialAndArcGridsForm.cs
包含对话框,提供创建径向和弧形网格的选项。
Unit.cs
定义了一个静态类 Unit,用于将显示单位类型转换为 Revit API 的内部单位。
EnumsAndValues.cs
该文件包含两个枚举和一个类。
- CreateMode 枚举列出创建网格的方式。
- BubbleLocation 枚举列出了网格的注释位置。
- Class Values 包含在度和弧度之间转换时使用的常量值。
Validation.cs
该文件包含用于在创建网格之前验证输入数据的静态函数。
描述:
该示例提供以下功能:
- 让用户在选定的线/弧线基础上创建网格。
- 允许用户生成具有指定原点、X 方向和 Y 方向间距、X 和 Y 方向网格数的正交线性网格。
- 允许用户生成具有指定中心、网格跨度、同心圆弧之间间距和指定网格跨度中的射线数量等信息的径向和弧形网格。甚至用户可以指定第一个弧形网格的半径和从中心到径向网格起始点的距离。
- 允许用户设置第一个网格的标签,如 A 或 1,并设置要创建的网格的泡位置。
- UI 中的长度单位应与当前项目单位设置相符。
说明:
打开 Revit 应用程序并执行以下命令。
1. 使用选定的线/弧线创建网格。
a. 在当前项目中选择一些线/弧线。
b. 执行命令。
c. 选中选项 “使用选定的线或弧度创建网格”。
d. 在下一个“使用选定线/弧创建网格”对话框中指定值并单击“创建网格”按钮。
预期结果: 网格会基于选定的线/弧线生成。如果弧是圆形,则会分别为圆形的上部和下部创建两个网格。
2. 创建正交网格。
a. 执行命令。
b. 选中选项“创建一批正交网格”。
c. 在下一个“创建正交网格”对话框中指定值并单击“创建网格”按钮。
预期结果: 根据指定的值创建正交网格。
3. 创建径向和弧形网格。
a. 执行命令。
b. 选中选项“创建一批径向和弧形网格”。
c. 在下一个“创建径向和弧形网格”对话框中指定值并单击“创建网格”按钮。
预期结果: 根据指定的值创建径向和弧形网格。
源代码
完整的源代码请加入QQ群649037449,在群文件中下载RevitSDK.exe,解压后在文件夹中搜索本文中应用程序名称即可获得完整源码
CreateGridsData.cs
//
// (C) Copyright 2003-2019 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Windows.Forms;
using Autodesk.Revit;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Application = Autodesk.Revit.ApplicationServices.Application;
namespace Revit.SDK.Samples.GridCreation.CS
{
/// <summary>
/// Base class of all grid creation data class
/// </summary>
public class CreateGridsData
{
#region Fields
/// <summary>
/// The active document of Revit
/// </summary>
protected Autodesk.Revit.DB.Document m_revitDoc;
/// <summary>
/// Document Creation object to create new elements
/// </summary>
protected Autodesk.Revit.Creation.Document m_docCreator;
/// <summary>
/// Application Creation object to create new elements
/// </summary>
protected Autodesk.Revit.Creation.Application m_appCreator;
/// <summary>
/// Array list contains all grid labels in current document
/// </summary>
private ArrayList m_labelsList;
/// <summary>
/// Current display unit type
/// </summary>
protected DisplayUnitType m_dut;
/// <summary>
/// Resource manager
/// </summary>
protected static System.Resources.ResourceManager resManager = Properties.Resources.ResourceManager;
#endregion
#region Properties
/// <summary>
/// Current display unit type
/// </summary>
public DisplayUnitType Dut
{
get
{
return m_dut;
}
}
/// <summary>
/// Get array list contains all grid labels in current document
/// </summary>
public ArrayList LabelsList
{
get
{
return m_labelsList;
}
}
#endregion
#region Methods
/// <summary>
/// Constructor without display unit type
/// </summary>
/// <param name="application">Revit application</param>
/// <param name="labels">All existing labels in Revit's document</param>
public CreateGridsData(UIApplication application, ArrayList labels)
{
m_revitDoc = application.ActiveUIDocument.Document;
m_appCreator = application.Application.Create;
m_docCreator = application.ActiveUIDocument.Document.Create;
m_labelsList = labels;
}
/// <summary>
/// Constructor with display unit type
/// </summary>
/// <param name="application">Revit application</param>
/// <param name="labels">All existing labels in Revit's document</param>
/// <param name="dut">Current length display unit type</param>
public CreateGridsData(UIApplication application, ArrayList labels, DisplayUnitType dut)
{
m_revitDoc = application.ActiveUIDocument.Document;
m_appCreator = application.Application.Create;
m_docCreator = application.ActiveUIDocument.Document.Create;
m_labelsList = labels;
m_dut = dut;
}
/// <summary>
/// Get the line to create grid according to the specified bubble location
/// </summary>
/// <param name="line">The original selected line</param>
/// <param name="bubLoc">bubble location</param>
/// <returns>The line to create grid</returns>
protected Line TransformLine(Line line, BubbleLocation bubLoc)
{
Line lineToCreate;
// Create grid according to the bubble location
if (bubLoc == BubbleLocation.StartPoint)
{
lineToCreate = line;
}
else
{
Autodesk.Revit.DB.XYZ startPoint = line.GetEndPoint(1);
Autodesk.Revit.DB.XYZ endPoint = line.GetEndPoint(0);
lineToCreate = NewLine(startPoint, endPoint);
}
return lineToCreate;
}
/// <summary>
/// Get the arc to create grid according to the specified bubble location
/// </summary>
/// <param name="arc">The original selected line</param>
/// <param name="bubLoc">bubble location</param>
/// <returns>The arc to create grid</returns>
protected Arc TransformArc(Arc arc, BubbleLocation bubLoc)
{
Arc arcToCreate;
if (bubLoc == BubbleLocation.StartPoint)
{
arcToCreate = arc;
}
else
{
// Get start point, end point of the arc and the middle point on it
Autodesk.Revit.DB.XYZ startPoint = arc.GetEndPoint(0);
Autodesk.Revit.DB.XYZ endPoint = arc.GetEndPoint(1);
bool clockwise = (arc.Normal.Z == -1);
// Get start angel and end angel of arc
double startDegree = arc.GetEndParameter(0);
double endDegree = arc.GetEndParameter(1);
// Handle the case that the arc is clockwise
if (clockwise && startDegree > 0 && endDegree > 0)
{
startDegree = 2 * Values.PI - startDegree;
endDegree = 2 * Values.PI - endDegree;
}
else if (clockwise && startDegree < 0)
{
double temp = endDegree;
endDegree = -1 * startDegree;
startDegree = -1 * temp;
}
double sumDegree = (startDegree + endDegree) / 2;
while (sumDegree > 2 * Values.PI)
{
sumDegree -= 2 * Values.PI;
}
while (sumDegree < -2 * Values.PI)
{
sumDegree += 2 * Values.PI;
}
Autodesk.Revit.DB.XYZ midPoint = new Autodesk.Revit.DB.XYZ(arc.Center.X + arc.Radius * Math.Cos(sumDegree),
arc.Center.Y + arc.Radius * Math.Sin(sumDegree), 0);
arcToCreate = Arc.Create(endPoint, startPoint, midPoint);
}
return arcToCreate;
}
/// <summary>
/// Get the arc to create grid according to the specified bubble location
/// </summary>
/// <param name="origin">Arc grid's origin</param>
/// <param name="radius">Arc grid's radius</param>
/// <param name="startDegree">Arc grid's start degree</param>
/// <param name="endDegree">Arc grid's end degree</param>
/// <param name="bubLoc">Arc grid's Bubble location</param>
/// <returns>The expected arc to create grid</returns>
protected Arc TransformArc(Autodesk.Revit.DB.XYZ origin, double radius, double startDegree, double endDegree,
BubbleLocation bubLoc)
{
Arc arcToCreate;
// Get start point and end point of the arc and the middle point on the arc
Autodesk.Revit.DB.XYZ startPoint = new Autodesk.Revit.DB.XYZ(origin.X + radius * Math.Cos(startDegree),
origin.Y + radius * Math.Sin(startDegree), origin.Z);
Autodesk.Revit.DB.XYZ midPoint = new Autodesk.Revit.DB.XYZ(origin.X + radius * Math.Cos((startDegree + endDegree) / 2),
origin.Y + radius * Math.Sin((startDegree + endDegree) / 2), origin.Z);
Autodesk.Revit.DB.XYZ endPoint = new Autodesk.Revit.DB.XYZ(origin.X + radius * Math.Cos(endDegree),
origin.Y + radius * Math.Sin(endDegree), origin.Z);
if (bubLoc == BubbleLocation.StartPoint)
{
arcToCreate = Arc.Create(startPoint, endPoint, midPoint);
}
else
{
arcToCreate = Arc.Create(endPoint, startPoint, midPoint);
}
return arcToCreate;
}
/// <summary>
/// Split a circle into the upper and lower parts
/// </summary>
/// <param name="arc">Arc to be split</param>
/// <param name="upperArc">Upper arc of the circle</param>
/// <param name="lowerArc">Lower arc of the circle</param>
/// <param name="bubLoc">bubble location</param>
protected void TransformCircle(Arc arc, ref Arc upperArc, ref Arc lowerArc, BubbleLocation bubLoc)
{
Autodesk.Revit.DB.XYZ center = arc.Center;
double radius = arc.Radius;
Autodesk.Revit.DB.XYZ XRightPoint = new Autodesk.Revit.DB.XYZ(center.X + radius, center.Y, 0);
Autodesk.Revit.DB.XYZ XLeftPoint = new Autodesk.Revit.DB.XYZ(center.X - radius, center.Y, 0);
Autodesk.Revit.DB.XYZ YUpperPoint = new Autodesk.Revit.DB.XYZ(center.X, center.Y + radius, 0);
Autodesk.Revit.DB.XYZ YLowerPoint = new Autodesk.Revit.DB.XYZ(center.X, center.Y - radius, 0);
if (bubLoc == BubbleLocation.StartPoint)
{
upperArc = Arc.Create(XRightPoint, XLeftPoint, YUpperPoint);
lowerArc = Arc.Create(XLeftPoint, XRightPoint, YLowerPoint);
}
else
{
upperArc = Arc.Create(XLeftPoint, XRightPoint, YUpperPoint);
lowerArc = Arc.Create(XRightPoint, XLeftPoint, YLowerPoint);
}
}
/// <summary>
/// Create a new bound line
/// </summary>
/// <param name="start">start point of line</param>
/// <param name="end">end point of line</param>
/// <returns></returns>
protected Line NewLine(Autodesk.Revit.DB.XYZ start, Autodesk.Revit.DB.XYZ end)
{
return Line.CreateBound(start, end);
}
/// <summary>
/// Create a grid with a line
/// </summary>
/// <param name="line">Line to create grid</param>
/// <returns>Newly created grid</returns>
protected Grid NewGrid(Line line)
{
return Grid.Create(m_revitDoc, line);
}
/// <summary>
/// Create a grid with an arc
/// </summary>
/// <param name="arc">Arc to create grid</param>
/// <returns>Newly created grid</returns>
protected Grid NewGrid(Arc arc)
{
return Grid.Create(m_revitDoc, arc);
}
/// <summary>
/// Create linear grid
/// </summary>
/// <param name="line">The linear curve to be transferred to grid</param>
/// <returns>The newly created grid</returns>
///
protected Grid CreateLinearGrid(Line line)
{
return Grid.Create(m_revitDoc, line);
}
/// <summary>
/// Create batch of grids with curves
/// </summary>
/// <param name="curves">Curves used to create grids</param>
protected void CreateGrids(CurveArray curves)
{
foreach (Curve c in curves)
{
Line line = c as Line;
Arc arc = c as Arc;
if (line != null)
{
Grid.Create(m_revitDoc, line);
}
if (arc != null)
{
Grid.Create(m_revitDoc, arc);
}
}
}
/// <summary>
/// Add curve to curve array for batch creation
/// </summary>
/// <param name="curves">curve array stores all curves for batch creation</param>
/// <param name="curve">curve to be added</param>
public static void AddCurveForBatchCreation(ref CurveArray curves, Curve curve)
{
curves.Append(curve);
}
/// <summary>
/// Show a message box
/// </summary>
/// <param name="message">Message</param>
/// <param name="caption">title of message box</param>
public static void ShowMessage(String message, String caption)
{
TaskDialog.Show(caption, message, TaskDialogCommonButtons.Ok);
}
#endregion
}
}
GridCreationOptionData.cs
//
// (C) Copyright 2003-2019 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
using System;
using System.Collections.Generic;
using System.Text;
using Autodesk.Revit;
using Autodesk.Revit.DB;
namespace Revit.SDK.Samples.GridCreation.CS
{
/// <summary>
/// Data class which stores the information of the way to create grids
/// </summary>
public class GridCreationOptionData
{
#region Fields
// The way to create grids
private CreateMode m_createGridsMode;
// If lines/arcs have been selected
private bool m_hasSelectedLinesOrArcs;
#endregion
#region Properties
/// <summary>
/// Creating mode
/// </summary>
public CreateMode CreateGridsMode
{
get
{
return m_createGridsMode;
}
set
{
m_createGridsMode = value;
}
}
/// <summary>
/// State whether lines/arcs have been selected
/// </summary>
public bool HasSelectedLinesOrArcs
{
get
{
return m_hasSelectedLinesOrArcs;
}
}
#endregion
#region Methods
/// <summary>
/// Constructor
/// </summary>
/// <param name="hasSelectedLinesOrArcs">Whether lines or arcs have been selected</param>
public GridCreationOptionData(bool hasSelectedLinesOrArcs)
{
m_hasSelectedLinesOrArcs = hasSelectedLinesOrArcs;
}
#endregion
}
}
GridCreationOptionForm.cs
//
// (C) Copyright 2003-2019 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
namespace Revit.SDK.Samples.GridCreation.CS
{
partial class CreateOrthogonalGridsForm
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.labelYCoordUnit = new System.Windows.Forms.Label();
this.labelXCoordUnit = new System.Windows.Forms.Label();
this.textBoxYCoord = new System.Windows.Forms.TextBox();
this.textBoxXCoord = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.textBoxYNumber = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.textBoxXNumber = new System.Windows.Forms.TextBox();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.labelUnitY = new System.Windows.Forms.Label();
this.textBoxYSpacing = new System.Windows.Forms.TextBox();
this.textBoxYFirstLabel = new System.Windows.Forms.TextBox();
this.comboBoxYBubbleLocation = new System.Windows.Forms.ComboBox();
this.label10 = new System.Windows.Forms.Label();
this.label5 = new System.Windows.Forms.Label();
this.label9 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.groupBox3 = new System.Windows.Forms.GroupBox();
this.labelUnitX = new System.Windows.Forms.Label();
this.textBoxXSpacing = new System.Windows.Forms.TextBox();
this.textBoxXFirstLabel = new System.Windows.Forms.TextBox();
this.comboBoxXBubbleLocation = new System.Windows.Forms.ComboBox();
this.label6 = new System.Windows.Forms.Label();
this.label7 = new System.Windows.Forms.Label();
this.label8 = new System.Windows.Forms.Label();
this.buttonCreate = new System.Windows.Forms.Button();
this.buttonCancel = new System.Windows.Forms.Button();
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
this.groupBox3.SuspendLayout();
this.SuspendLayout();
//
// groupBox1
//
this.groupBox1.Controls.Add(this.labelYCoordUnit);
this.groupBox1.Controls.Add(this.labelXCoordUnit);
this.groupBox1.Controls.Add(this.textBoxYCoord);
this.groupBox1.Controls.Add(this.textBoxXCoord);
this.groupBox1.Controls.Add(this.label2);
this.groupBox1.Controls.Add(this.label1);
this.groupBox1.Location = new System.Drawing.Point(13, 12);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(520, 55);
this.groupBox1.TabIndex = 0;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Origin of the Grids";
//
// labelYCoordUnit
//
this.labelYCoordUnit.Location = new System.Drawing.Point(484, 23);
this.labelYCoordUnit.Name = "labelYCoordUnit";
this.labelYCoordUnit.Size = new System.Drawing.Size(23, 13);
this.labelYCoordUnit.TabIndex = 7;
//
// labelXCoordUnit
//
this.labelXCoordUnit.Location = new System.Drawing.Point(227, 23);
this.labelXCoordUnit.Name = "labelXCoordUnit";
this.labelXCoordUnit.Size = new System.Drawing.Size(23, 13);
this.labelXCoordUnit.TabIndex = 7;
//
// textBoxYCoord
//
this.textBoxYCoord.Location = new System.Drawing.Point(385, 20);
this.textBoxYCoord.Name = "textBoxYCoord";
this.textBoxYCoord.Size = new System.Drawing.Size(98, 20);
this.textBoxYCoord.TabIndex = 1;
this.textBoxYCoord.Tag = "0";
this.textBoxYCoord.Text = "0";
//
// textBoxXCoord
//
this.textBoxXCoord.Location = new System.Drawing.Point(109, 20);
this.textBoxXCoord.Name = "textBoxXCoord";
this.textBoxXCoord.Size = new System.Drawing.Size(112, 20);
this.textBoxXCoord.TabIndex = 0;
this.textBoxXCoord.Tag = "0";
this.textBoxXCoord.Text = "0";
//
// label2
//
this.label2.Location = new System.Drawing.Point(261, 24);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(122, 13);
this.label2.TabIndex = 0;
this.label2.Text = "Y coordinate:";
//
// label1
//
this.label1.Location = new System.Drawing.Point(7, 24);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(95, 13);
this.label1.TabIndex = 0;
this.label1.Text = "X coordinate:";
//
// textBoxYNumber
//
this.textBoxYNumber.Location = new System.Drawing.Point(385, 24);
this.textBoxYNumber.Name = "textBoxYNumber";
this.textBoxYNumber.Size = new System.Drawing.Size(120, 20);
this.textBoxYNumber.TabIndex = 1;
this.textBoxYNumber.Tag = "3";
this.textBoxYNumber.Text = "3";
//
// label3
//
this.label3.Location = new System.Drawing.Point(261, 27);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(122, 13);
this.label3.TabIndex = 7;
this.label3.Text = "Number:";
//
// textBoxXNumber
//
this.textBoxXNumber.Location = new System.Drawing.Point(385, 23);
this.textBoxXNumber.Name = "textBoxXNumber";
this.textBoxXNumber.Size = new System.Drawing.Size(120, 20);
this.textBoxXNumber.TabIndex = 1;
this.textBoxXNumber.Tag = "3";
this.textBoxXNumber.Text = "3";
//
// groupBox2
//
this.groupBox2.Controls.Add(this.labelUnitY);
this.groupBox2.Controls.Add(this.textBoxYNumber);
this.groupBox2.Controls.Add(this.textBoxYSpacing);
this.groupBox2.Controls.Add(this.textBoxYFirstLabel);
this.groupBox2.Controls.Add(this.label3);
this.groupBox2.Controls.Add(this.comboBoxYBubbleLocation);
this.groupBox2.Controls.Add(this.label10);
this.groupBox2.Controls.Add(this.label5);
this.groupBox2.Controls.Add(this.label9);
this.groupBox2.Location = new System.Drawing.Point(14, 165);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(519, 85);
this.groupBox2.TabIndex = 2;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "Y direction Grids";
//
// labelUnitY
//
this.labelUnitY.Location = new System.Drawing.Point(227, 26);
this.labelUnitY.Name = "labelUnitY";
this.labelUnitY.Size = new System.Drawing.Size(23, 13);
this.labelUnitY.TabIndex = 7;
//
// textBoxYSpacing
//
this.textBoxYSpacing.Location = new System.Drawing.Point(110, 24);
this.textBoxYSpacing.Name = "textBoxYSpacing";
this.textBoxYSpacing.Size = new System.Drawing.Size(112, 20);
this.textBoxYSpacing.TabIndex = 0;
this.textBoxYSpacing.Tag = "10.0";
this.textBoxYSpacing.Text = 10.0.ToString("0.0");
//
// textBoxYFirstLabel
//
this.textBoxYFirstLabel.Location = new System.Drawing.Point(385, 53);
this.textBoxYFirstLabel.Name = "textBoxYFirstLabel";
this.textBoxYFirstLabel.Size = new System.Drawing.Size(120, 20);
this.textBoxYFirstLabel.TabIndex = 3;
this.textBoxYFirstLabel.Tag = "A";
this.textBoxYFirstLabel.Text = "A";
//
// comboBoxYBubbleLocation
//
this.comboBoxYBubbleLocation.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxYBubbleLocation.FormattingEnabled = true;
this.comboBoxYBubbleLocation.Items.AddRange(new object[] {
"At start point of lines",
"At end point of lines"});
this.comboBoxYBubbleLocation.Location = new System.Drawing.Point(108, 53);
this.comboBoxYBubbleLocation.Name = "comboBoxYBubbleLocation";
this.comboBoxYBubbleLocation.Size = new System.Drawing.Size(146, 21);
this.comboBoxYBubbleLocation.TabIndex = 2;
//
// label10
//
this.label10.Location = new System.Drawing.Point(7, 55);
this.label10.Name = "label10";
this.label10.Size = new System.Drawing.Size(95, 13);
this.label10.TabIndex = 6;
this.label10.Text = "Bubble location:";
//
// label5
//
this.label5.Location = new System.Drawing.Point(6, 26);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(95, 13);
this.label5.TabIndex = 7;
this.label5.Text = "Spacing:";
//
// label9
//
this.label9.Location = new System.Drawing.Point(261, 55);
this.label9.Name = "label9";
this.label9.Size = new System.Drawing.Size(122, 13);
this.label9.TabIndex = 6;
this.label9.Text = "Label of first grid:";
//
// label4
//
this.label4.Location = new System.Drawing.Point(261, 26);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(122, 13);
this.label4.TabIndex = 6;
this.label4.Text = "Number:";
//
// groupBox3
//
this.groupBox3.Controls.Add(this.labelUnitX);
this.groupBox3.Controls.Add(this.textBoxXNumber);
this.groupBox3.Controls.Add(this.textBoxXSpacing);
this.groupBox3.Controls.Add(this.textBoxXFirstLabel);
this.groupBox3.Controls.Add(this.comboBoxXBubbleLocation);
this.groupBox3.Controls.Add(this.label6);
this.groupBox3.Controls.Add(this.label7);
this.groupBox3.Controls.Add(this.label4);
this.groupBox3.Controls.Add(this.label8);
this.groupBox3.Location = new System.Drawing.Point(13, 73);
this.groupBox3.Name = "groupBox3";
this.groupBox3.Size = new System.Drawing.Size(520, 86);
this.groupBox3.TabIndex = 1;
this.groupBox3.TabStop = false;
this.groupBox3.Text = "X direction Grids";
//
// labelUnitX
//
this.labelUnitX.Location = new System.Drawing.Point(227, 25);
this.labelUnitX.Name = "labelUnitX";
this.labelUnitX.Size = new System.Drawing.Size(23, 13);
this.labelUnitX.TabIndex = 7;
//
// textBoxXSpacing
//
this.textBoxXSpacing.Location = new System.Drawing.Point(109, 23);
this.textBoxXSpacing.Name = "textBoxXSpacing";
this.textBoxXSpacing.Size = new System.Drawing.Size(112, 20);
this.textBoxXSpacing.TabIndex = 0;
this.textBoxXSpacing.Tag = "10.0";
this.textBoxXSpacing.Text = 10.0.ToString("0.0");
//
// textBoxXFirstLabel
//
this.textBoxXFirstLabel.Location = new System.Drawing.Point(385, 53);
this.textBoxXFirstLabel.Name = "textBoxXFirstLabel";
this.textBoxXFirstLabel.Size = new System.Drawing.Size(120, 20);
this.textBoxXFirstLabel.TabIndex = 3;
this.textBoxXFirstLabel.Tag = "";
this.textBoxXFirstLabel.Text = "1";
//
// comboBoxXBubbleLocation
//
this.comboBoxXBubbleLocation.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxXBubbleLocation.FormattingEnabled = true;
this.comboBoxXBubbleLocation.Items.AddRange(new object[] {
"At start point of lines",
"At end point of lines"});
this.comboBoxXBubbleLocation.Location = new System.Drawing.Point(108, 53);
this.comboBoxXBubbleLocation.Name = "comboBoxXBubbleLocation";
this.comboBoxXBubbleLocation.Size = new System.Drawing.Size(147, 21);
this.comboBoxXBubbleLocation.TabIndex = 2;
//
// label6
//
this.label6.Location = new System.Drawing.Point(7, 25);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(95, 13);
this.label6.TabIndex = 6;
this.label6.Text = "Spacing:";
//
// label7
//
this.label7.Location = new System.Drawing.Point(7, 55);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(95, 13);
this.label7.TabIndex = 6;
this.label7.Text = "Bubble location:";
//
// label8
//
this.label8.Location = new System.Drawing.Point(261, 55);
this.label8.Name = "label8";
this.label8.Size = new System.Drawing.Size(122, 13);
this.label8.TabIndex = 6;
this.label8.Text = "Label of first grid:";
//
// buttonCreate
//
this.buttonCreate.DialogResult = System.Windows.Forms.DialogResult.OK;
this.buttonCreate.Location = new System.Drawing.Point(327, 269);
this.buttonCreate.Name = "buttonCreate";
this.buttonCreate.Size = new System.Drawing.Size(94, 23);
this.buttonCreate.TabIndex = 3;
this.buttonCreate.Text = "Create &Grids";
this.buttonCreate.UseVisualStyleBackColor = true;
this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click);
//
// buttonCancel
//
this.buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.buttonCancel.Location = new System.Drawing.Point(439, 269);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(94, 23);
this.buttonCancel.TabIndex = 4;
this.buttonCancel.Text = "&Cancel";
this.buttonCancel.UseVisualStyleBackColor = true;
//
// CreateOrthogonalGridsForm
//
this.AcceptButton = this.buttonCreate;
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.CancelButton = this.buttonCancel;
this.ClientSize = new System.Drawing.Size(545, 304);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonCreate);
this.Controls.Add(this.groupBox3);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.groupBox1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "CreateOrthogonalGridsForm";
this.ShowIcon = false;
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Create Orthogonal Grids";
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.groupBox2.ResumeLayout(false);
this.groupBox2.PerformLayout();
this.groupBox3.ResumeLayout(false);
this.groupBox3.PerformLayout();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.TextBox textBoxYCoord;
private System.Windows.Forms.TextBox textBoxXCoord;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox textBoxYNumber;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox textBoxXNumber;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.GroupBox groupBox3;
private System.Windows.Forms.TextBox textBoxXSpacing;
private System.Windows.Forms.TextBox textBoxYSpacing;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.Label label7;
private System.Windows.Forms.Label label8;
private System.Windows.Forms.TextBox textBoxXFirstLabel;
private System.Windows.Forms.ComboBox comboBoxXBubbleLocation;
private System.Windows.Forms.Button buttonCreate;
private System.Windows.Forms.Button buttonCancel;
private System.Windows.Forms.TextBox textBoxYFirstLabel;
private System.Windows.Forms.ComboBox comboBoxYBubbleLocation;
private System.Windows.Forms.Label label10;
private System.Windows.Forms.Label label9;
private System.Windows.Forms.Label labelUnitY;
private System.Windows.Forms.Label labelUnitX;
private System.Windows.Forms.Label labelYCoordUnit;
private System.Windows.Forms.Label labelXCoordUnit;
}
}
CreateWithSeletedCurvesData.cs
//
// (C) Copyright 2003-2019 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Windows.Forms;
using Autodesk.Revit;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Application = Autodesk.Revit.ApplicationServices.Application;
namespace Revit.SDK.Samples.GridCreation.CS
{
/// <summary>
/// The dialog which provides the options of creating grids with selected lines/arcs
/// </summary>
public class CreateWithSelectedCurvesData : CreateGridsData
{
#region Fields
// Selected curves in current document
private CurveArray m_selectedCurves;
// Whether to delete selected lines/arc after creation
private bool m_deleteSelectedElements;
// Label of first grid
private String m_firstLabel;
// Bubble location of grids
private BubbleLocation m_bubbleLocation;
#endregion
#region Properties
/// <summary>
/// Whether to delete selected lines/arc after creation
/// </summary>
public bool DeleteSelectedElements
{
get
{
return m_deleteSelectedElements;
}
set
{
m_deleteSelectedElements = value;
}
}
/// <summary>
/// Bubble location of grids
/// </summary>
public BubbleLocation BubbleLocation
{
get
{
return m_bubbleLocation;
}
set
{
m_bubbleLocation = value;
}
}
/// <summary>
/// Label of first grid
/// </summary>
public String FirstLabel
{
get
{
return m_firstLabel;
}
set
{
m_firstLabel = value;
}
}
#endregion
#region Methods
/// <summary>
/// Constructor
/// </summary>
/// <param name="application">Revit application</param>
/// <param name="selectedCurves">Array contains geometry curves of selected lines or arcs </param>
/// <param name="labels">List contains all existing labels in Revit document</param>
public CreateWithSelectedCurvesData(UIApplication application, CurveArray selectedCurves, ArrayList labels)
: base(application, labels)
{
m_selectedCurves = selectedCurves;
}
/// <summary>
/// Create grids
/// </summary>
public void CreateGrids()
{
int errorCount = 0;
CurveArray curves = new CurveArray();
int i = 0;
foreach (Curve curve in m_selectedCurves)
{
try
{
Line line = curve as Line;
if (line != null) // Selected curve is a line
{
Line lineToCreate;
lineToCreate = TransformLine(line, m_bubbleLocation);
if (i == 0)
{
Grid grid;
// Create the first grid
grid = CreateLinearGrid(lineToCreate);
try
{
// Set label of first grid
grid.Name = m_firstLabel;
}
catch (System.ArgumentException)
{
ShowMessage(resManager.GetString("FailedToSetLabel") + m_firstLabel + "!",
resManager.GetString("FailureCaptionSetLabel"));
}
}
else
{
AddCurveForBatchCreation(ref curves, lineToCreate);
}
}
else // Selected curve is an arc
{
Arc arc = curve as Arc;
if (arc != null)
{
if (arc.IsBound) // Part of a circle
{
Arc arcToCreate;
arcToCreate = TransformArc(arc, m_bubbleLocation);
if (i == 0)
{
Grid grid;
// Create arc grid
grid = NewGrid(arcToCreate);
try
{
// Set label of first grid
grid.Name = m_firstLabel;
}
catch (System.ArgumentException)
{
ShowMessage(resManager.GetString("FailedToSetLabel") + m_firstLabel + "!",
resManager.GetString("FailureCaptionSetLabel"));
}
}
else
{
AddCurveForBatchCreation(ref curves, arcToCreate);
}
}
else // Arc is a circle
{
// In Revit UI user can select a circle to create a grid, but actually two grids
// (One from 0 to 180 degree and the other from 180 degree to 360) will be created.
// In RevitAPI using NewGrid method with a circle as its argument will raise an exception.
// Therefore in this sample we will create two arcs from the upper and lower parts of the
// circle, and then create two grids on the base of the two arcs to accord with UI.
Arc upperArc = null;
Arc lowerArc = null;
TransformCircle(arc, ref upperArc, ref lowerArc, m_bubbleLocation);
// Create grids
if (i == 0)
{
Grid gridUpper;
// Create arc grid
gridUpper = NewGrid(upperArc);
try
{
// Set label of first grid
gridUpper.Name = m_firstLabel;
}
catch (System.ArgumentException)
{
ShowMessage(resManager.GetString("FailedToSetLabel") + m_firstLabel + "!",
resManager.GetString("FailureCaptionSetLabel"));
}
AddCurveForBatchCreation(ref curves, lowerArc);
}
else
{
AddCurveForBatchCreation(ref curves, upperArc);
AddCurveForBatchCreation(ref curves, lowerArc);
}
}
}
}
}
catch (Exception)
{
++errorCount;
continue;
}
++i;
}
// Create grids with curves
CreateGrids(curves);
if (m_deleteSelectedElements)
{
try
{
foreach (Element e in Command.GetSelectedModelLinesAndArcs(m_revitDoc))
{
m_revitDoc.Delete(e.Id);
}
}
catch (Exception)
{
ShowMessage(resManager.GetString("FailedToDeletedLinesOrArcs"),
resManager.GetString("FailureCaptionDeletedLinesOrArcs"));
}
}
if (errorCount != 0)
{
ShowMessage(resManager.GetString("FailedToCreateGrids"),
resManager.GetString("FailureCaptionCreateGrids"));
}
}
#endregion
}
}
CreateWithSelectedCurvesForm.cs
//
// (C) Copyright 2003-2019 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
namespace Revit.SDK.Samples.GridCreation.CS
{
partial class CreateWithSelectedCurvesForm
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.buttonCancel = new System.Windows.Forms.Button();
this.buttonOK = new System.Windows.Forms.Button();
this.textBoxFirstLabel = new System.Windows.Forms.TextBox();
this.comboBoxBubbleLocation = new System.Windows.Forms.ComboBox();
this.labelBubbleLocation = new System.Windows.Forms.Label();
this.labelFirstLabel = new System.Windows.Forms.Label();
this.groupBoxGridSettings = new System.Windows.Forms.GroupBox();
this.checkBoxDeleteElements = new System.Windows.Forms.CheckBox();
this.groupBoxGridSettings.SuspendLayout();
this.SuspendLayout();
//
// buttonCancel
//
this.buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.buttonCancel.Location = new System.Drawing.Point(232, 144);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(90, 23);
this.buttonCancel.TabIndex = 1;
this.buttonCancel.Text = "&Cancel";
this.buttonCancel.UseVisualStyleBackColor = true;
//
// buttonOK
//
this.buttonOK.DialogResult = System.Windows.Forms.DialogResult.OK;
this.buttonOK.Location = new System.Drawing.Point(126, 144);
this.buttonOK.Name = "buttonOK";
this.buttonOK.Size = new System.Drawing.Size(90, 23);
this.buttonOK.TabIndex = 0;
this.buttonOK.Text = "Create &Grids";
this.buttonOK.UseVisualStyleBackColor = true;
this.buttonOK.Click += new System.EventHandler(this.buttonOK_Click);
//
// textBoxFirstLabel
//
this.textBoxFirstLabel.Location = new System.Drawing.Point(124, 53);
this.textBoxFirstLabel.Name = "textBoxFirstLabel";
this.textBoxFirstLabel.Size = new System.Drawing.Size(171, 20);
this.textBoxFirstLabel.TabIndex = 1;
this.textBoxFirstLabel.Tag = "";
this.textBoxFirstLabel.Text = "1";
//
// comboBoxBubbleLocation
//
this.comboBoxBubbleLocation.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxBubbleLocation.FormattingEnabled = true;
this.comboBoxBubbleLocation.Items.AddRange(new object[] {
"At start point of lines/arcs",
"At end point of lines/arcs"});
this.comboBoxBubbleLocation.Location = new System.Drawing.Point(124, 19);
this.comboBoxBubbleLocation.Name = "comboBoxBubbleLocation";
this.comboBoxBubbleLocation.Size = new System.Drawing.Size(171, 21);
this.comboBoxBubbleLocation.TabIndex = 0;
//
// labelBubbleLocation
//
this.labelBubbleLocation.Location = new System.Drawing.Point(6, 21);
this.labelBubbleLocation.Name = "labelBubbleLocation";
this.labelBubbleLocation.Size = new System.Drawing.Size(112, 19);
this.labelBubbleLocation.TabIndex = 16;
this.labelBubbleLocation.Text = "Bubble location:";
//
// labelFirstLabel
//
this.labelFirstLabel.Location = new System.Drawing.Point(6, 56);
this.labelFirstLabel.Name = "labelFirstLabel";
this.labelFirstLabel.Size = new System.Drawing.Size(112, 19);
this.labelFirstLabel.TabIndex = 15;
this.labelFirstLabel.Text = "Label of first grid:";
//
// groupBoxGridSettings
//
this.groupBoxGridSettings.Controls.Add(this.checkBoxDeleteElements);
this.groupBoxGridSettings.Controls.Add(this.labelBubbleLocation);
this.groupBoxGridSettings.Controls.Add(this.textBoxFirstLabel);
this.groupBoxGridSettings.Controls.Add(this.labelFirstLabel);
this.groupBoxGridSettings.Controls.Add(this.comboBoxBubbleLocation);
this.groupBoxGridSettings.Location = new System.Drawing.Point(12, 12);
this.groupBoxGridSettings.Name = "groupBoxGridSettings";
this.groupBoxGridSettings.Size = new System.Drawing.Size(310, 113);
this.groupBoxGridSettings.TabIndex = 18;
this.groupBoxGridSettings.TabStop = false;
this.groupBoxGridSettings.Text = "Settings";
//
// checkBoxDeleteElements
//
this.checkBoxDeleteElements.AutoSize = true;
this.checkBoxDeleteElements.Checked = true;
this.checkBoxDeleteElements.CheckState = System.Windows.Forms.CheckState.Checked;
this.checkBoxDeleteElements.Location = new System.Drawing.Point(9, 87);
this.checkBoxDeleteElements.Name = "checkBoxDeleteElements";
this.checkBoxDeleteElements.Size = new System.Drawing.Size(232, 17);
this.checkBoxDeleteElements.TabIndex = 2;
this.checkBoxDeleteElements.Text = "Delete the selected lines/arcs after creation";
this.checkBoxDeleteElements.UseVisualStyleBackColor = true;
//
// CreateWithSelectedCurvesForm
//
this.AcceptButton = this.buttonOK;
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.CancelButton = this.buttonCancel;
this.ClientSize = new System.Drawing.Size(334, 177);
this.Controls.Add(this.groupBoxGridSettings);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonOK);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "CreateWithSelectedCurvesForm";
this.ShowIcon = false;
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Create Grids with Lines/Arcs";
this.groupBoxGridSettings.ResumeLayout(false);
this.groupBoxGridSettings.PerformLayout();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Button buttonCancel;
private System.Windows.Forms.Button buttonOK;
private System.Windows.Forms.TextBox textBoxFirstLabel;
private System.Windows.Forms.ComboBox comboBoxBubbleLocation;
private System.Windows.Forms.Label labelBubbleLocation;
private System.Windows.Forms.Label labelFirstLabel;
private System.Windows.Forms.GroupBox groupBoxGridSettings;
private System.Windows.Forms.CheckBox checkBoxDeleteElements;
}
}
CreateOrthogonalGridsData.cs
//
// (C) Copyright 2003-2019 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Windows.Forms;
using Autodesk.Revit;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Application = Autodesk.Revit.ApplicationServices.Application;
namespace Revit.SDK.Samples.GridCreation.CS
{
/// <summary>
/// Data class which stores information for creating orthogonal grids
/// </summary>
public class CreateOrthogonalGridsData : CreateGridsData
{
#region Fields
// X coordinate of origin
private double m_xOrigin;
// Y coordinate of origin
private double m_yOrigin;
// Spacing between horizontal grids
private double m_xSpacing;
// Spacing between vertical grids
private double m_ySpacing;
// Number of horizontal grids
private uint m_xNumber;
// Number of vertical grids
private uint m_yNumber;
// Bubble location of horizontal grids
private BubbleLocation m_xBubbleLoc;
// Bubble location of vertical grids
private BubbleLocation m_yBubbleLoc;
// Label of first horizontal grid
private String m_xFirstLabel;
// Label of first vertical grid
private String m_yFirstLabel;
#endregion
#region Properties
/// <summary>
/// X coordinate of origin
/// </summary>
public double XOrigin
{
get
{
return m_xOrigin;
}
set
{
m_xOrigin = value;
}
}
/// <summary>
/// Y coordinate of origin
/// </summary>
public double YOrigin
{
get
{
return m_yOrigin;
}
set
{
m_yOrigin = value;
}
}
/// <summary>
/// Spacing between horizontal grids
/// </summary>
public double XSpacing
{
get
{
return m_xSpacing;
}
set
{
m_xSpacing = value;
}
}
/// <summary>
/// Spacing between vertical grids
/// </summary>
public double YSpacing
{
get
{
return m_ySpacing;
}
set
{
m_ySpacing = value;
}
}
/// <summary>
/// Number of horizontal grids
/// </summary>
public uint XNumber
{
get
{
return m_xNumber;
}
set
{
m_xNumber = value;
}
}
/// <summary>
/// Number of vertical grids
/// </summary>
public uint YNumber
{
get
{
return m_yNumber;
}
set
{
m_yNumber = value;
}
}
/// <summary>
/// Bubble location of horizontal grids
/// </summary>
public BubbleLocation XBubbleLoc
{
get
{
return m_xBubbleLoc;
}
set
{
m_xBubbleLoc = value;
}
}
/// <summary>
/// Bubble location of vertical grids
/// </summary>
public BubbleLocation YBubbleLoc
{
get
{
return m_yBubbleLoc;
}
set
{
m_yBubbleLoc = value;
}
}
/// <summary>
/// Label of first horizontal grid
/// </summary>
public String XFirstLabel
{
get
{
return m_xFirstLabel;
}
set
{
m_xFirstLabel = value;
}
}
/// <summary>
/// Label of first vertical grid
/// </summary>
public String YFirstLabel
{
get
{
return m_yFirstLabel;
}
set
{
m_yFirstLabel = value;
}
}
#endregion
#region Methods
/// <summary>
/// Constructor
/// </summary>
/// <param name="application">Application object</param>
/// <param name="dut">Current length display unit type</param>
/// <param name="labels">All existing labels in Revit's document</param>
public CreateOrthogonalGridsData(UIApplication application, DisplayUnitType dut, ArrayList labels)
: base(application, labels, dut)
{
}
/// <summary>
/// Create grids
/// </summary>
public void CreateGrids()
{
ArrayList failureReasons = new ArrayList();
if (CreateXGrids(ref failureReasons) + CreateYGrids(ref failureReasons) != 0)
{
String failureReason = resManager.GetString("FailedToCreateGrids");
if (failureReasons.Count != 0)
{
failureReason += resManager.GetString("Reasons") + "\r";
failureReason += "\r";
foreach (String reason in failureReasons)
{
failureReason += reason + "\r";
}
}
failureReason += "\r" + resManager.GetString("AjustValues");
ShowMessage(failureReason, resManager.GetString("FailureCaptionCreateGrids"));
}
}
/// <summary>
/// Create horizontal grids
/// </summary>
/// <param name="failureReasons">ArrayList contains failure reasons</param>
/// <returns>Number of grids failed to create</returns>
private int CreateXGrids(ref ArrayList failureReasons)
{
int errorCount = 0;
// Curve array which stores all curves for batch creation
CurveArray curves = new CurveArray();
for (int i = 0; i < m_xNumber; ++i)
{
Autodesk.Revit.DB.XYZ startPoint;
Autodesk.Revit.DB.XYZ endPoint;
Line line;
try
{
if (m_yNumber != 0)
{
// Grids will have an extension distance of m_ySpacing / 2
startPoint = new Autodesk.Revit.DB.XYZ (m_xOrigin - m_ySpacing / 2, m_yOrigin + i * m_xSpacing, 0);
endPoint = new Autodesk.Revit.DB.XYZ (m_xOrigin + (m_yNumber - 1) * m_ySpacing + m_ySpacing / 2, m_yOrigin + i * m_xSpacing, 0);
}
else
{
startPoint = new Autodesk.Revit.DB.XYZ (m_xOrigin, m_yOrigin + i * m_xSpacing, 0);
endPoint = new Autodesk.Revit.DB.XYZ (m_xOrigin + m_xSpacing / 2, m_yOrigin + i * m_xSpacing, 0);
}
try
{
// Create a line according to the bubble location
if (m_xBubbleLoc == BubbleLocation.StartPoint)
{
line = NewLine(startPoint, endPoint);
}
else
{
line = NewLine(endPoint, startPoint);
}
}
catch (System.ArgumentException)
{
String failureReason = resManager.GetString("SpacingsTooSmall");
if (!failureReasons.Contains(failureReason))
{
failureReasons.Add(failureReason);
}
errorCount++;
continue;
}
if (i == 0)
{
Grid grid;
// Create grid with line
grid = NewGrid(line);
try
{
// Set the label of first horizontal grid
grid.Name = m_xFirstLabel;
}
catch (System.ArgumentException)
{
ShowMessage(resManager.GetString("FailedToSetLabel") + m_xFirstLabel + "!",
resManager.GetString("FailureCaptionSetLabel"));
}
}
else
{
// Add the line to curve array
curves.Append(line);
}
}
catch (Exception)
{
++errorCount;
continue;
}
}
// Create grids with curve array
CreateGrids(curves);
return errorCount;
}
/// <summary>
/// Create vertical grids
/// </summary>
/// <param name="failureReasons">ArrayList contains failure reasons</param>
/// <returns>Number of grids failed to create</returns>
private int CreateYGrids(ref ArrayList failureReasons)
{
int errorCount = 0;
// Curve array which stores all curves for batch creation
CurveArray curves = new CurveArray();
for (int j = 0; j < m_yNumber; ++j)
{
Autodesk.Revit.DB.XYZ startPoint;
Autodesk.Revit.DB.XYZ endPoint;
Line line;
try
{
if (m_xNumber != 0)
{
startPoint = new Autodesk.Revit.DB.XYZ (m_xOrigin + j * m_ySpacing, m_yOrigin - m_xSpacing / 2, 0);
endPoint = new Autodesk.Revit.DB.XYZ (m_xOrigin + j * m_ySpacing, m_yOrigin + (m_xNumber - 1) * m_xSpacing + m_xSpacing / 2, 0);
}
else
{
startPoint = new Autodesk.Revit.DB.XYZ (m_xOrigin + j * m_ySpacing, m_yOrigin, 0);
endPoint = new Autodesk.Revit.DB.XYZ (m_xOrigin + j * m_ySpacing, m_yOrigin + m_ySpacing / 2, 0);
}
try
{
// Create a line according to the bubble location
if (m_yBubbleLoc == BubbleLocation.StartPoint)
{
line = NewLine(startPoint, endPoint);
}
else
{
line = NewLine(endPoint, startPoint);
}
}
catch (System.ArgumentException)
{
String failureReason = resManager.GetString("SpacingsTooSmall");
if (!failureReasons.Contains(failureReason))
{
failureReasons.Add(failureReason);
}
errorCount++;
continue;
}
if (j == 0)
{
Grid grid;
// Create grid with line
grid = NewGrid(line);
try
{
// Set label of first vertical grid
grid.Name = m_yFirstLabel;
}
catch (System.ArgumentException)
{
ShowMessage(resManager.GetString("FailedToSetLabel") + m_yFirstLabel + "!",
resManager.GetString("FailureCaptionSetLabel"));
}
}
else
{
// Add the line to curve array
curves.Append(line);
}
}
catch (Exception)
{
++errorCount;
continue;
}
}
// Create grids with curves
CreateGrids(curves);
return errorCount;
}
#endregion
}
}
CreateOrthogonalGridsForm.cs
//
// (C) Copyright 2003-2019 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
namespace Revit.SDK.Samples.GridCreation.CS
{
partial class CreateOrthogonalGridsForm
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.labelYCoordUnit = new System.Windows.Forms.Label();
this.labelXCoordUnit = new System.Windows.Forms.Label();
this.textBoxYCoord = new System.Windows.Forms.TextBox();
this.textBoxXCoord = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.textBoxYNumber = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.textBoxXNumber = new System.Windows.Forms.TextBox();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.labelUnitY = new System.Windows.Forms.Label();
this.textBoxYSpacing = new System.Windows.Forms.TextBox();
this.textBoxYFirstLabel = new System.Windows.Forms.TextBox();
this.comboBoxYBubbleLocation = new System.Windows.Forms.ComboBox();
this.label10 = new System.Windows.Forms.Label();
this.label5 = new System.Windows.Forms.Label();
this.label9 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.groupBox3 = new System.Windows.Forms.GroupBox();
this.labelUnitX = new System.Windows.Forms.Label();
this.textBoxXSpacing = new System.Windows.Forms.TextBox();
this.textBoxXFirstLabel = new System.Windows.Forms.TextBox();
this.comboBoxXBubbleLocation = new System.Windows.Forms.ComboBox();
this.label6 = new System.Windows.Forms.Label();
this.label7 = new System.Windows.Forms.Label();
this.label8 = new System.Windows.Forms.Label();
this.buttonCreate = new System.Windows.Forms.Button();
this.buttonCancel = new System.Windows.Forms.Button();
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
this.groupBox3.SuspendLayout();
this.SuspendLayout();
//
// groupBox1
//
this.groupBox1.Controls.Add(this.labelYCoordUnit);
this.groupBox1.Controls.Add(this.labelXCoordUnit);
this.groupBox1.Controls.Add(this.textBoxYCoord);
this.groupBox1.Controls.Add(this.textBoxXCoord);
this.groupBox1.Controls.Add(this.label2);
this.groupBox1.Controls.Add(this.label1);
this.groupBox1.Location = new System.Drawing.Point(13, 12);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(520, 55);
this.groupBox1.TabIndex = 0;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Origin of the Grids";
//
// labelYCoordUnit
//
this.labelYCoordUnit.Location = new System.Drawing.Point(484, 23);
this.labelYCoordUnit.Name = "labelYCoordUnit";
this.labelYCoordUnit.Size = new System.Drawing.Size(23, 13);
this.labelYCoordUnit.TabIndex = 7;
//
// labelXCoordUnit
//
this.labelXCoordUnit.Location = new System.Drawing.Point(227, 23);
this.labelXCoordUnit.Name = "labelXCoordUnit";
this.labelXCoordUnit.Size = new System.Drawing.Size(23, 13);
this.labelXCoordUnit.TabIndex = 7;
//
// textBoxYCoord
//
this.textBoxYCoord.Location = new System.Drawing.Point(385, 20);
this.textBoxYCoord.Name = "textBoxYCoord";
this.textBoxYCoord.Size = new System.Drawing.Size(98, 20);
this.textBoxYCoord.TabIndex = 1;
this.textBoxYCoord.Tag = "0";
this.textBoxYCoord.Text = "0";
//
// textBoxXCoord
//
this.textBoxXCoord.Location = new System.Drawing.Point(109, 20);
this.textBoxXCoord.Name = "textBoxXCoord";
this.textBoxXCoord.Size = new System.Drawing.Size(112, 20);
this.textBoxXCoord.TabIndex = 0;
this.textBoxXCoord.Tag = "0";
this.textBoxXCoord.Text = "0";
//
// label2
//
this.label2.Location = new System.Drawing.Point(261, 24);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(122, 13);
this.label2.TabIndex = 0;
this.label2.Text = "Y coordinate:";
//
// label1
//
this.label1.Location = new System.Drawing.Point(7, 24);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(95, 13);
this.label1.TabIndex = 0;
this.label1.Text = "X coordinate:";
//
// textBoxYNumber
//
this.textBoxYNumber.Location = new System.Drawing.Point(385, 24);
this.textBoxYNumber.Name = "textBoxYNumber";
this.textBoxYNumber.Size = new System.Drawing.Size(120, 20);
this.textBoxYNumber.TabIndex = 1;
this.textBoxYNumber.Tag = "3";
this.textBoxYNumber.Text = "3";
//
// label3
//
this.label3.Location = new System.Drawing.Point(261, 27);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(122, 13);
this.label3.TabIndex = 7;
this.label3.Text = "Number:";
//
// textBoxXNumber
//
this.textBoxXNumber.Location = new System.Drawing.Point(385, 23);
this.textBoxXNumber.Name = "textBoxXNumber";
this.textBoxXNumber.Size = new System.Drawing.Size(120, 20);
this.textBoxXNumber.TabIndex = 1;
this.textBoxXNumber.Tag = "3";
this.textBoxXNumber.Text = "3";
//
// groupBox2
//
this.groupBox2.Controls.Add(this.labelUnitY);
this.groupBox2.Controls.Add(this.textBoxYNumber);
this.groupBox2.Controls.Add(this.textBoxYSpacing);
this.groupBox2.Controls.Add(this.textBoxYFirstLabel);
this.groupBox2.Controls.Add(this.label3);
this.groupBox2.Controls.Add(this.comboBoxYBubbleLocation);
this.groupBox2.Controls.Add(this.label10);
this.groupBox2.Controls.Add(this.label5);
this.groupBox2.Controls.Add(this.label9);
this.groupBox2.Location = new System.Drawing.Point(14, 165);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(519, 85);
this.groupBox2.TabIndex = 2;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "Y direction Grids";
//
// labelUnitY
//
this.labelUnitY.Location = new System.Drawing.Point(227, 26);
this.labelUnitY.Name = "labelUnitY";
this.labelUnitY.Size = new System.Drawing.Size(23, 13);
this.labelUnitY.TabIndex = 7;
//
// textBoxYSpacing
//
this.textBoxYSpacing.Location = new System.Drawing.Point(110, 24);
this.textBoxYSpacing.Name = "textBoxYSpacing";
this.textBoxYSpacing.Size = new System.Drawing.Size(112, 20);
this.textBoxYSpacing.TabIndex = 0;
this.textBoxYSpacing.Tag = "10.0";
this.textBoxYSpacing.Text = 10.0.ToString("0.0");
//
// textBoxYFirstLabel
//
this.textBoxYFirstLabel.Location = new System.Drawing.Point(385, 53);
this.textBoxYFirstLabel.Name = "textBoxYFirstLabel";
this.textBoxYFirstLabel.Size = new System.Drawing.Size(120, 20);
this.textBoxYFirstLabel.TabIndex = 3;
this.textBoxYFirstLabel.Tag = "A";
this.textBoxYFirstLabel.Text = "A";
//
// comboBoxYBubbleLocation
//
this.comboBoxYBubbleLocation.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxYBubbleLocation.FormattingEnabled = true;
this.comboBoxYBubbleLocation.Items.AddRange(new object[] {
"At start point of lines",
"At end point of lines"});
this.comboBoxYBubbleLocation.Location = new System.Drawing.Point(108, 53);
this.comboBoxYBubbleLocation.Name = "comboBoxYBubbleLocation";
this.comboBoxYBubbleLocation.Size = new System.Drawing.Size(146, 21);
this.comboBoxYBubbleLocation.TabIndex = 2;
//
// label10
//
this.label10.Location = new System.Drawing.Point(7, 55);
this.label10.Name = "label10";
this.label10.Size = new System.Drawing.Size(95, 13);
this.label10.TabIndex = 6;
this.label10.Text = "Bubble location:";
//
// label5
//
this.label5.Location = new System.Drawing.Point(6, 26);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(95, 13);
this.label5.TabIndex = 7;
this.label5.Text = "Spacing:";
//
// label9
//
this.label9.Location = new System.Drawing.Point(261, 55);
this.label9.Name = "label9";
this.label9.Size = new System.Drawing.Size(122, 13);
this.label9.TabIndex = 6;
this.label9.Text = "Label of first grid:";
//
// label4
//
this.label4.Location = new System.Drawing.Point(261, 26);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(122, 13);
this.label4.TabIndex = 6;
this.label4.Text = "Number:";
//
// groupBox3
//
this.groupBox3.Controls.Add(this.labelUnitX);
this.groupBox3.Controls.Add(this.textBoxXNumber);
this.groupBox3.Controls.Add(this.textBoxXSpacing);
this.groupBox3.Controls.Add(this.textBoxXFirstLabel);
this.groupBox3.Controls.Add(this.comboBoxXBubbleLocation);
this.groupBox3.Controls.Add(this.label6);
this.groupBox3.Controls.Add(this.label7);
this.groupBox3.Controls.Add(this.label4);
this.groupBox3.Controls.Add(this.label8);
this.groupBox3.Location = new System.Drawing.Point(13, 73);
this.groupBox3.Name = "groupBox3";
this.groupBox3.Size = new System.Drawing.Size(520, 86);
this.groupBox3.TabIndex = 1;
this.groupBox3.TabStop = false;
this.groupBox3.Text = "X direction Grids";
//
// labelUnitX
//
this.labelUnitX.Location = new System.Drawing.Point(227, 25);
this.labelUnitX.Name = "labelUnitX";
this.labelUnitX.Size = new System.Drawing.Size(23, 13);
this.labelUnitX.TabIndex = 7;
//
// textBoxXSpacing
//
this.textBoxXSpacing.Location = new System.Drawing.Point(109, 23);
this.textBoxXSpacing.Name = "textBoxXSpacing";
this.textBoxXSpacing.Size = new System.Drawing.Size(112, 20);
this.textBoxXSpacing.TabIndex = 0;
this.textBoxXSpacing.Tag = "10.0";
this.textBoxXSpacing.Text = 10.0.ToString("0.0");
//
// textBoxXFirstLabel
//
this.textBoxXFirstLabel.Location = new System.Drawing.Point(385, 53);
this.textBoxXFirstLabel.Name = "textBoxXFirstLabel";
this.textBoxXFirstLabel.Size = new System.Drawing.Size(120, 20);
this.textBoxXFirstLabel.TabIndex = 3;
this.textBoxXFirstLabel.Tag = "";
this.textBoxXFirstLabel.Text = "1";
//
// comboBoxXBubbleLocation
//
this.comboBoxXBubbleLocation.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxXBubbleLocation.FormattingEnabled = true;
this.comboBoxXBubbleLocation.Items.AddRange(new object[] {
"At start point of lines",
"At end point of lines"});
this.comboBoxXBubbleLocation.Location = new System.Drawing.Point(108, 53);
this.comboBoxXBubbleLocation.Name = "comboBoxXBubbleLocation";
this.comboBoxXBubbleLocation.Size = new System.Drawing.Size(147, 21);
this.comboBoxXBubbleLocation.TabIndex = 2;
//
// label6
//
this.label6.Location = new System.Drawing.Point(7, 25);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(95, 13);
this.label6.TabIndex = 6;
this.label6.Text = "Spacing:";
//
// label7
//
this.label7.Location = new System.Drawing.Point(7, 55);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(95, 13);
this.label7.TabIndex = 6;
this.label7.Text = "Bubble location:";
//
// label8
//
this.label8.Location = new System.Drawing.Point(261, 55);
this.label8.Name = "label8";
this.label8.Size = new System.Drawing.Size(122, 13);
this.label8.TabIndex = 6;
this.label8.Text = "Label of first grid:";
//
// buttonCreate
//
this.buttonCreate.DialogResult = System.Windows.Forms.DialogResult.OK;
this.buttonCreate.Location = new System.Drawing.Point(327, 269);
this.buttonCreate.Name = "buttonCreate";
this.buttonCreate.Size = new System.Drawing.Size(94, 23);
this.buttonCreate.TabIndex = 3;
this.buttonCreate.Text = "Create &Grids";
this.buttonCreate.UseVisualStyleBackColor = true;
this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click);
//
// buttonCancel
//
this.buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.buttonCancel.Location = new System.Drawing.Point(439, 269);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(94, 23);
this.buttonCancel.TabIndex = 4;
this.buttonCancel.Text = "&Cancel";
this.buttonCancel.UseVisualStyleBackColor = true;
//
// CreateOrthogonalGridsForm
//
this.AcceptButton = this.buttonCreate;
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.CancelButton = this.buttonCancel;
this.ClientSize = new System.Drawing.Size(545, 304);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonCreate);
this.Controls.Add(this.groupBox3);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.groupBox1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "CreateOrthogonalGridsForm";
this.ShowIcon = false;
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Create Orthogonal Grids";
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.groupBox2.ResumeLayout(false);
this.groupBox2.PerformLayout();
this.groupBox3.ResumeLayout(false);
this.groupBox3.PerformLayout();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.TextBox textBoxYCoord;
private System.Windows.Forms.TextBox textBoxXCoord;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox textBoxYNumber;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox textBoxXNumber;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.GroupBox groupBox3;
private System.Windows.Forms.TextBox textBoxXSpacing;
private System.Windows.Forms.TextBox textBoxYSpacing;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.Label label7;
private System.Windows.Forms.Label label8;
private System.Windows.Forms.TextBox textBoxXFirstLabel;
private System.Windows.Forms.ComboBox comboBoxXBubbleLocation;
private System.Windows.Forms.Button buttonCreate;
private System.Windows.Forms.Button buttonCancel;
private System.Windows.Forms.TextBox textBoxYFirstLabel;
private System.Windows.Forms.ComboBox comboBoxYBubbleLocation;
private System.Windows.Forms.Label label10;
private System.Windows.Forms.Label label9;
private System.Windows.Forms.Label labelUnitY;
private System.Windows.Forms.Label labelUnitX;
private System.Windows.Forms.Label labelYCoordUnit;
private System.Windows.Forms.Label labelXCoordUnit;
}
}
CreateRadialAndArcGridsData.cs
//
// (C) Copyright 2003-2019 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Windows.Forms;
using Autodesk.Revit;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Application = Autodesk.Revit.ApplicationServices.Application;
namespace Revit.SDK.Samples.GridCreation.CS
{
/// <summary>
/// The dialog which provides the options of creating radial and arc grids
/// </summary>
public class CreateRadialAndArcGridsData : CreateGridsData
{
#region Fields
// X coordinate of origin
private double m_xOrigin;
// Y coordinate of origin
private double m_yOrigin;
// Start degree of arc grids and radial grids
private double m_startDegree;
// End degree of arc grids and radial grids
private double m_endDegree;
// Spacing between arc grids
private double m_arcSpacing;
// Number of arc grids
private uint m_arcNumber;
// Number of radial grids
private uint m_lineNumber;
// Radius of first arc grid
private double m_arcFirstRadius;
// Distance from origin to start point
private double m_LineFirstDistance;
// Bubble location of arc grids
private BubbleLocation m_arcFirstBubbleLoc;
// Bubble location of radial grids
private BubbleLocation m_lineFirstBubbleLoc;
// Label of first arc grid
private String m_arcFirstLabel;
// Label of first radial grid
private String m_lineFirstLabel;
#endregion
#region Properties
/// <summary>
/// X coordinate of origin
/// </summary>
public double XOrigin
{
get
{
return m_xOrigin;
}
set
{
m_xOrigin = value;
}
}
/// <summary>
/// Y coordinate of origin
/// </summary>
public double YOrigin
{
get
{
return m_yOrigin;
}
set
{
m_yOrigin = value;
}
}
/// <summary>
/// Start degree of arc grids and radial grids
/// </summary>
public double StartDegree
{
get
{
return m_startDegree;
}
set
{
m_startDegree = value;
}
}
/// <summary>
/// End degree of arc grids and radial grids
/// </summary>
public double EndDegree
{
get
{
return m_endDegree;
}
set
{
m_endDegree = value;
}
}
/// <summary>
/// Spacing between arc grids
/// </summary>
public double ArcSpacing
{
get
{
return m_arcSpacing;
}
set
{
m_arcSpacing = value;
}
}
/// <summary>
/// Number of arc grids
/// </summary>
public uint ArcNumber
{
get
{
return m_arcNumber;
}
set
{
m_arcNumber = value;
}
}
/// <summary>
/// Number of radial grids
/// </summary>
public uint LineNumber
{
get
{
return m_lineNumber;
}
set
{
m_lineNumber = value;
}
}
/// <summary>
/// Radius of first arc grid
/// </summary>
public double ArcFirstRadius
{
get
{
return m_arcFirstRadius;
}
set
{
m_arcFirstRadius = value;
}
}
/// <summary>
/// Distance from origin to start point
/// </summary>
public double LineFirstDistance
{
get
{
return m_LineFirstDistance;
}
set
{
m_LineFirstDistance = value;
}
}
/// <summary>
/// Bubble location of arc grids
/// </summary>
public BubbleLocation ArcFirstBubbleLoc
{
get
{
return m_arcFirstBubbleLoc;
}
set
{
m_arcFirstBubbleLoc = value;
}
}
/// <summary>
/// Bubble location of radial grids
/// </summary>
public BubbleLocation LineFirstBubbleLoc
{
get
{
return m_lineFirstBubbleLoc;
}
set
{
m_lineFirstBubbleLoc = value;
}
}
/// <summary>
/// Label of first arc grid
/// </summary>
public String ArcFirstLabel
{
get
{
return m_arcFirstLabel;
}
set
{
m_arcFirstLabel = value;
}
}
/// <summary>
/// Label of first radial grid
/// </summary>
public String LineFirstLabel
{
get
{
return m_lineFirstLabel;
}
set
{
m_lineFirstLabel = value;
}
}
#endregion
#region Methods
/// <summary>
/// Constructor
/// </summary>
/// <param name="application">Application object</param>
/// <param name="dut">Current length display unit type</param>
/// <param name="labels">All existing labels in Revit's document</param>
public CreateRadialAndArcGridsData(UIApplication application, DisplayUnitType dut, ArrayList labels)
: base(application, labels)
{
}
/// <summary>
/// Create grids
/// </summary>
public void CreateGrids()
{
if (CreateRadialGrids() != 0)
{
String failureReason = resManager.GetString("FailedToCreateRadialGrids") + "\r";
failureReason += resManager.GetString("AjustValues");
ShowMessage(failureReason, resManager.GetString("FailureCaptionCreateGrids"));
}
ArrayList failureReasons = new ArrayList();
if (CreateArcGrids(ref failureReasons) != 0)
{
String failureReason = resManager.GetString("FailedToCreateArcGrids") +
resManager.GetString("Reasons") + "\r";
if (failureReasons.Count != 0)
{
failureReason += "\r";
foreach (String reason in failureReasons)
{
failureReason += reason + "\r";
}
}
failureReason += "\r" + resManager.GetString("AjustValues");
ShowMessage(failureReason, resManager.GetString("FailureCaptionCreateGrids"));
}
}
/// <summary>
/// Create radial grids
/// </summary>
/// <returns>Number of grids failed to create</returns>
private int CreateRadialGrids()
{
int errorCount = 0;
// Curve array which stores all curves for batch creation
CurveArray curves = new CurveArray();
for (int i = 0; i < m_lineNumber; ++i)
{
try
{
double angel;
if (m_lineNumber == 1)
{
angel = (m_startDegree + m_endDegree) / 2;
}
else
{
// The number of space between radial grids will be m_lineNumber if arc is a circle
if (m_endDegree - m_startDegree == 2 * Values.PI)
{
angel = m_startDegree + i * (m_endDegree - m_startDegree) / m_lineNumber;
}
// The number of space between radial grids will be m_lineNumber-1 if arc is not a circle
else
{
angel = m_startDegree + i * (m_endDegree - m_startDegree) / (m_lineNumber - 1);
}
}
Autodesk.Revit.DB.XYZ startPoint;
Autodesk.Revit.DB.XYZ endPoint;
double cos = Math.Cos(angel);
double sin = Math.Sin(angel);
if (m_arcNumber != 0)
{
// Grids will have an extension distance of m_ySpacing / 2
startPoint = new Autodesk.Revit.DB.XYZ (m_xOrigin + m_LineFirstDistance * cos, m_yOrigin + m_LineFirstDistance * sin, 0);
endPoint = new Autodesk.Revit.DB.XYZ (m_xOrigin + (m_arcFirstRadius + (m_arcNumber - 1) * m_arcSpacing + m_arcSpacing / 2) * cos,
m_yOrigin + (m_arcFirstRadius + (m_arcNumber - 1) * m_arcSpacing + m_arcSpacing / 2) * sin, 0);
}
else
{
startPoint = new Autodesk.Revit.DB.XYZ (m_xOrigin + m_LineFirstDistance * cos, m_yOrigin + m_LineFirstDistance * sin, 0);
endPoint = new Autodesk.Revit.DB.XYZ (m_xOrigin + (m_arcFirstRadius + 5) * cos, m_yOrigin + (m_arcFirstRadius + 5) * sin, 0);
}
Line line;
// Create a line according to the bubble location
if (m_lineFirstBubbleLoc == BubbleLocation.StartPoint)
{
line = NewLine(startPoint, endPoint);
}
else
{
line = NewLine(endPoint, startPoint);
}
if (i == 0)
{
// Create grid with line
Grid grid = NewGrid(line);
try
{
// Set label of first radial grid
grid.Name = m_lineFirstLabel;
}
catch (System.ArgumentException)
{
ShowMessage(resManager.GetString("FailedToSetLabel") + m_lineFirstLabel + "!",
resManager.GetString("FailureCaptionSetLabel"));
}
}
else
{
// Add the line to curve array
AddCurveForBatchCreation(ref curves, line);
}
}
catch (Exception)
{
++errorCount;
continue;
}
}
// Create grids with curves
CreateGrids(curves);
return errorCount;
}
/// <summary>
/// Create Arc Grids
/// </summary>
/// <param name="failureReasons">ArrayList contains failure reasons</param>
/// <returns>Number of grids failed to create</returns>
private int CreateArcGrids(ref ArrayList failureReasons)
{
int errorCount = 0;
// Curve array which stores all curves for batch creation
CurveArray curves = new CurveArray();
for (int i = 0; i < m_arcNumber; ++i)
{
try
{
Autodesk.Revit.DB.XYZ origin = new Autodesk.Revit.DB.XYZ (m_xOrigin, m_yOrigin, 0);
double radius = m_arcFirstRadius + i * m_arcSpacing;
// In Revit UI user can select a circle to create a grid, but actually two grids
// (One from 0 to 180 degree and the other from 180 degree to 360) will be created.
// In RevitAPI using NewGrid method with a circle as its argument will raise an exception.
// Therefore in this sample we will create two arcs from the upper and lower parts of the
// circle, and then create two grids on the base of the two arcs to accord with UI.
if (m_endDegree - m_startDegree == 2 * Values.PI) // Create circular grids
{
Arc upperArcToCreate;
Arc lowerArcToCreate;
upperArcToCreate = TransformArc(origin, radius, 0, Values.PI, m_arcFirstBubbleLoc);
if (i == 0)
{
Grid gridUpper;
gridUpper = NewGrid(upperArcToCreate);
if (gridUpper != null)
{
try
{
// Set label of first grid
gridUpper.Name = m_arcFirstLabel;
}
catch (System.ArgumentException)
{
ShowMessage(resManager.GetString("FailedToSetLabel") + m_arcFirstLabel + "!",
resManager.GetString("FailureCaptionSetLabel"));
}
}
}
else
{
curves.Append(upperArcToCreate);
}
lowerArcToCreate = TransformArc(origin, radius, Values.PI, 2 * Values.PI, m_arcFirstBubbleLoc);
curves.Append(lowerArcToCreate);
}
else // Create arc grids
{
// Each arc grid will has extension degree of 15 degree
double extensionDegree = 15 * Values.DEGTORAD;
Grid grid;
Arc arcToCreate;
if (m_lineNumber != 0)
{
// If the range of arc degree is too close to a circle, the arc grids will not have
// extension degrees.
// Also the room for bubble should be considered, so a room size of 3 * extensionDegree
// is reserved here
if (m_endDegree - m_startDegree < 2 * Values.PI - 3 * extensionDegree)
{
double startDegreeWithExtension = m_startDegree - extensionDegree;
double endDegreeWithExtension = m_endDegree + extensionDegree;
arcToCreate = TransformArc(origin, radius, startDegreeWithExtension, endDegreeWithExtension, m_arcFirstBubbleLoc);
}
else
{
try
{
arcToCreate = TransformArc(origin, radius, m_startDegree, m_endDegree, m_arcFirstBubbleLoc);
}
catch (System.ArgumentException)
{
String failureReason = resManager.GetString("EndPointsTooClose");
if (!failureReasons.Contains(failureReason))
{
failureReasons.Add(failureReason);
}
errorCount++;
continue;
}
}
}
else
{
try
{
arcToCreate = TransformArc(origin, radius, m_startDegree, m_endDegree, m_arcFirstBubbleLoc);
}
catch (System.ArgumentException)
{
String failureReason = resManager.GetString("EndPointsTooClose");
if (!failureReasons.Contains(failureReason))
{
failureReasons.Add(failureReason);
}
errorCount++;
continue;
}
}
if (i == 0)
{
grid = NewGrid(arcToCreate);
if (grid != null)
{
try
{
grid.Name = m_arcFirstLabel;
}
catch (System.ArgumentException)
{
ShowMessage(resManager.GetString("FailedToSetLabel") + m_arcFirstLabel + "!",
resManager.GetString("FailureCaptionSetLabel"));
}
}
}
else
{
curves.Append(arcToCreate);
}
}
}
catch (Exception)
{
++errorCount;
continue;
}
}
// Create grids with curves
CreateGrids(curves);
return errorCount;
}
#endregion
}
}
CreateRadialAndArcGridsForm.cs
//
// (C) Copyright 2003-2019 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
namespace Revit.SDK.Samples.GridCreation.CS
{
/// <summary>
/// The dialog which provides the options of creating radial and arc grids
/// </summary>
partial class CreateRadialAndArcGridsForm
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.textBoxArcSpacing = new System.Windows.Forms.TextBox();
this.label6 = new System.Windows.Forms.Label();
this.groupBox3 = new System.Windows.Forms.GroupBox();
this.labelUnitFirstRadius = new System.Windows.Forms.Label();
this.labelUnitX = new System.Windows.Forms.Label();
this.textBoxArcFirstRadius = new System.Windows.Forms.TextBox();
this.comboBoxArcBubbleLocation = new System.Windows.Forms.ComboBox();
this.label10 = new System.Windows.Forms.Label();
this.textBoxArcFirstLabel = new System.Windows.Forms.TextBox();
this.textBoxArcNumber = new System.Windows.Forms.TextBox();
this.label9 = new System.Windows.Forms.Label();
this.label5 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.textBoxYCoord = new System.Windows.Forms.TextBox();
this.textBoxXCoord = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.labelUnitY = new System.Windows.Forms.Label();
this.textBoxLineFirstDistance = new System.Windows.Forms.TextBox();
this.comboBoxLineBubbleLocation = new System.Windows.Forms.ComboBox();
this.label11 = new System.Windows.Forms.Label();
this.textBoxLineNumber = new System.Windows.Forms.TextBox();
this.textBoxLineFirstLabel = new System.Windows.Forms.TextBox();
this.label13 = new System.Windows.Forms.Label();
this.label12 = new System.Windows.Forms.Label();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.labelYCoordUnit = new System.Windows.Forms.Label();
this.labelXCoordUnit = new System.Windows.Forms.Label();
this.buttonCancel = new System.Windows.Forms.Button();
this.buttonCreate = new System.Windows.Forms.Button();
this.groupBox4 = new System.Windows.Forms.GroupBox();
this.textBoxEndDegree = new System.Windows.Forms.TextBox();
this.textBoxStartDegree = new System.Windows.Forms.TextBox();
this.labelEndDegree = new System.Windows.Forms.Label();
this.labelStartDegree = new System.Windows.Forms.Label();
this.radioButtonCustomize = new System.Windows.Forms.RadioButton();
this.radioButton360 = new System.Windows.Forms.RadioButton();
this.groupBox3.SuspendLayout();
this.groupBox2.SuspendLayout();
this.groupBox1.SuspendLayout();
this.groupBox4.SuspendLayout();
this.SuspendLayout();
//
// textBoxArcSpacing
//
this.textBoxArcSpacing.Location = new System.Drawing.Point(132, 17);
this.textBoxArcSpacing.Name = "textBoxArcSpacing";
this.textBoxArcSpacing.Size = new System.Drawing.Size(108, 20);
this.textBoxArcSpacing.TabIndex = 0;
this.textBoxArcSpacing.Tag = "10.0";
this.textBoxArcSpacing.Text = 10.0.ToString("0.0");
//
// label6
//
this.label6.Location = new System.Drawing.Point(13, 20);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(113, 18);
this.label6.TabIndex = 6;
this.label6.Text = "Spacing:";
//
// groupBox3
//
this.groupBox3.Controls.Add(this.labelUnitFirstRadius);
this.groupBox3.Controls.Add(this.labelUnitX);
this.groupBox3.Controls.Add(this.textBoxArcFirstRadius);
this.groupBox3.Controls.Add(this.comboBoxArcBubbleLocation);
this.groupBox3.Controls.Add(this.label10);
this.groupBox3.Controls.Add(this.textBoxArcFirstLabel);
this.groupBox3.Controls.Add(this.textBoxArcNumber);
this.groupBox3.Controls.Add(this.label9);
this.groupBox3.Controls.Add(this.textBoxArcSpacing);
this.groupBox3.Controls.Add(this.label5);
this.groupBox3.Controls.Add(this.label3);
this.groupBox3.Controls.Add(this.label6);
this.groupBox3.Location = new System.Drawing.Point(12, 175);
this.groupBox3.Name = "groupBox3";
this.groupBox3.Size = new System.Drawing.Size(544, 116);
this.groupBox3.TabIndex = 2;
this.groupBox3.TabStop = false;
this.groupBox3.Text = "Arc Grids";
//
// labelUnitFirstRadius
//
this.labelUnitFirstRadius.Location = new System.Drawing.Point(240, 52);
this.labelUnitFirstRadius.Name = "labelUnitFirstRadius";
this.labelUnitFirstRadius.Size = new System.Drawing.Size(23, 23);
this.labelUnitFirstRadius.TabIndex = 31;
//
// labelUnitX
//
this.labelUnitX.Location = new System.Drawing.Point(240, 20);
this.labelUnitX.Name = "labelUnitX";
this.labelUnitX.Size = new System.Drawing.Size(23, 23);
this.labelUnitX.TabIndex = 13;
//
// textBoxArcFirstRadius
//
this.textBoxArcFirstRadius.Location = new System.Drawing.Point(132, 50);
this.textBoxArcFirstRadius.Name = "textBoxArcFirstRadius";
this.textBoxArcFirstRadius.Size = new System.Drawing.Size(108, 20);
this.textBoxArcFirstRadius.TabIndex = 2;
this.textBoxArcFirstRadius.Text = 10.0.ToString("0.0");
//
// comboBoxArcBubbleLocation
//
this.comboBoxArcBubbleLocation.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxArcBubbleLocation.FormattingEnabled = true;
this.comboBoxArcBubbleLocation.Items.AddRange(new object[] {
"At start point of arcs",
"At end point of arcs"});
this.comboBoxArcBubbleLocation.Location = new System.Drawing.Point(133, 83);
this.comboBoxArcBubbleLocation.Name = "comboBoxArcBubbleLocation";
this.comboBoxArcBubbleLocation.Size = new System.Drawing.Size(373, 21);
this.comboBoxArcBubbleLocation.TabIndex = 4;
//
// label10
//
this.label10.Location = new System.Drawing.Point(13, 52);
this.label10.Name = "label10";
this.label10.Size = new System.Drawing.Size(113, 18);
this.label10.TabIndex = 7;
this.label10.Text = "Radius of first grid:";
//
// textBoxArcFirstLabel
//
this.textBoxArcFirstLabel.Location = new System.Drawing.Point(398, 50);
this.textBoxArcFirstLabel.Name = "textBoxArcFirstLabel";
this.textBoxArcFirstLabel.Size = new System.Drawing.Size(108, 20);
this.textBoxArcFirstLabel.TabIndex = 3;
this.textBoxArcFirstLabel.Tag = "";
this.textBoxArcFirstLabel.Text = "1";
//
// textBoxArcNumber
//
this.textBoxArcNumber.Location = new System.Drawing.Point(398, 17);
this.textBoxArcNumber.Name = "textBoxArcNumber";
this.textBoxArcNumber.Size = new System.Drawing.Size(108, 20);
this.textBoxArcNumber.TabIndex = 1;
this.textBoxArcNumber.Text = "3";
//
// label9
//
this.label9.Location = new System.Drawing.Point(279, 52);
this.label9.Name = "label9";
this.label9.Size = new System.Drawing.Size(113, 18);
this.label9.TabIndex = 30;
this.label9.Text = "Label of first grid:";
//
// label5
//
this.label5.Location = new System.Drawing.Point(13, 85);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(113, 18);
this.label5.TabIndex = 29;
this.label5.Text = "Bubble location:";
//
// label3
//
this.label3.Location = new System.Drawing.Point(279, 20);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(113, 18);
this.label3.TabIndex = 6;
this.label3.Text = "Number:";
//
// label4
//
this.label4.Location = new System.Drawing.Point(279, 23);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(113, 18);
this.label4.TabIndex = 6;
this.label4.Text = "Number:";
//
// textBoxYCoord
//
this.textBoxYCoord.Location = new System.Drawing.Point(398, 22);
this.textBoxYCoord.Name = "textBoxYCoord";
this.textBoxYCoord.Size = new System.Drawing.Size(108, 20);
this.textBoxYCoord.TabIndex = 1;
this.textBoxYCoord.Text = "0";
//
// textBoxXCoord
//
this.textBoxXCoord.Location = new System.Drawing.Point(132, 21);
this.textBoxXCoord.Name = "textBoxXCoord";
this.textBoxXCoord.Size = new System.Drawing.Size(108, 20);
this.textBoxXCoord.TabIndex = 0;
this.textBoxXCoord.Text = "0";
//
// label2
//
this.label2.Location = new System.Drawing.Point(279, 25);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(113, 18);
this.label2.TabIndex = 0;
this.label2.Text = "Y coordinate:";
//
// label1
//
this.label1.Location = new System.Drawing.Point(13, 25);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(112, 18);
this.label1.TabIndex = 0;
this.label1.Text = "X coordinate:";
//
// groupBox2
//
this.groupBox2.Controls.Add(this.labelUnitY);
this.groupBox2.Controls.Add(this.textBoxLineFirstDistance);
this.groupBox2.Controls.Add(this.comboBoxLineBubbleLocation);
this.groupBox2.Controls.Add(this.label11);
this.groupBox2.Controls.Add(this.textBoxLineNumber);
this.groupBox2.Controls.Add(this.textBoxLineFirstLabel);
this.groupBox2.Controls.Add(this.label13);
this.groupBox2.Controls.Add(this.label4);
this.groupBox2.Controls.Add(this.label12);
this.groupBox2.Location = new System.Drawing.Point(13, 297);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(543, 119);
this.groupBox2.TabIndex = 3;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "Radial Grids";
//
// labelUnitY
//
this.labelUnitY.Location = new System.Drawing.Point(508, 88);
this.labelUnitY.Name = "labelUnitY";
this.labelUnitY.Size = new System.Drawing.Size(23, 23);
this.labelUnitY.TabIndex = 13;
//
// textBoxLineFirstDistance
//
this.textBoxLineFirstDistance.Location = new System.Drawing.Point(236, 86);
this.textBoxLineFirstDistance.Name = "textBoxLineFirstDistance";
this.textBoxLineFirstDistance.Size = new System.Drawing.Size(270, 20);
this.textBoxLineFirstDistance.TabIndex = 3;
this.textBoxLineFirstDistance.Text = 8.0.ToString("0.0");
//
// comboBoxLineBubbleLocation
//
this.comboBoxLineBubbleLocation.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxLineBubbleLocation.FormattingEnabled = true;
this.comboBoxLineBubbleLocation.Items.AddRange(new object[] {
"At start point of lines",
"At end point of lines"});
this.comboBoxLineBubbleLocation.Location = new System.Drawing.Point(131, 54);
this.comboBoxLineBubbleLocation.Name = "comboBoxLineBubbleLocation";
this.comboBoxLineBubbleLocation.Size = new System.Drawing.Size(374, 21);
this.comboBoxLineBubbleLocation.TabIndex = 2;
//
// label11
//
this.label11.Location = new System.Drawing.Point(6, 88);
this.label11.Name = "label11";
this.label11.Size = new System.Drawing.Size(224, 18);
this.label11.TabIndex = 7;
this.label11.Text = "Distance from origin to start point:";
//
// textBoxLineNumber
//
this.textBoxLineNumber.Location = new System.Drawing.Point(398, 23);
this.textBoxLineNumber.Name = "textBoxLineNumber";
this.textBoxLineNumber.Size = new System.Drawing.Size(108, 20);
this.textBoxLineNumber.TabIndex = 1;
this.textBoxLineNumber.Tag = "3";
this.textBoxLineNumber.Text = "3";
//
// textBoxLineFirstLabel
//
this.textBoxLineFirstLabel.Location = new System.Drawing.Point(131, 20);
this.textBoxLineFirstLabel.Name = "textBoxLineFirstLabel";
this.textBoxLineFirstLabel.Size = new System.Drawing.Size(108, 20);
this.textBoxLineFirstLabel.TabIndex = 0;
this.textBoxLineFirstLabel.Tag = "A";
this.textBoxLineFirstLabel.Text = "A";
//
// label13
//
this.label13.Location = new System.Drawing.Point(6, 23);
this.label13.Name = "label13";
this.label13.Size = new System.Drawing.Size(119, 18);
this.label13.TabIndex = 30;
this.label13.Text = "Label of first grid:";
//
// label12
//
this.label12.Location = new System.Drawing.Point(6, 57);
this.label12.Name = "label12";
this.label12.Size = new System.Drawing.Size(119, 18);
this.label12.TabIndex = 29;
this.label12.Text = "Bubble location:";
//
// groupBox1
//
this.groupBox1.Controls.Add(this.textBoxYCoord);
this.groupBox1.Controls.Add(this.labelYCoordUnit);
this.groupBox1.Controls.Add(this.labelXCoordUnit);
this.groupBox1.Controls.Add(this.textBoxXCoord);
this.groupBox1.Controls.Add(this.label2);
this.groupBox1.Controls.Add(this.label1);
this.groupBox1.Location = new System.Drawing.Point(13, 12);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(543, 55);
this.groupBox1.TabIndex = 0;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Center of Arc Grids";
//
// labelYCoordUnit
//
this.labelYCoordUnit.Location = new System.Drawing.Point(508, 22);
this.labelYCoordUnit.Name = "labelYCoordUnit";
this.labelYCoordUnit.Size = new System.Drawing.Size(23, 23);
this.labelYCoordUnit.TabIndex = 13;
//
// labelXCoordUnit
//
this.labelXCoordUnit.Location = new System.Drawing.Point(240, 24);
this.labelXCoordUnit.Name = "labelXCoordUnit";
this.labelXCoordUnit.Size = new System.Drawing.Size(23, 23);
this.labelXCoordUnit.TabIndex = 13;
//
// buttonCancel
//
this.buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.buttonCancel.Location = new System.Drawing.Point(463, 436);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(94, 23);
this.buttonCancel.TabIndex = 5;
this.buttonCancel.Text = "&Cancel";
this.buttonCancel.UseVisualStyleBackColor = true;
//
// buttonCreate
//
this.buttonCreate.DialogResult = System.Windows.Forms.DialogResult.OK;
this.buttonCreate.Location = new System.Drawing.Point(356, 436);
this.buttonCreate.Name = "buttonCreate";
this.buttonCreate.Size = new System.Drawing.Size(94, 23);
this.buttonCreate.TabIndex = 4;
this.buttonCreate.Text = "Create &Grids";
this.buttonCreate.UseVisualStyleBackColor = true;
this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click);
//
// groupBox4
//
this.groupBox4.Controls.Add(this.textBoxEndDegree);
this.groupBox4.Controls.Add(this.textBoxStartDegree);
this.groupBox4.Controls.Add(this.labelEndDegree);
this.groupBox4.Controls.Add(this.labelStartDegree);
this.groupBox4.Controls.Add(this.radioButtonCustomize);
this.groupBox4.Controls.Add(this.radioButton360);
this.groupBox4.Location = new System.Drawing.Point(13, 74);
this.groupBox4.Name = "groupBox4";
this.groupBox4.Size = new System.Drawing.Size(543, 95);
this.groupBox4.TabIndex = 1;
this.groupBox4.TabStop = false;
this.groupBox4.Text = "Span of Grids";
//
// textBoxEndDegree
//
this.textBoxEndDegree.Location = new System.Drawing.Point(397, 62);
this.textBoxEndDegree.Name = "textBoxEndDegree";
this.textBoxEndDegree.Size = new System.Drawing.Size(108, 20);
this.textBoxEndDegree.TabIndex = 3;
this.textBoxEndDegree.Text = "360";
//
// textBoxStartDegree
//
this.textBoxStartDegree.Location = new System.Drawing.Point(131, 62);
this.textBoxStartDegree.Name = "textBoxStartDegree";
this.textBoxStartDegree.Size = new System.Drawing.Size(108, 20);
this.textBoxStartDegree.TabIndex = 2;
this.textBoxStartDegree.Text = "0";
//
// labelEndDegree
//
this.labelEndDegree.Location = new System.Drawing.Point(279, 64);
this.labelEndDegree.Name = "labelEndDegree";
this.labelEndDegree.Size = new System.Drawing.Size(113, 18);
this.labelEndDegree.TabIndex = 2;
this.labelEndDegree.Text = "End degree:";
//
// labelStartDegree
//
this.labelStartDegree.Location = new System.Drawing.Point(24, 64);
this.labelStartDegree.Name = "labelStartDegree";
this.labelStartDegree.Size = new System.Drawing.Size(101, 18);
this.labelStartDegree.TabIndex = 2;
this.labelStartDegree.Text = "Start degree:";
//
// radioButtonCustomize
//
this.radioButtonCustomize.Location = new System.Drawing.Point(9, 41);
this.radioButtonCustomize.Name = "radioButtonCustomize";
this.radioButtonCustomize.Size = new System.Drawing.Size(104, 24);
this.radioButtonCustomize.TabIndex = 1;
this.radioButtonCustomize.Text = "Customize";
this.radioButtonCustomize.UseVisualStyleBackColor = true;
this.radioButtonCustomize.CheckedChanged += new System.EventHandler(this.radioButtonCustomize_CheckedChanged);
//
// radioButton360
//
this.radioButton360.AutoSize = true;
this.radioButton360.Checked = true;
this.radioButton360.Location = new System.Drawing.Point(9, 20);
this.radioButton360.Name = "radioButton360";
this.radioButton360.Size = new System.Drawing.Size(79, 17);
this.radioButton360.TabIndex = 0;
this.radioButton360.TabStop = true;
this.radioButton360.Text = "360 degree";
this.radioButton360.UseVisualStyleBackColor = true;
this.radioButton360.MouseClick += new System.Windows.Forms.MouseEventHandler(this.radioButton360_MouseClick);
//
// CreateRadialAndArcGridsForm
//
this.AcceptButton = this.buttonCreate;
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.CancelButton = this.buttonCancel;
this.ClientSize = new System.Drawing.Size(568, 466);
this.Controls.Add(this.groupBox4);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonCreate);
this.Controls.Add(this.groupBox3);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.groupBox1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "CreateRadialAndArcGridsForm";
this.ShowIcon = false;
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Create Radial and Arc Grids";
this.groupBox3.ResumeLayout(false);
this.groupBox3.PerformLayout();
this.groupBox2.ResumeLayout(false);
this.groupBox2.PerformLayout();
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.groupBox4.ResumeLayout(false);
this.groupBox4.PerformLayout();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.TextBox textBoxArcSpacing;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.GroupBox groupBox3;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.TextBox textBoxYCoord;
private System.Windows.Forms.TextBox textBoxXCoord;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.TextBox textBoxLineNumber;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.TextBox textBoxArcNumber;
private System.Windows.Forms.Button buttonCancel;
private System.Windows.Forms.Button buttonCreate;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.GroupBox groupBox4;
private System.Windows.Forms.TextBox textBoxEndDegree;
private System.Windows.Forms.TextBox textBoxStartDegree;
private System.Windows.Forms.Label labelEndDegree;
private System.Windows.Forms.Label labelStartDegree;
private System.Windows.Forms.RadioButton radioButtonCustomize;
private System.Windows.Forms.RadioButton radioButton360;
private System.Windows.Forms.TextBox textBoxArcFirstRadius;
private System.Windows.Forms.Label label10;
private System.Windows.Forms.TextBox textBoxLineFirstDistance;
private System.Windows.Forms.Label label11;
private System.Windows.Forms.ComboBox comboBoxArcBubbleLocation;
private System.Windows.Forms.TextBox textBoxArcFirstLabel;
private System.Windows.Forms.Label label9;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.ComboBox comboBoxLineBubbleLocation;
private System.Windows.Forms.TextBox textBoxLineFirstLabel;
private System.Windows.Forms.Label label13;
private System.Windows.Forms.Label label12;
private System.Windows.Forms.Label labelUnitX;
private System.Windows.Forms.Label labelUnitY;
private System.Windows.Forms.Label labelUnitFirstRadius;
private System.Windows.Forms.Label labelYCoordUnit;
private System.Windows.Forms.Label labelXCoordUnit;
}
}
Unit.cs
//
// (C) Copyright 2003-2019 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
using System;
using System.Collections.Generic;
using System.Text;
using Autodesk.Revit;
using System.Configuration;
using System.Reflection;
using Autodesk.Revit.DB;
namespace Revit.SDK.Samples.GridCreation.CS
{
/// <summary>
/// Provides static functions to convert unit
/// </summary>
static class Unit
{
#region Methods
/// <summary>
/// Convert the value get from RevitAPI to the value indicated by DisplayUnitType
/// </summary>
/// <param name="to">DisplayUnitType indicates unit of target value</param>
/// <param name="value">value get from RevitAPI</param>
/// <returns>Target value</returns>
public static double CovertFromAPI(DisplayUnitType to, double value)
{
return value *= ImperialDutRatio(to);
}
/// <summary>
/// Convert a value indicated by DisplayUnitType to the value used by RevitAPI
/// </summary>
/// <param name="value">Value to be converted</param>
/// <param name="from">DisplayUnitType indicates the unit of the value to be converted</param>
/// <returns>Target value</returns>
public static double CovertToAPI(double value, DisplayUnitType from )
{
return value /= ImperialDutRatio(from);
}
/// <summary>
/// Get ratio between value in RevitAPI and value to display indicated by DisplayUnitType
/// </summary>
/// <param name="dut">DisplayUnitType indicates display unit type</param>
/// <returns>Ratio </returns>
private static double ImperialDutRatio(DisplayUnitType dut)
{
switch (dut)
{
case DisplayUnitType.DUT_DECIMAL_FEET: return 1;
case DisplayUnitType.DUT_FEET_FRACTIONAL_INCHES: return 1;
case DisplayUnitType.DUT_DECIMAL_INCHES: return 12;
case DisplayUnitType.DUT_FRACTIONAL_INCHES: return 12;
case DisplayUnitType.DUT_METERS: return 0.3048;
case DisplayUnitType.DUT_CENTIMETERS: return 30.48;
case DisplayUnitType.DUT_MILLIMETERS: return 304.8;
case DisplayUnitType.DUT_METERS_CENTIMETERS: return 0.3048;
default: return 1;
}
}
#endregion
}
}
EnumsAndValues.cs
//
// (C) Copyright 2003-2019 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
using System;
using System.Collections.Generic;
using System.Text;
namespace Revit.SDK.Samples.GridCreation.CS
{
/// <summary>
/// An enumerate type listing the ways to create grids.
/// </summary>
public enum CreateMode
{
/// <summary>
/// Create grids with selected lines/arcs
/// </summary>
Select,
/// <summary>
/// Create orthogonal grids
/// </summary>
Orthogonal,
/// <summary>
/// Create radial and arc grids
/// </summary>
RadialAndArc
}
/// <summary>
/// An enumerate type listing bubble locations of grids.
/// </summary>
public enum BubbleLocation
{
/// <summary>
/// Place bubble at the start point
/// </summary>
StartPoint,
/// <summary>
/// Place bubble at the end point
/// </summary>
EndPoint
}
/// <summary>
/// Class contains common const values
/// </summary>
static class Values
{
public const double PI = 3.1415926535897900;
// ratio from degree to radian
public const double DEGTORAD = PI / 180;
}
}
Validation.cs
//
// (C) Copyright 2003-2019 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Resources;
using System.Collections;
using Autodesk.Revit.UI;
namespace Revit.SDK.Samples.GridCreation.CS
{
/// <summary>
/// Class to validate input data before creating grids
/// </summary>
public static class Validation
{
// Get the resource contains strings
static ResourceManager resManager = Properties.Resources.ResourceManager;
/// <summary>
/// Validate numbers in UI
/// </summary>
/// <param name="number1Ctrl">Control contains number information</param>
/// <param name="number2Ctrl">Control contains another number information</param>
/// <returns>Whether the numbers are validated</returns>
public static bool ValidateNumbers(Control number1Ctrl, Control number2Ctrl)
{
if (!ValidateNumber(number1Ctrl) || !ValidateNumber(number2Ctrl))
{
return false;
}
if (Convert.ToUInt32(number1Ctrl.Text) == 0 && Convert.ToUInt32(number2Ctrl.Text) == 0)
{
ShowWarningMessage(resManager.GetString("NumbersCannotBeBothZero"),
Properties.Resources.ResourceManager.GetString("FailureCaptionInvalidValue"));
number1Ctrl.Focus();
return false;
}
return true;
}
/// <summary>
/// Validate number value
/// </summary>
/// <param name="numberCtrl">Control contains number information</param>
/// <returns>Whether the number value is validated</returns>
public static bool ValidateNumber(Control numberCtrl)
{
if (!ValidateNotNull(numberCtrl, "Number"))
{
return false;
}
try
{
uint number = Convert.ToUInt32(numberCtrl.Text);
if (number > 200)
{
ShowWarningMessage(resManager.GetString("NumberBetween0And200"),
Properties.Resources.ResourceManager.GetString("FailureCaptionInvalidValue"));
numberCtrl.Focus();
return false;
}
}
catch (OverflowException)
{
ShowWarningMessage(resManager.GetString("NumberBetween0And200"),
Properties.Resources.ResourceManager.GetString("FailureCaptionInvalidValue"));
numberCtrl.Focus();
return false;
}
catch (Exception)
{
ShowWarningMessage(resManager.GetString("NumberFormatWrong"),
Properties.Resources.ResourceManager.GetString("FailureCaptionInvalidValue"));
numberCtrl.Focus();
return false;
}
return true;
}
/// <summary>
/// Validate length value
/// </summary>
/// <param name="lengthCtrl">Control contains length information</param>
/// <param name="typeName">Type of length</param>
/// <param name="canBeZero">Whether the length can be zero</param>
/// <returns>Whether the length value is validated</returns>
public static bool ValidateLength(Control lengthCtrl, String typeName, bool canBeZero)
{
if (!ValidateNotNull(lengthCtrl, typeName))
{
return false;
}
try
{
double length = Convert.ToDouble(lengthCtrl.Text);
if (length <= 0 && !canBeZero)
{
ShowWarningMessage(resManager.GetString(typeName + "CannotBeNegativeOrZero"),
Properties.Resources.ResourceManager.GetString("FailureCaptionInvalidValue"));
lengthCtrl.Focus();
return false;
}
else if (length < 0 && canBeZero)
{
ShowWarningMessage(resManager.GetString(typeName + "CannotBeNegative"),
Properties.Resources.ResourceManager.GetString("FailureCaptionInvalidValue"));
lengthCtrl.Focus();
return false;
}
}
catch (Exception)
{
ShowWarningMessage(resManager.GetString(typeName + "FormatWrong"),
Properties.Resources.ResourceManager.GetString("FailureCaptionInvalidValue"));
lengthCtrl.Focus();
return false;
}
return true;
}
/// <summary>
/// Validate coordinate value
/// </summary>
/// <param name="coordCtrl">Control contains coordinate information</param>
/// <returns>Whether the coordinate value is validated</returns>
public static bool ValidateCoord(Control coordCtrl)
{
if (!ValidateNotNull(coordCtrl, "Coordinate"))
{
return false;
}
try
{
Convert.ToDouble(coordCtrl.Text);
}
catch (Exception)
{
ShowWarningMessage(resManager.GetString("CoordinateFormatWrong"),
Properties.Resources.ResourceManager.GetString("FailureCaptionInvalidValue"));
coordCtrl.Focus();
return false;
}
return true;
}
/// <summary>
/// Validate start degree and end degree
/// </summary>
/// <param name="startDegree">Control contains start degree information</param>
/// <param name="endDegree">Control contains end degree information</param>
/// <returns>Whether the degree values are validated</returns>
public static bool ValidateDegrees(Control startDegree, Control endDegree)
{
if (!ValidateDegree(startDegree) || !ValidateDegree(endDegree))
{
return false;
}
if (Math.Abs(Convert.ToDouble(startDegree.Text) - Convert.ToDouble(endDegree.Text)) <= Double.Epsilon)
{
ShowWarningMessage(resManager.GetString("DegreesAreTooClose"),
Properties.Resources.ResourceManager.GetString("FailureCaptionInvalidValue"));
startDegree.Focus();
return false;
}
if (Convert.ToDouble(startDegree.Text) >= Convert.ToDouble(endDegree.Text))
{
ShowWarningMessage(resManager.GetString("StartDegreeShouldBeLessThanEndDegree"),
Properties.Resources.ResourceManager.GetString("FailureCaptionInvalidValue"));
startDegree.Focus();
return false;
}
return true;
}
/// <summary>
/// Validate degree value
/// </summary>
/// <param name="degreeCtrl">Control contains degree information</param>
/// <returns>Whether the degree value is validated</returns>
public static bool ValidateDegree(Control degreeCtrl)
{
if (!ValidateNotNull(degreeCtrl, "Degree"))
{
return false;
}
try
{
double startDegree = Convert.ToDouble(degreeCtrl.Text);
if (startDegree < 0 || startDegree > 360)
{
ShowWarningMessage(resManager.GetString("DegreeWithin0To360"),
Properties.Resources.ResourceManager.GetString("FailureCaptionInvalidValue"));
degreeCtrl.Focus();
return false;
}
}
catch (Exception)
{
ShowWarningMessage(resManager.GetString("DegreeFormatWrong"),
Properties.Resources.ResourceManager.GetString("FailureCaptionInvalidValue"));
degreeCtrl.Focus();
return false;
}
return true;
}
/// <summary>
/// Validate label
/// </summary>
/// <param name="labelCtrl">Control contains label information</param>
/// <param name="allLabels">List contains all labels in Revit document</param>
/// <returns>Whether the label value is validated</returns>
public static bool ValidateLabel(Control labelCtrl, ArrayList allLabels)
{
if (!ValidateNotNull(labelCtrl, "Label"))
{
return false;
}
String labelToBeValidated = labelCtrl.Text;
foreach (String label in allLabels)
{
if (label == labelToBeValidated)
{
ShowWarningMessage(resManager.GetString("LabelExisted"),
Properties.Resources.ResourceManager.GetString("FailureCaptionInvalidValue"));
labelCtrl.Focus();
return false;
}
}
return true;
}
/// <summary>
/// Assure value is not null
/// </summary>
/// <param name="control">Control contains information needs to be checked</param>
/// <param name="typeName">Type of information</param>
/// <returns>Whether the value is not null</returns>
public static bool ValidateNotNull(Control control, String typeName)
{
if (String.IsNullOrEmpty(control.Text.TrimStart(' ').TrimEnd(' ')))
{
ShowWarningMessage(resManager.GetString(typeName + "CannotBeNull"),
Properties.Resources.ResourceManager.GetString("FailureCaptionInvalidValue"));
control.Focus();
return false;
}
return true;
}
/// <summary>
/// Assure two labels are not same
/// </summary>
/// <param name="label1Ctrl">Control contains label information</param>
/// <param name="label2Ctrl">Control contains label information</param>
/// <returns>Whether the labels are same</returns>
public static bool ValidateLabels(Control label1Ctrl, Control label2Ctrl)
{
if (label1Ctrl.Text.TrimStart(' ').TrimEnd(' ') == label2Ctrl.Text.TrimStart(' ').TrimEnd(' '))
{
ShowWarningMessage(resManager.GetString("LabelsCannotBeSame"),
Properties.Resources.ResourceManager.GetString("FailureCaptionInvalidValue"));
label1Ctrl.Focus();
return false;
}
return true;
}
/// <summary>
/// Show a warning message box
/// </summary>
/// <param name="message">Message</param>
/// <param name="caption">title of message box</param>
public static void ShowWarningMessage(String message, String caption)
{
TaskDialog.Show(caption, message, TaskDialogCommonButtons.Ok);
}
}
}
版权所有 :无锡模信建筑科技有限公司 苏ICP备2021028830号-1 BIM建模|BIM技术应用|BIM软件开发
联系地址:江苏省无锡市新吴区龙山路4号B座705 手机:18761516598