-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added analytical member and panels components
- Loading branch information
1 parent
0f0ebc6
commit 043bd79
Showing
9 changed files
with
733 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
175 changes: 175 additions & 0 deletions
175
src/RhinoInside.Revit.GH/Components/Structure/AddAnalyticalMember.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
using System; | ||
using Grasshopper.Kernel; | ||
using Grasshopper.Kernel.Parameters; | ||
using RhinoInside.Revit.Convert.Geometry; | ||
using RhinoInside.Revit.External.DB.Extensions; | ||
using Rhino.Geometry; | ||
using ARDB = Autodesk.Revit.DB; | ||
using RhinoInside.Revit.GH.Parameters; | ||
|
||
namespace RhinoInside.Revit.GH.Components.Structure | ||
{ | ||
|
||
#if REVIT_2023 | ||
using ARDB_Structure_AnalyticalMember = ARDB.Structure.AnalyticalMember; | ||
#else | ||
using ARDB_Structure_AnalyticalMember = ARDB.Structure.AnalyticalModelStick; | ||
#endif | ||
|
||
[ComponentVersion(introduced: "1.26")] | ||
public class AddAnalyticalMember : ElementTrackerComponent | ||
{ | ||
public override Guid ComponentGuid => new Guid("88AD5522-B3AD-4A67-AB96-3D90249BA215"); | ||
public override GH_Exposure Exposure => GH_Exposure.secondary; | ||
public AddAnalyticalMember() : base | ||
( | ||
name: "Add Analytical Member", | ||
nickname: "A-Member", | ||
description: "Given its location curve, it adds an analytical member to the active Revit document", | ||
category: "Revit", | ||
subCategory: "Structure" | ||
) | ||
{ } | ||
|
||
protected override ParamDefinition[] Inputs => inputs; | ||
static readonly ParamDefinition[] inputs = | ||
{ | ||
new ParamDefinition | ||
( | ||
new Parameters.Document() | ||
{ | ||
Name = "Document", | ||
NickName = "DOC", | ||
Description = "Document", | ||
Optional = true | ||
}, ParamRelevance.Occasional | ||
), | ||
new ParamDefinition | ||
( | ||
new Param_Curve() | ||
{ | ||
Name = "Curve", | ||
NickName = "C", | ||
Description = "Analytical member location", | ||
Access = GH_ParamAccess.item | ||
} | ||
), | ||
new ParamDefinition | ||
( | ||
new Param_Enum<Types.AnalyticalStructuralRole> | ||
{ | ||
Name = "Structural Role", | ||
NickName = "R", | ||
Description = "Analytical member structural role", | ||
Access = GH_ParamAccess.item, | ||
Optional = true, | ||
}.SetDefaultVale(ARDB.Structure.AnalyticalStructuralRole.StructuralRoleMember) | ||
) | ||
}; | ||
|
||
protected override ParamDefinition[] Outputs => outputs; | ||
static readonly ParamDefinition[] outputs = | ||
{ | ||
new ParamDefinition | ||
( | ||
new Parameters.AnalyticalMember() | ||
{ | ||
Name = _AnalyticalMember_, | ||
NickName = _AnalyticalMember_.Substring(0, 1), | ||
Description = $"Output {_AnalyticalMember_}", | ||
} | ||
) | ||
}; | ||
|
||
const string _AnalyticalMember_ = "Analytical Member"; | ||
static readonly ARDB.BuiltInParameter[] ExcludeUniqueProperties = | ||
{ | ||
ARDB.BuiltInParameter.STRUCTURAL_SECTION_SHAPE, | ||
ARDB.BuiltInParameter.STRUCTURAL_ANALYZES_AS, | ||
ARDB.BuiltInParameter.ANALYTICAL_ELEMENT_STRUCTURAL_ROLE, | ||
ARDB.BuiltInParameter.ANALYTICAL_MEMBER_ROTATION, | ||
ARDB.BuiltInParameter.ANALYTICAL_MEMBER_SECTION_TYPE | ||
}; | ||
|
||
protected override void TrySolveInstance(IGH_DataAccess DA) | ||
{ | ||
if (!Parameters.Document.TryGetDocumentOrCurrent(this, DA, "Document", out var doc) || !doc.IsValid) return; | ||
|
||
ReconstructElement<ARDB_Structure_AnalyticalMember> | ||
( | ||
doc.Value, _AnalyticalMember_, analyticalMember => | ||
{ | ||
var tol = GeometryTolerance.Model; | ||
|
||
// Input | ||
if (!Params.GetData(DA, "Curve", out Curve curve)) return null; | ||
if (!Params.GetData(DA, "Structural Role", out Types.AnalyticalStructuralRole structuralRole)) return null; | ||
|
||
// Compute | ||
analyticalMember = Reconstruct | ||
( | ||
analyticalMember, | ||
doc.Value, | ||
curve, | ||
structuralRole.Value | ||
); | ||
|
||
DA.SetData(_AnalyticalMember_, analyticalMember); | ||
return analyticalMember; | ||
} | ||
); | ||
} | ||
|
||
bool Reuse | ||
( | ||
ARDB_Structure_AnalyticalMember analyticalMember, | ||
Curve curve, | ||
ARDB.Structure.AnalyticalStructuralRole structuralRole | ||
) | ||
{ | ||
if (analyticalMember is null) return false; | ||
|
||
if ( analyticalMember.StructuralRole != structuralRole) | ||
analyticalMember.StructuralRole = structuralRole; | ||
|
||
using (var loc = analyticalMember.GetCurve() as ARDB.Curve) | ||
{ | ||
if (!loc.IsSameKindAs(curve.ToCurve())) | ||
return false; | ||
|
||
if (!loc.AlmostEquals(curve.ToCurve(), analyticalMember.Document.Application.VertexTolerance)) | ||
analyticalMember.SetCurve(curve.ToCurve()); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
ARDB_Structure_AnalyticalMember Create(ARDB.Document doc, ARDB.Curve curve, ARDB.Structure.AnalyticalStructuralRole structuralRole) | ||
{ | ||
ARDB_Structure_AnalyticalMember analyticalMember = ARDB_Structure_AnalyticalMember.Create(doc, curve); | ||
analyticalMember.StructuralRole = structuralRole; | ||
return analyticalMember; | ||
} | ||
|
||
ARDB_Structure_AnalyticalMember Reconstruct | ||
( | ||
ARDB_Structure_AnalyticalMember analyticalMember, | ||
ARDB.Document doc, | ||
Curve curve, | ||
ARDB.Structure.AnalyticalStructuralRole structuralRole | ||
) | ||
{ | ||
if (!Reuse(analyticalMember, curve, structuralRole)) | ||
{ | ||
analyticalMember = analyticalMember.ReplaceElement | ||
( | ||
Create(doc, curve.ToCurve(), structuralRole), | ||
ExcludeUniqueProperties | ||
); | ||
analyticalMember.Document.Regenerate(); | ||
} | ||
|
||
return analyticalMember; | ||
} | ||
} | ||
} |
188 changes: 188 additions & 0 deletions
188
src/RhinoInside.Revit.GH/Components/Structure/AddAnalyticalPanelByBoundary.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,188 @@ | ||
using System; | ||
using Grasshopper.Kernel; | ||
using Grasshopper.Kernel.Parameters; | ||
using RhinoInside.Revit.Convert.Geometry; | ||
using RhinoInside.Revit.External.DB.Extensions; | ||
using Rhino.Geometry; | ||
using ARDB = Autodesk.Revit.DB; | ||
using System.Collections.Generic; | ||
using RhinoInside.Revit.GH.Exceptions; | ||
using RhinoInside.Revit.Convert.System.Collections.Generic; | ||
using System.Linq; | ||
using RhinoInside.Revit.GH.Parameters; | ||
|
||
namespace RhinoInside.Revit.GH.Components.Structure | ||
{ | ||
#if REVIT_2023 | ||
using ARDB_Structure_AnalyticalPanel = ARDB.Structure.AnalyticalPanel; | ||
#else | ||
using ARDB_Structure_AnalyticalPanel = ARDB.Structure.AnalyticalModelSurface; | ||
#endif | ||
|
||
[ComponentVersion(introduced: "1.26")] | ||
public class AddAnalyticalPanelByBoundary : ElementTrackerComponent | ||
{ | ||
public override Guid ComponentGuid => new Guid("BA2D1733-0A7A-463C-BDDC-4262405F4FE6"); | ||
public override GH_Exposure Exposure => GH_Exposure.secondary; | ||
public AddAnalyticalPanelByBoundary() : base | ||
( | ||
name: "Add Analytical Panel By Boundary", | ||
nickname: "A-BoundaryPanel", | ||
description: "Given its boundary, it adds an analytical panel to the active Revit document", | ||
category: "Revit", | ||
subCategory: "Structure" | ||
) | ||
{ } | ||
|
||
protected override ParamDefinition[] Inputs => inputs; | ||
static readonly ParamDefinition[] inputs = | ||
{ | ||
new ParamDefinition | ||
( | ||
new Parameters.Document() | ||
{ | ||
Name = "Document", | ||
NickName = "DOC", | ||
Description = "Document", | ||
Optional = true | ||
}, ParamRelevance.Occasional | ||
), | ||
new ParamDefinition | ||
( | ||
new Param_Curve() | ||
{ | ||
Name = "Boundary", | ||
NickName = "B", | ||
Description = "Analytical panel boundary profile", | ||
Access = GH_ParamAccess.list | ||
} | ||
), | ||
new ParamDefinition | ||
( | ||
new Param_Enum<Types.AnalyticalStructuralRole> | ||
{ | ||
Name = "Structural Role", | ||
NickName = "R", | ||
Description = "Analytical element structural role", | ||
Access = GH_ParamAccess.item, | ||
Optional = true, | ||
}.SetDefaultVale(ARDB.Structure.AnalyticalStructuralRole.StructuralRolePanel) | ||
) | ||
}; | ||
|
||
protected override ParamDefinition[] Outputs => outputs; | ||
static readonly ParamDefinition[] outputs = | ||
{ | ||
new ParamDefinition | ||
( | ||
new Parameters.AnalyticalPanel() | ||
{ | ||
Name = _AnalyticalPanel_, | ||
NickName = _AnalyticalPanel_.Substring(0, 1), | ||
Description = $"Output {_AnalyticalPanel_}", | ||
} | ||
) | ||
}; | ||
|
||
const string _AnalyticalPanel_ = "Analytical Panel"; | ||
|
||
static readonly ARDB.BuiltInParameter[] ExcludeUniqueProperties = | ||
{ | ||
ARDB.BuiltInParameter.STRUCTURAL_ANALYZES_AS, | ||
ARDB.BuiltInParameter.ANALYTICAL_ELEMENT_STRUCTURAL_ROLE, | ||
ARDB.BuiltInParameter.ANALYTICAL_PANEL_THICKNESS | ||
}; | ||
|
||
protected override void TrySolveInstance(IGH_DataAccess DA) | ||
{ | ||
if (!Parameters.Document.TryGetDocumentOrCurrent(this, DA, "Document", out var doc) || !doc.IsValid) return; | ||
|
||
ReconstructElement<ARDB_Structure_AnalyticalPanel> | ||
( | ||
doc.Value, _AnalyticalPanel_, analyticalPanel => | ||
{ | ||
|
||
// Input | ||
if (!Params.GetDataList(DA, "Boundary", out IList<Curve> boundary)) return null; | ||
if (!Params.GetData(DA, "Structural Role", out Types.AnalyticalStructuralRole structuralRole)) return null; | ||
|
||
var tol = GeometryTolerance.Model; | ||
for (int index = 0; index < boundary.Count; ++index) | ||
{ | ||
var loop = boundary[index]; | ||
if (loop is null) return null; | ||
var plane = default(Plane); | ||
if | ||
( | ||
loop.IsShort(tol.ShortCurveTolerance) || | ||
!loop.IsClosed || | ||
!loop.TryGetPlane(out plane, tol.VertexTolerance) | ||
) | ||
throw new RuntimeArgumentException(nameof(boundary), "Boundary loop curves should be a set of valid coplanar and closed curves.", boundary); | ||
|
||
boundary[index] = loop.Simplify(CurveSimplifyOptions.All & ~CurveSimplifyOptions.Merge, tol.VertexTolerance, tol.AngleTolerance) ?? loop; | ||
} | ||
|
||
// Compute | ||
analyticalPanel = Reconstruct | ||
( | ||
analyticalPanel, | ||
doc.Value, | ||
boundary | ||
); | ||
|
||
DA.SetData(_AnalyticalPanel_, analyticalPanel); | ||
return analyticalPanel; | ||
} | ||
); | ||
} | ||
|
||
bool Reuse | ||
( | ||
ARDB_Structure_AnalyticalPanel analyticalPanel, | ||
IList<Curve> boundary | ||
) | ||
{ | ||
if (analyticalPanel is null) return false; | ||
|
||
if (analyticalPanel.GetOuterContour() is null) return false; | ||
|
||
var curveLoop = boundary.ConvertAll(x => x.ToCurveLoop()).FirstOrDefault(); | ||
analyticalPanel.SetOuterContour(curveLoop); | ||
return true; | ||
} | ||
|
||
ARDB_Structure_AnalyticalPanel Create(ARDB.Document doc, IList<Curve> boundary) | ||
{ | ||
var curveLoop = boundary.ConvertAll(x => x.ToCurveLoop()).FirstOrDefault(); | ||
|
||
if (curveLoop is null) | ||
throw new ArgumentException("Failed to convert boundary curves to CurveLoop.", nameof(boundary)); | ||
|
||
ARDB_Structure_AnalyticalPanel analyticalPanel = ARDB_Structure_AnalyticalPanel.Create(doc, curveLoop); | ||
|
||
return analyticalPanel; | ||
} | ||
|
||
|
||
ARDB_Structure_AnalyticalPanel Reconstruct | ||
( | ||
ARDB_Structure_AnalyticalPanel analyticalPanel, | ||
ARDB.Document doc, | ||
IList<Curve> boundary | ||
) | ||
{ | ||
if (!Reuse(analyticalPanel, boundary)) | ||
{ | ||
analyticalPanel = analyticalPanel.ReplaceElement | ||
( | ||
Create(doc, boundary), | ||
ExcludeUniqueProperties | ||
); | ||
analyticalPanel.Document.Regenerate(); | ||
} | ||
|
||
return analyticalPanel; | ||
} | ||
} | ||
} |
Oops, something went wrong.