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

Add LightFamily support #266

Merged
merged 3 commits into from
Jul 14, 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
2 changes: 2 additions & 0 deletions source/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.Electrical;
using Autodesk.Revit.DB.ExtensibleStorage;
using Autodesk.Revit.DB.ExternalService;
using Autodesk.Revit.DB.Lighting;
using Autodesk.Revit.DB.Mechanical;
using Autodesk.Revit.DB.Plumbing;
using Autodesk.Revit.DB.Visual;
Expand Down Expand Up @@ -127,6 +128,7 @@ public static Descriptor FindDescriptor(object obj, Type type)
FailureMessage value when type is null || type == typeof(FailureMessage) => new FailureMessageDescriptor(value),
UpdaterInfo value when type is null || type == typeof(UpdaterInfo) => new UpdaterInfoDescriptor(value),
ExternalService value when type is null || type == typeof(ExternalService) => new ExternalServiceDescriptor(value),
LightFamily value when type is null || type == typeof(LightFamily) => new LightFamilyDescriptor(value),
RevitApplication value when type is null || type == typeof(RevitApplication) => new ApplicationDescriptor(value),
UIApplication when type is null || type == typeof(UIApplication) => new UiApplicationDescriptor(),
PerformanceAdviser value when type is null || type == typeof(PerformanceAdviser) => new PerformanceAdviserDescriptor(value),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@

using System.Reflection;
using Autodesk.Revit.DB.Lighting;
using RevitLookup.Core.Contracts;
using RevitLookup.Core.Objects;
#if REVIT2023_OR_GREATER
using Autodesk.Revit.DB.Structure;
#endif
using RevitLookup.Core.Contracts;
using RevitLookup.Core.Objects;

namespace RevitLookup.Core.ComponentModel.Descriptors;

Expand Down Expand Up @@ -87,13 +87,14 @@
manager.Register(nameof(AnalyticalToPhysicalAssociationManager.GetAnalyticalToPhysicalAssociationManager),
AnalyticalToPhysicalAssociationManager.GetAnalyticalToPhysicalAssociationManager);
#endif
if (_document.IsFamilyDocument)

Check notice on line 90 in source/RevitLookup/Core/ComponentModel/Descriptors/DocumentDescriptor.cs

View workflow job for this annotation

GitHub Actions / qodana

Invert 'if' statement to reduce nesting

Invert 'if' statement to reduce nesting
{
manager.Register(nameof(FamilySizeTableManager.GetFamilySizeTableManager), context =>
{
var familyTableId = new ElementId(BuiltInParameter.RBS_LOOKUP_TABLE_NAME);
return FamilySizeTableManager.GetFamilySizeTableManager(context, familyTableId);
});
manager.Register(nameof(LightFamily.GetLightFamily), LightFamily.GetLightFamily);
}

// Disabled: slow performance.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Copyright 2003-2024 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.Lighting;
using RevitLookup.Core.Contracts;
using RevitLookup.Core.Objects;

namespace RevitLookup.Core.ComponentModel.Descriptors;

public class LightFamilyDescriptor (LightFamily lightFamily) : Descriptor, IDescriptorResolver
{
public Func<IVariants> Resolve(Document context, string target, ParameterInfo[] parameters)
{
return target switch
{
nameof(LightFamily.GetLightTypeName) => ResolveLightTypeName,
nameof(LightFamily.GetLightType) => ResolveLightType,
_ => null
};

IVariants ResolveLightTypeName()
{
var capacity = lightFamily.GetNumberOfLightTypes();
var variants = new Variants<string>(capacity);
for (var i = 0; i < capacity; i++)
{
var name = lightFamily.GetLightTypeName(i);
variants.Add(name);
}

return variants;
}
IVariants ResolveLightType()
{
var capacity = lightFamily.GetNumberOfLightTypes();
var variants = new Variants<LightType>(capacity);
for (var i = 0; i < capacity; i++)
{
var type = lightFamily.GetLightType(i);
variants.Add(type, $"Index {i}");
}

return variants;
}
}
}
Loading