mirror of
https://github.com/jeremytammik/RevitSdkSamples.git
synced 2026-10-03 23:47:57 +00:00
updated to Revit 2023 SDK
This commit is contained in:
@@ -42,7 +42,6 @@
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<CodeAnalysisRuleSet />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
@@ -61,8 +60,7 @@
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>
|
||||
</CodeAnalysisRuleSet>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<RunPostBuildEvent>OnOutputUpdated</RunPostBuildEvent>
|
||||
|
||||
@@ -49,8 +49,8 @@ namespace Revit.SDK.Samples.BoundaryConditions.CS
|
||||
|
||||
// store all the corresponding BCs of the current selected host element
|
||||
// and use the BC Id value as the key
|
||||
private Dictionary<int, Autodesk.Revit.DB.Structure.BoundaryConditions> m_bCsDictionary =
|
||||
new Dictionary<int, Autodesk.Revit.DB.Structure.BoundaryConditions>();
|
||||
private Dictionary<Autodesk.Revit.DB.ElementId, Autodesk.Revit.DB.Structure.BoundaryConditions> m_bCsDictionary =
|
||||
new Dictionary<Autodesk.Revit.DB.ElementId, Autodesk.Revit.DB.Structure.BoundaryConditions>();
|
||||
|
||||
// the object for which the grid in UI displays.
|
||||
private BCProperties m_bCProperties;
|
||||
@@ -88,7 +88,7 @@ namespace Revit.SDK.Samples.BoundaryConditions.CS
|
||||
/// <summary>
|
||||
/// get all the BCs correspond with current host
|
||||
/// </summary>
|
||||
public Dictionary<int, Autodesk.Revit.DB.Structure.BoundaryConditions> BCs
|
||||
public Dictionary<Autodesk.Revit.DB.ElementId, Autodesk.Revit.DB.Structure.BoundaryConditions> BCs
|
||||
{
|
||||
get
|
||||
{
|
||||
@@ -177,7 +177,7 @@ namespace Revit.SDK.Samples.BoundaryConditions.CS
|
||||
}
|
||||
|
||||
// add the created Boundary Conditions into m_bCsDictionary
|
||||
m_bCsDictionary.Add(NewBC.Id.IntegerValue, NewBC);
|
||||
m_bCsDictionary.Add(NewBC.Id, NewBC);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -195,84 +195,101 @@ namespace Revit.SDK.Samples.BoundaryConditions.CS
|
||||
IEnumerable<Autodesk.Revit.DB.Structure.BoundaryConditions> boundaryConditions = from elem in
|
||||
new FilteredElementCollector(doc).OfClass(typeof(Autodesk.Revit.DB.Structure.BoundaryConditions)).ToElements()
|
||||
let bC = elem as Autodesk.Revit.DB.Structure.BoundaryConditions
|
||||
where bC != null && m_hostElement.Id.IntegerValue == bC.HostElement.Id.IntegerValue
|
||||
where bC != null && m_hostElement.Id == bC.HostElementId
|
||||
select bC;
|
||||
foreach (Autodesk.Revit.DB.Structure.BoundaryConditions bC in boundaryConditions)
|
||||
{
|
||||
m_bCsDictionary.Add(bC.Id.IntegerValue, bC);
|
||||
m_bCsDictionary.Add(bC.Id, bC);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a new Point BoundaryConditions Element.
|
||||
/// All the parameter default as Fixed.
|
||||
/// </summary>
|
||||
/// <param name="hostElement">
|
||||
/// structural element which provide the analytical line end reference
|
||||
/// </param>
|
||||
/// <returns> the created Point BoundaryConditions Element</returns>
|
||||
private Autodesk.Revit.DB.Structure.BoundaryConditions CreatePointBC(Autodesk.Revit.DB.Element hostElement)
|
||||
{
|
||||
if (!(hostElement is FamilyInstance))
|
||||
AnalyticalElement GetAnalyticalElement(Autodesk.Revit.DB.Element element)
|
||||
{
|
||||
AnalyticalElement analyticalModel = null;
|
||||
Document document = element.Document;
|
||||
AnalyticalToPhysicalAssociationManager assocManager = AnalyticalToPhysicalAssociationManager.GetAnalyticalToPhysicalAssociationManager(document);
|
||||
if (assocManager != null)
|
||||
{
|
||||
ElementId associatedElementId = assocManager.GetAssociatedElementId(element.Id);
|
||||
if (associatedElementId != ElementId.InvalidElementId)
|
||||
{
|
||||
return null;
|
||||
Element associatedElement = document.GetElement(associatedElementId);
|
||||
if (associatedElement != null && associatedElement is AnalyticalElement)
|
||||
{
|
||||
analyticalModel = associatedElement as AnalyticalElement;
|
||||
}
|
||||
}
|
||||
}
|
||||
return analyticalModel;
|
||||
}
|
||||
|
||||
FamilyInstance familyInstance = hostElement as FamilyInstance;
|
||||
AnalyticalModel analyticalModel = familyInstance.GetAnalyticalModel();
|
||||
Reference endReference = null;
|
||||
/// <summary>
|
||||
/// Create a new Point BoundaryConditions Element.
|
||||
/// All the parameter default as Fixed.
|
||||
/// </summary>
|
||||
/// <param name="hostElement">
|
||||
/// structural element which provide the analytical line end reference
|
||||
/// </param>
|
||||
/// <returns> the created Point BoundaryConditions Element</returns>
|
||||
private Autodesk.Revit.DB.Structure.BoundaryConditions CreatePointBC(Autodesk.Revit.DB.Element hostElement)
|
||||
{
|
||||
if (!(hostElement is FamilyInstance))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
FamilyInstance familyInstance = hostElement as FamilyInstance;
|
||||
AnalyticalElement analyticalModel = GetAnalyticalElement(hostElement);
|
||||
Reference endReference = null;
|
||||
|
||||
Curve refCurve = analyticalModel.GetCurve();
|
||||
if (null != refCurve)
|
||||
{
|
||||
Curve refCurve = analyticalModel.GetCurve();
|
||||
if (null != refCurve)
|
||||
{
|
||||
|
||||
endReference = analyticalModel.GetReference(new AnalyticalModelSelector(refCurve,AnalyticalCurveSelector.EndPoint));
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
endReference = analyticalModel.GetReference(new AnalyticalModelSelector(refCurve, AnalyticalCurveSelector.EndPoint));
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
Autodesk.Revit.Creation.Document createDoc = hostElement.Document.Create;
|
||||
Autodesk.Revit.Creation.Document createDoc = hostElement.Document.Create;
|
||||
|
||||
// invoke Document.NewPointBoundaryConditions Method
|
||||
Autodesk.Revit.DB.Structure.BoundaryConditions createdBC =
|
||||
createDoc.NewPointBoundaryConditions(endReference, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
||||
return createdBC;
|
||||
}
|
||||
// invoke Document.NewPointBoundaryConditions Method
|
||||
Autodesk.Revit.DB.Structure.BoundaryConditions createdBC =
|
||||
createDoc.NewPointBoundaryConditions(endReference, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
||||
return createdBC;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a new Line BoundaryConditions Element.
|
||||
/// All the parameter default as Fixed.
|
||||
/// </summary>
|
||||
/// <param name="hostElement">structural element which provide the hostElementId</param>
|
||||
/// <returns>the created Point BoundaryConditions Element</returns>
|
||||
private Autodesk.Revit.DB.Structure.BoundaryConditions CreateLineBC(Autodesk.Revit.DB.Element hostElement)
|
||||
/// <summary>
|
||||
/// Create a new Line BoundaryConditions Element.
|
||||
/// All the parameter default as Fixed.
|
||||
/// </summary>
|
||||
/// <param name="hostElement">structural element which provide the hostElementId</param>
|
||||
/// <returns>the created Point BoundaryConditions Element</returns>
|
||||
private Autodesk.Revit.DB.Structure.BoundaryConditions CreateLineBC(Autodesk.Revit.DB.Element hostElement)
|
||||
{
|
||||
Autodesk.Revit.Creation.Document createDoc = hostElement.Document.Create;
|
||||
// invoke Document.NewLineBoundaryConditions Method
|
||||
AnalyticalElement analyticalModel = GetAnalyticalElement(hostElement);
|
||||
Autodesk.Revit.DB.Structure.BoundaryConditions createdBC =
|
||||
createDoc.NewLineBoundaryConditions(analyticalModel, 0, 0, 0, 0, 0, 0, 0, 0);
|
||||
return createdBC;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a new Area BoundaryConditions Element.
|
||||
/// All the parameter default as Fixed.
|
||||
/// </summary>
|
||||
/// <param name="hostElement">structural element which provide the hostElementId</param>
|
||||
/// <returns>the created Point BoundaryConditions Element</returns>
|
||||
private Autodesk.Revit.DB.Structure.BoundaryConditions CreateAreaBC(Autodesk.Revit.DB.Element hostElement)
|
||||
{
|
||||
Autodesk.Revit.Creation.Document createDoc = hostElement.Document.Create;
|
||||
|
||||
// invoke Document.NewLineBoundaryConditions Method
|
||||
Autodesk.Revit.DB.Structure.BoundaryConditions createdBC =
|
||||
createDoc.NewLineBoundaryConditions(hostElement.GetAnalyticalModel(), 0, 0, 0, 0, 0, 0, 0, 0);
|
||||
|
||||
return createdBC;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a new Area BoundaryConditions Element.
|
||||
/// All the parameter default as Fixed.
|
||||
/// </summary>
|
||||
/// <param name="hostElement">structural element which provide the hostElementId</param>
|
||||
/// <returns>the created Point BoundaryConditions Element</returns>
|
||||
private Autodesk.Revit.DB.Structure.BoundaryConditions CreateAreaBC(Autodesk.Revit.DB.Element hostElement)
|
||||
{
|
||||
Autodesk.Revit.Creation.Document createDoc = hostElement.Document.Create;
|
||||
|
||||
// invoke Document.NewAreaBoundaryConditions Method
|
||||
Autodesk.Revit.DB.Structure.BoundaryConditions createdBC =
|
||||
createDoc.NewAreaBoundaryConditions(hostElement.GetAnalyticalModel(), 0, 0, 0, 0, 0, 0);
|
||||
|
||||
return createdBC;
|
||||
// invoke Document.NewAreaBoundaryConditions Method
|
||||
Autodesk.Revit.DB.Structure.BoundaryConditions createdBC =
|
||||
createDoc.NewAreaBoundaryConditions(GetAnalyticalElement(hostElement), 0, 0, 0, 0, 0, 0);
|
||||
return createdBC;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -58,7 +58,7 @@ namespace Revit.SDK.Samples.BoundaryConditions.CS
|
||||
private void BoundaryConditionsForm_Load(object sender, EventArgs e)
|
||||
{
|
||||
// display host element id in the text box
|
||||
hostTextBox.Text = m_dataBuffer.HostElement.Id.IntegerValue.ToString();
|
||||
hostTextBox.Text = m_dataBuffer.HostElement.Id.ToString();
|
||||
|
||||
// if the selected element has not a BC, create one and display the default parameter values
|
||||
// else list the BC ids in the combox and display the first BC's parameter values
|
||||
@@ -83,7 +83,7 @@ namespace Revit.SDK.Samples.BoundaryConditions.CS
|
||||
|
||||
// list the boundary conditions Id values to the combobox
|
||||
System.Collections.ICollection bCIdValues = m_dataBuffer.BCs.Keys;
|
||||
foreach (int bCIdValue in bCIdValues)
|
||||
foreach (Autodesk.Revit.DB.ElementId bCIdValue in bCIdValues)
|
||||
{
|
||||
bCComboBox.Items.Add(bCIdValue);
|
||||
}
|
||||
@@ -99,7 +99,7 @@ namespace Revit.SDK.Samples.BoundaryConditions.CS
|
||||
private void bCComboBox_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
// create a BCProperties instance according to current selected BC Id
|
||||
m_dataBuffer.BCProperties = new BCProperties(m_dataBuffer.BCs[int.Parse(bCComboBox.Text)]);
|
||||
m_dataBuffer.BCProperties = new BCProperties(m_dataBuffer.BCs[Autodesk.Revit.DB.ElementId.Parse(bCComboBox.Text)]);
|
||||
|
||||
// set the display object
|
||||
bCPropertyGrid.SelectedObject = m_dataBuffer.BCProperties;
|
||||
|
||||
@@ -25,6 +25,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using System.Linq;
|
||||
|
||||
using Autodesk.Revit;
|
||||
using Autodesk.Revit.DB;
|
||||
@@ -127,32 +128,44 @@ namespace Revit.SDK.Samples.BoundaryConditions.CS
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// the selected element must be a structural Column/brace/Beam/Wall/Wall Foundation/Slab/Foundation Slab.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private bool IsExpectedElement(Element element)
|
||||
{
|
||||
|
||||
// judge the element's type. If it is any type of FamilyInstance, Wall, Floor or
|
||||
// WallFoundation, then get judge if it has a AnalyticalModel.
|
||||
if (null == element.GetAnalyticalModel())
|
||||
/// <summary>
|
||||
/// the selected element must be a structural Column/brace/Beam/Wall/Wall Foundation/Slab/Foundation Slab.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private bool IsExpectedElement(Element element)
|
||||
{
|
||||
// judge the element's type. If it is any type of FamilyInstance, Wall, Floor or
|
||||
// WallFoundation, then get judge if it has a AnalyticalModel.
|
||||
AnalyticalToPhysicalAssociationManager assocManager = AnalyticalToPhysicalAssociationManager.GetAnalyticalToPhysicalAssociationManager(element.Document);
|
||||
AnalyticalElement elemAnalytical = null;
|
||||
if (assocManager != null)
|
||||
{
|
||||
ElementId associatedElementId = assocManager.GetAssociatedElementId(element.Id);
|
||||
if (associatedElementId != ElementId.InvalidElementId)
|
||||
{
|
||||
return false;
|
||||
Element associatedElement = element.Document.GetElement(associatedElementId);
|
||||
if (associatedElement != null && associatedElement is AnalyticalElement)
|
||||
{
|
||||
elemAnalytical = associatedElement as AnalyticalElement;
|
||||
}
|
||||
}
|
||||
|
||||
FamilyInstance familyInstance = element as FamilyInstance;
|
||||
if ((null != familyInstance) && (StructuralType.Footing == familyInstance.StructuralType))
|
||||
{
|
||||
return false; // if selected a isolated foundation not create BC
|
||||
}
|
||||
|
||||
if (element is FamilyInstance || element is Wall || element is Floor || element is WallFoundation)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
if (null == elemAnalytical)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
FamilyInstance familyInstance = element as FamilyInstance;
|
||||
if ((null != familyInstance) && (StructuralType.Footing == familyInstance.StructuralType))
|
||||
{
|
||||
return false; // if selected a isolated foundation not create BC
|
||||
}
|
||||
|
||||
if (element is FamilyInstance || element is Wall || element is Floor || element is WallFoundation)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user