mirror of
https://github.com/jeremytammik/RevitSdkSamples.git
synced 2026-09-18 02:21:33 +00:00
replaced Revit 2020 SDK by Revit 2021 SDK
This commit is contained in:
@@ -78,7 +78,7 @@ namespace Revit.SDK.Samples.GridCreation.CS
|
||||
}
|
||||
|
||||
ArrayList labels = GetAllLabelsOfGrids(document);
|
||||
DisplayUnitType dut = GetLengthUnitType(document);
|
||||
ForgeTypeId unit = GetLengthUnitType(document);
|
||||
switch (gridCreationOption.CreateGridsMode)
|
||||
{
|
||||
case CreateMode.Select: // Create grids with selected lines/arcs
|
||||
@@ -98,7 +98,7 @@ namespace Revit.SDK.Samples.GridCreation.CS
|
||||
break;
|
||||
|
||||
case CreateMode.Orthogonal: // Create orthogonal grids
|
||||
CreateOrthogonalGridsData orthogonalData = new CreateOrthogonalGridsData(commandData.Application, dut, labels);
|
||||
CreateOrthogonalGridsData orthogonalData = new CreateOrthogonalGridsData(commandData.Application, unit, labels);
|
||||
using (CreateOrthogonalGridsForm orthogonalGridForm = new CreateOrthogonalGridsForm(orthogonalData))
|
||||
{
|
||||
result = orthogonalGridForm.ShowDialog();
|
||||
@@ -114,7 +114,7 @@ namespace Revit.SDK.Samples.GridCreation.CS
|
||||
break;
|
||||
|
||||
case CreateMode.RadialAndArc: // Create radial and arc grids
|
||||
CreateRadialAndArcGridsData radArcData = new CreateRadialAndArcGridsData(commandData.Application, dut, labels);
|
||||
CreateRadialAndArcGridsData radArcData = new CreateRadialAndArcGridsData(commandData.Application, unit, labels);
|
||||
using (CreateRadialAndArcGridsForm radArcForm = new CreateRadialAndArcGridsForm(radArcData))
|
||||
{
|
||||
result = radArcForm.ShowDialog();
|
||||
@@ -216,18 +216,18 @@ namespace Revit.SDK.Samples.GridCreation.CS
|
||||
/// </summary>
|
||||
/// <param name="document">Revit's document</param>
|
||||
/// <returns>Current length display unit type</returns>
|
||||
private static DisplayUnitType GetLengthUnitType(Document document)
|
||||
private static ForgeTypeId GetLengthUnitType(Document document)
|
||||
{
|
||||
UnitType unittype = UnitType.UT_Length;
|
||||
ForgeTypeId specTypeId = SpecTypeId.Length;
|
||||
Units projectUnit = document.GetUnits();
|
||||
try
|
||||
{
|
||||
Autodesk.Revit.DB.FormatOptions formatOption = projectUnit.GetFormatOptions(unittype);
|
||||
return formatOption.DisplayUnits;
|
||||
Autodesk.Revit.DB.FormatOptions formatOption = projectUnit.GetFormatOptions(specTypeId);
|
||||
return formatOption.GetUnitTypeId();
|
||||
}
|
||||
catch (System.Exception /*e*/)
|
||||
{
|
||||
return DisplayUnitType.DUT_DECIMAL_FEET;
|
||||
return UnitTypeId.Feet;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ namespace Revit.SDK.Samples.GridCreation.CS
|
||||
/// <summary>
|
||||
/// Current display unit type
|
||||
/// </summary>
|
||||
protected DisplayUnitType m_dut;
|
||||
protected ForgeTypeId m_unit;
|
||||
/// <summary>
|
||||
/// Resource manager
|
||||
/// </summary>
|
||||
@@ -69,11 +69,11 @@ namespace Revit.SDK.Samples.GridCreation.CS
|
||||
/// <summary>
|
||||
/// Current display unit type
|
||||
/// </summary>
|
||||
public DisplayUnitType Dut
|
||||
public ForgeTypeId Unit
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_dut;
|
||||
return m_unit;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,14 +108,14 @@ namespace Revit.SDK.Samples.GridCreation.CS
|
||||
/// </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)
|
||||
/// <param name="unit">Current length display unit type</param>
|
||||
public CreateGridsData(UIApplication application, ArrayList labels, ForgeTypeId unit)
|
||||
{
|
||||
m_revitDoc = application.ActiveUIDocument.Document;
|
||||
m_appCreator = application.Application.Create;
|
||||
m_docCreator = application.ActiveUIDocument.Document.Create;
|
||||
m_labelsList = labels;
|
||||
m_dut = dut;
|
||||
m_unit = unit;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -218,10 +218,10 @@ namespace Revit.SDK.Samples.GridCreation.CS
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <param name="application">Application object</param>
|
||||
/// <param name="dut">Current length display unit type</param>
|
||||
/// <param name="unit">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)
|
||||
public CreateOrthogonalGridsData(UIApplication application, ForgeTypeId unit, ArrayList labels)
|
||||
: base(application, labels, unit)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ namespace Revit.SDK.Samples.GridCreation.CS
|
||||
private void InitializeControls()
|
||||
{
|
||||
// Set length unit related labels
|
||||
String unit = Properties.Resources.ResourceManager.GetString(m_data.Dut.ToString());
|
||||
String unit = Properties.Resources.ResourceManager.GetString(m_data.Unit.TypeId);
|
||||
labelUnitX.Text = unit;
|
||||
labelUnitY.Text = unit;
|
||||
labelXCoordUnit.Text = unit;
|
||||
@@ -65,7 +65,7 @@ namespace Revit.SDK.Samples.GridCreation.CS
|
||||
|
||||
|
||||
// Set spacing values
|
||||
textBoxXSpacing.Text = Unit.CovertFromAPI(m_data.Dut, 10).ToString();
|
||||
textBoxXSpacing.Text = Unit.CovertFromAPI(m_data.Unit, 10).ToString();
|
||||
textBoxYSpacing.Text = textBoxXSpacing.Text;
|
||||
|
||||
// Set bubble locations to end point
|
||||
@@ -92,21 +92,21 @@ namespace Revit.SDK.Samples.GridCreation.CS
|
||||
/// </summary>
|
||||
private void SetData()
|
||||
{
|
||||
m_data.XOrigin = Unit.CovertToAPI(Convert.ToDouble(textBoxXCoord.Text), m_data.Dut);
|
||||
m_data.YOrigin = Unit.CovertToAPI(Convert.ToDouble(textBoxYCoord.Text), m_data.Dut);
|
||||
m_data.XOrigin = Unit.CovertToAPI(Convert.ToDouble(textBoxXCoord.Text), m_data.Unit);
|
||||
m_data.YOrigin = Unit.CovertToAPI(Convert.ToDouble(textBoxYCoord.Text), m_data.Unit);
|
||||
m_data.XNumber = Convert.ToUInt32(textBoxXNumber.Text);
|
||||
m_data.YNumber = Convert.ToUInt32(textBoxYNumber.Text);
|
||||
|
||||
if (Convert.ToUInt32(textBoxXNumber.Text) != 0)
|
||||
{
|
||||
m_data.XSpacing = Unit.CovertToAPI(Convert.ToDouble(textBoxXSpacing.Text), m_data.Dut);
|
||||
m_data.XSpacing = Unit.CovertToAPI(Convert.ToDouble(textBoxXSpacing.Text), m_data.Unit);
|
||||
m_data.XBubbleLoc = (BubbleLocation)comboBoxXBubbleLocation.SelectedIndex;
|
||||
m_data.XFirstLabel = textBoxXFirstLabel.Text;
|
||||
}
|
||||
|
||||
if (Convert.ToUInt32(textBoxYNumber.Text) != 0)
|
||||
{
|
||||
m_data.YSpacing = Unit.CovertToAPI(Convert.ToDouble(textBoxYSpacing.Text), m_data.Dut);
|
||||
m_data.YSpacing = Unit.CovertToAPI(Convert.ToDouble(textBoxYSpacing.Text), m_data.Unit);
|
||||
m_data.YBubbleLoc = (BubbleLocation)comboBoxYBubbleLocation.SelectedIndex;
|
||||
m_data.YFirstLabel = textBoxYFirstLabel.Text;
|
||||
}
|
||||
|
||||
@@ -269,10 +269,10 @@ namespace Revit.SDK.Samples.GridCreation.CS
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <param name="application">Application object</param>
|
||||
/// <param name="dut">Current length display unit type</param>
|
||||
/// <param name="unit">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)
|
||||
public CreateRadialAndArcGridsData(UIApplication application, ForgeTypeId unit, ArrayList labels)
|
||||
: base(application, labels, unit)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ namespace Revit.SDK.Samples.GridCreation.CS
|
||||
private void InitializeControls()
|
||||
{
|
||||
// Set length unit related labels
|
||||
String unit = Properties.Resources.ResourceManager.GetString(m_data.Dut.ToString());
|
||||
String unit = Properties.Resources.ResourceManager.GetString(m_data.Unit.TypeId);
|
||||
labelUnitX.Text = unit;
|
||||
labelUnitY.Text = unit;
|
||||
labelUnitFirstRadius.Text = unit;
|
||||
@@ -62,9 +62,9 @@ namespace Revit.SDK.Samples.GridCreation.CS
|
||||
labelYCoordUnit.Text = unit;
|
||||
|
||||
// Set length values
|
||||
textBoxArcSpacing.Text = Unit.CovertFromAPI(m_data.Dut, 10).ToString();
|
||||
textBoxArcSpacing.Text = Unit.CovertFromAPI(m_data.Unit, 10).ToString();
|
||||
textBoxArcFirstRadius.Text = textBoxArcSpacing.Text;
|
||||
textBoxLineFirstDistance.Text = Unit.CovertFromAPI(m_data.Dut, 8).ToString();
|
||||
textBoxLineFirstDistance.Text = Unit.CovertFromAPI(m_data.Unit, 8).ToString();
|
||||
|
||||
radioButton360.Checked = true;
|
||||
radioButtonCustomize.Checked = false;
|
||||
@@ -109,8 +109,8 @@ namespace Revit.SDK.Samples.GridCreation.CS
|
||||
/// </summary>
|
||||
private void SetData()
|
||||
{
|
||||
m_data.XOrigin = Unit.CovertToAPI(Convert.ToDouble(textBoxXCoord.Text), m_data.Dut);
|
||||
m_data.YOrigin = Unit.CovertToAPI(Convert.ToDouble(textBoxYCoord.Text), m_data.Dut);
|
||||
m_data.XOrigin = Unit.CovertToAPI(Convert.ToDouble(textBoxXCoord.Text), m_data.Unit);
|
||||
m_data.YOrigin = Unit.CovertToAPI(Convert.ToDouble(textBoxYCoord.Text), m_data.Unit);
|
||||
|
||||
if (radioButton360.Checked)
|
||||
{
|
||||
@@ -129,15 +129,15 @@ namespace Revit.SDK.Samples.GridCreation.CS
|
||||
|
||||
if (Convert.ToUInt32(textBoxArcNumber.Text) != 0)
|
||||
{
|
||||
m_data.ArcSpacing = Unit.CovertToAPI(Convert.ToDouble(textBoxArcSpacing.Text), m_data.Dut);
|
||||
m_data.ArcFirstRadius = Unit.CovertToAPI(Convert.ToDouble(textBoxArcFirstRadius.Text), m_data.Dut);
|
||||
m_data.ArcSpacing = Unit.CovertToAPI(Convert.ToDouble(textBoxArcSpacing.Text), m_data.Unit);
|
||||
m_data.ArcFirstRadius = Unit.CovertToAPI(Convert.ToDouble(textBoxArcFirstRadius.Text), m_data.Unit);
|
||||
m_data.ArcFirstBubbleLoc = (BubbleLocation)comboBoxArcBubbleLocation.SelectedIndex;
|
||||
m_data.ArcFirstLabel = textBoxArcFirstLabel.Text;
|
||||
}
|
||||
|
||||
if (Convert.ToUInt32(textBoxLineNumber.Text) != 0)
|
||||
{
|
||||
m_data.LineFirstDistance = Unit.CovertToAPI(Convert.ToDouble(textBoxLineFirstDistance.Text), m_data.Dut);
|
||||
m_data.LineFirstDistance = Unit.CovertToAPI(Convert.ToDouble(textBoxLineFirstDistance.Text), m_data.Unit);
|
||||
m_data.LineFirstBubbleLoc = (BubbleLocation)comboBoxLineBubbleLocation.SelectedIndex;
|
||||
m_data.LineFirstLabel = textBoxLineFirstLabel.Text;
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
<AssemblyName>GridCreation</AssemblyName>
|
||||
<StartupObject>
|
||||
</StartupObject>
|
||||
<TargetFrameworkVersion>v4.7</TargetFrameworkVersion>
|
||||
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
|
||||
<TargetFrameworkProfile />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
|
||||
@@ -39,46 +39,43 @@ namespace Revit.SDK.Samples.GridCreation.CS
|
||||
{
|
||||
#region Methods
|
||||
/// <summary>
|
||||
/// Convert the value get from RevitAPI to the value indicated by DisplayUnitType
|
||||
/// Convert the value get from RevitAPI to the value indicated by ForgeTypeId
|
||||
/// </summary>
|
||||
/// <param name="to">DisplayUnitType indicates unit of target value</param>
|
||||
/// <param name="to">ForgeTypeId 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)
|
||||
public static double CovertFromAPI(ForgeTypeId to, double value)
|
||||
{
|
||||
return value *= ImperialDutRatio(to);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert a value indicated by DisplayUnitType to the value used by RevitAPI
|
||||
/// Convert a value indicated by ForgeTypeId 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>
|
||||
/// <param name="from">ForgeTypeId indicates the unit of the value to be converted</param>
|
||||
/// <returns>Target value</returns>
|
||||
public static double CovertToAPI(double value, DisplayUnitType from )
|
||||
public static double CovertToAPI(double value, ForgeTypeId from )
|
||||
{
|
||||
return value /= ImperialDutRatio(from);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get ratio between value in RevitAPI and value to display indicated by DisplayUnitType
|
||||
/// Get ratio between value in RevitAPI and value to display indicated by ForgeTypeId
|
||||
/// </summary>
|
||||
/// <param name="dut">DisplayUnitType indicates display unit type</param>
|
||||
/// <param name="unit">ForgeTypeId indicates display unit type</param>
|
||||
/// <returns>Ratio </returns>
|
||||
private static double ImperialDutRatio(DisplayUnitType dut)
|
||||
private static double ImperialDutRatio(ForgeTypeId unit)
|
||||
{
|
||||
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;
|
||||
}
|
||||
if (unit == UnitTypeId.Feet) return 1;
|
||||
if (unit == UnitTypeId.FeetFractionalInches) return 1;
|
||||
if (unit == UnitTypeId.Inches) return 12;
|
||||
if (unit == UnitTypeId.FractionalInches) return 12;
|
||||
if (unit == UnitTypeId.Meters) return 0.3048;
|
||||
if (unit == UnitTypeId.Centimeters) return 30.48;
|
||||
if (unit == UnitTypeId.Millimeters) return 304.8;
|
||||
if (unit == UnitTypeId.MetersCentimeters) return 0.3048;
|
||||
return 1;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user