Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added analytical components #1208

Merged
merged 10 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/RhinoInside.Revit.GH/Components/Element/Parameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ internal static IGH_Goo AsGoo(this ARDB.Parameter parameter)
case ARDB.BuiltInParameter.VIEW_DETAIL_LEVEL: return new Types.ViewDetailLevel((ARDB.ViewDetailLevel) integer);
case ARDB.BuiltInParameter.VIEW_DISCIPLINE: return new Types.ViewDiscipline((ARDB.ViewDiscipline) integer);
case ARDB.BuiltInParameter.HOST_SSE_CURVED_EDGE_CONDITION_PARAM: return new Types.SlabShapeEditCurvedEdgeCondition((ERDB.SlabShapeEditCurvedEdgeCondition) integer);
#if REVIT_2023
case ARDB.BuiltInParameter.ANALYTICAL_ELEMENT_STRUCTURAL_ROLE: return new Types.AnalyticalStructuralRole((ARDB.Structure.AnalyticalStructuralRole) integer);
#endif
}

if (builtInParameter.IsColor())
Expand Down
185 changes: 185 additions & 0 deletions src/RhinoInside.Revit.GH/Components/Structure/AddAnalyticalMember.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
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.27")]
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 =
{
#if REVIT_2023
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)
)
#endif
};

protected override ParamDefinition[] Outputs => outputs;
static readonly ParamDefinition[] outputs =
{
#if REVIT_2023
new ParamDefinition
(
new Parameters.AnalyticalMember()
{
Name = _AnalyticalMember_,
NickName = _AnalyticalMember_.Substring(0, 1),
Description = $"Output {_AnalyticalMember_}",
}
)
#endif
};

const string _AnalyticalMember_ = "Analytical Member";
static readonly ARDB.BuiltInParameter[] ExcludeUniqueProperties =
{
#if REVIT_2023
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
#endif
};

protected override void TrySolveInstance(IGH_DataAccess DA)
{
#if REVIT_2023
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;
}
);
#endif
}
#if REVIT_2023
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;
}
#endif
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
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.27")]
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 =
{
#if REVIT_2023
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)
)
#endif
};

protected override ParamDefinition[] Outputs => outputs;
static readonly ParamDefinition[] outputs =
{
#if REVIT_2023
new ParamDefinition
(
new Parameters.AnalyticalPanel()
{
Name = _AnalyticalPanel_,
NickName = _AnalyticalPanel_.Substring(0, 1),
Description = $"Output {_AnalyticalPanel_}",
}
)
#endif
};

const string _AnalyticalPanel_ = "Analytical Panel";

static readonly ARDB.BuiltInParameter[] ExcludeUniqueProperties =
{
#if REVIT_2023
ARDB.BuiltInParameter.STRUCTURAL_ANALYZES_AS,
ARDB.BuiltInParameter.ANALYTICAL_ELEMENT_STRUCTURAL_ROLE,
ARDB.BuiltInParameter.ANALYTICAL_PANEL_THICKNESS
#endif
};

protected override void TrySolveInstance(IGH_DataAccess DA)
{
#if REVIT_2023
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;
}
);
#endif
}
#if REVIT_2023
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;
}
#endif
}
}
Loading
Loading