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

Mep section methods support added #192

Merged
merged 1 commit into from
Nov 23, 2023
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
2 changes: 2 additions & 0 deletions RevitLookup/Core/ComponentModel/DescriptorMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.ExtensibleStorage;
using Autodesk.Revit.DB.ExternalService;
using Autodesk.Revit.DB.Mechanical;
using Autodesk.Windows;
using RevitLookup.Core.ComponentModel.Descriptors;
using RevitLookup.Core.Objects;
Expand Down Expand Up @@ -77,6 +78,7 @@ public static Descriptor FindDescriptor(object obj, Type type)
PrintManager value when type is null || type == typeof(PrintManager) => new PrintManagerDescriptor(value),
DefinitionGroup value when type is null || type == typeof(DefinitionGroup) => new DefinitionGroupDescriptor(value),
FamilyManager value when type is null || type == typeof(FamilyManager) => new FamilyManagerDescriptor(value),
MEPSection value when type is null || type == typeof(MEPSection) => new MepSectionDescriptor(value),
APIObject when type is null || type == typeof(APIObject) => new ApiObjectDescriptor(),

//IDisposables
Expand Down
102 changes: 102 additions & 0 deletions RevitLookup/Core/ComponentModel/Descriptors/MepSectionDescriptor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
// Copyright 2003-$File.CreatedYear 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.Reflection;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Mechanical;
using RevitLookup.Core.Contracts;
using RevitLookup.Core.Objects;
using ArgumentException = Autodesk.Revit.Exceptions.ArgumentException;

namespace RevitLookup.Core.ComponentModel.Descriptors;

public class MepSectionDescriptor : Descriptor, IDescriptorResolver
{
private MEPSection _mepSection;
public MepSectionDescriptor(MEPSection mepSection)
{
_mepSection = mepSection;
}
public ResolveSet Resolve(Document context, string target, ParameterInfo[] parameters)
{
return target switch
{
nameof(MEPSection.GetElementIds) => ResolveSectionIds(),
nameof(MEPSection.GetCoefficient) => ResolveCoefficient(),
nameof(MEPSection.GetPressureDrop) => ResolvePressureDrop(),
nameof(MEPSection.GetSegmentLength) => ResolveSegmentLength(),
_ => null
};

ResolveSet ResolveSectionIds()
{
var elementIds = _mepSection.GetElementIds();
var resolveSummary = new ResolveSet(elementIds.Count);
foreach (var id in elementIds)
{
resolveSummary.AppendVariant(id);
}
return resolveSummary;
}
ResolveSet ResolveCoefficient()
{
var elementIds = _mepSection.GetElementIds();
var resolveSummary = new ResolveSet(elementIds.Count);
foreach (var id in elementIds)
{
resolveSummary.AppendVariant(_mepSection.GetCoefficient(id), $"{id}");
}
return resolveSummary;
}

ResolveSet ResolvePressureDrop()
{
var elementIds = _mepSection.GetElementIds();
var resolveSummary = new ResolveSet(elementIds.Count);
foreach (var id in elementIds)
{
resolveSummary.AppendVariant(_mepSection.GetPressureDrop(id), $"{id}");
}
return resolveSummary;
}

ResolveSet ResolveSegmentLength()
{
var elementIds = _mepSection.GetElementIds();
var resolveSummary = new ResolveSet(elementIds.Count);
foreach (var id in elementIds)
{
var length = 0.0d;
try
{
length = _mepSection.GetSegmentLength(id);
}
catch (ArgumentException)
{
// ignored
}
if (length != 0.0d) resolveSummary.AppendVariant(length, $"{id}");
}
return resolveSummary;
}
}


}
Loading