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

Dev macro manager #268

Merged
merged 9 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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.Macros;
using Autodesk.Revit.DB.Lighting;
using Autodesk.Revit.DB.Mechanical;
using Autodesk.Revit.DB.Plumbing;
Expand Down Expand Up @@ -58,6 +59,7 @@ public static Descriptor FindDescriptor(object obj, Type type)
//System
string value when type is null || type == typeof(string) => new StringDescriptor(value),
bool value when type is null || type == typeof(bool) => new BoolDescriptor(value),
MacroManager value when type is null || type == typeof(MacroManager) => new MacroManagerDescriptor(value),
IEnumerable value => new EnumerableDescriptor(value),
Exception value when type is null || type == typeof(Exception) => new ExceptionDescriptor(value),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,25 @@
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.

using Autodesk.Revit.DB.Macros;
using RevitLookup.Core.Contracts;

Check warning on line 22 in source/RevitLookup/Core/ComponentModel/Descriptors/ApplicationDescriptor.cs

View workflow job for this annotation

GitHub Actions / qodana

Redundant using directive

Using directive is not required by the code and can be safely removed
using RevitLookup.Core.Objects;

Check warning on line 23 in source/RevitLookup/Core/ComponentModel/Descriptors/ApplicationDescriptor.cs

View workflow job for this annotation

GitHub Actions / qodana

Redundant using directive

Using directive is not required by the code and can be safely removed

namespace RevitLookup.Core.ComponentModel.Descriptors;

public sealed class ApplicationDescriptor : Descriptor, IDescriptorExtension
{
private readonly Autodesk.Revit.ApplicationServices.Application _application;
public ApplicationDescriptor(Autodesk.Revit.ApplicationServices.Application application)
{
Name = application.VersionName;
_application = application;
}

public void RegisterExtensions(IExtensionManager manager)
{
manager.Register("GetFormulaFunctions", _ => FormulaManager.GetFunctions());
manager.Register("GetFormulaOperators", _ => FormulaManager.GetOperators());
manager.Register(nameof(MacroManager.GetMacroManager), _ => Variants.Single(MacroManager.GetMacroManager(_application)));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

u can remove Variants.Single for extensions

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
#if REVIT2023_OR_GREATER
using Autodesk.Revit.DB.Structure;
#endif
#if !REVIT2025_OR_GREATER
using Autodesk.Revit.DB.Macros;
#endif

namespace RevitLookup.Core.ComponentModel.Descriptors;

Expand Down Expand Up @@ -78,6 +81,9 @@ public void RegisterExtensions(IExtensionManager manager)
{
manager.Register(nameof(GlobalParametersManager.GetAllGlobalParameters), GlobalParametersManager.GetAllGlobalParameters);
manager.Register(nameof(LightGroupManager.GetLightGroupManager), LightGroupManager.GetLightGroupManager);
#if !REVIT2025_OR_GREATER
manager.Register(nameof(MacroManager.GetMacroManager), MacroManager.GetMacroManager);
#endif
#if REVIT2022_OR_GREATER
manager.Register(nameof(TemporaryGraphicsManager.GetTemporaryGraphicsManager), TemporaryGraphicsManager.GetTemporaryGraphicsManager);
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using System.Collections;
using System.Reflection;
using Autodesk.Revit.DB.Electrical;
using Autodesk.Revit.DB.Macros;

namespace RevitLookup.Core.ComponentModel.Descriptors;

Expand All @@ -36,6 +37,7 @@ public EnumerableDescriptor(IEnumerable value)
IsEmpty = value switch
{
string => true,
MacroManager enumerable => enumerable.Count == 0,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move it to the very bottom. In the top position you should insert frequently used types to increase the efficiency of resolving switching cases

IVariants enumerable => enumerable.Count == 0,
ICollection enumerable => enumerable.Count == 0,
ParameterSet enumerable => enumerable.IsEmpty,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// 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.Collections;
using System.Reflection;
using Autodesk.Revit.DB.Macros;

namespace RevitLookup.Core.ComponentModel.Descriptors;

public class MacroManagerDescriptor(MacroManager macroManager) : Descriptor, IDescriptorResolver
{
public Func<IVariants> Resolve(Document context, string target, ParameterInfo[] parameters)
{
return target switch
{
#if !REVIT2025_OR_GREATER
nameof(MacroManager.GetDocumentMacroSecurityOptions) => ResolveDocumentMacroSecurityOptions,
#endif
nameof(MacroManager.GetApplicationMacroSecurityOptions) => ResolveApplicationMacroSecurityOptions,
nameof(IEnumerable.GetEnumerator) => ResolveGetEnumerator,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GetEnumerator should be automatically resolved, what problem does using it in a Resolve method solve?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had some problems with it but resolved it. We really don't need this, I removed


_ => null
};

IVariants ResolveApplicationMacroSecurityOptions()
{
return Variants.Single(MacroManager.GetApplicationMacroSecurityOptions(Context.Application));
}
#if !REVIT2025_OR_GREATER
IVariants ResolveDocumentMacroSecurityOptions()
{
return Variants.Single(MacroManager.GetDocumentMacroSecurityOptions(Context.Application));
}
#endif
IVariants ResolveGetEnumerator()
{
using var enumerator = macroManager.GetEnumerator();
return Variants.Single<IEnumerator>(enumerator);
}
}
}
1 change: 1 addition & 0 deletions source/RevitLookup/RevitLookup.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
<PackageReference Include="Nice3point.Revit.Api.RevitAPI" Version="$(RevitVersion).*"/>
<PackageReference Include="Nice3point.Revit.Api.AdWindows" Version="$(RevitVersion).*"/>
<PackageReference Include="Nice3point.Revit.Api.RevitAPIUI" Version="$(RevitVersion).*"/>
<PackageReference Include="Nice3point.Revit.Api.RevitAPIMacros" Version="$(RevitVersion).*"/>
<PackageReference Include="Nice3point.Revit.Api.UIFramework" Version="$(RevitVersion).*"/>
<PackageReference Include="Nice3point.Revit.Api.UIFrameworkServices" Version="$(RevitVersion).*"/>

Expand Down
Loading