diff --git a/sources/RevitDBExplorer/Domain/DataModel/Members/Base/MemberOverride.cs b/sources/RevitDBExplorer/Domain/DataModel/Members/Base/MemberOverride.cs index 6885f370..88cb2152 100644 --- a/sources/RevitDBExplorer/Domain/DataModel/Members/Base/MemberOverride.cs +++ b/sources/RevitDBExplorer/Domain/DataModel/Members/Base/MemberOverride.cs @@ -26,7 +26,17 @@ public static IMemberOverride ByFunc(Expression() @@ -35,7 +45,7 @@ public static IMemberOverride ByFunc(Expression { var accessor = new MemberAccessorByFunc(compiledGetter); - //accessor.DefaultInvocation.Syntax = syntax; + accessor.DefaultInvocation.Syntax = syntax; return accessor; } }; diff --git a/sources/RevitDBExplorer/Domain/DataModel/Members/Base/MemberTemplate.cs b/sources/RevitDBExplorer/Domain/DataModel/Members/Base/MemberTemplate.cs index eae61036..8f8203d9 100644 --- a/sources/RevitDBExplorer/Domain/DataModel/Members/Base/MemberTemplate.cs +++ b/sources/RevitDBExplorer/Domain/DataModel/Members/Base/MemberTemplate.cs @@ -31,16 +31,37 @@ public bool CanBeUsedWith(object @object) } - public static ISnoopableMemberTemplate Create(Expression> getter, Func canBeUsed = null, MemberKind kind = MemberKind.StaticMethod) + public static ISnoopableMemberTemplate Create(Expression> getter, + Func canBeUsed = null, + MemberKind kind = MemberKind.StaticMethod) { var compiledGetter = getter.Compile(); var methodCallExpression = getter.Body as MethodCallExpression; var memberAccessor = new MemberAccessorByFunc(compiledGetter); - return Create(methodCallExpression.Method.DeclaringType, methodCallExpression.Method.Name, memberAccessor, canBeUsed, kind, () => RevitDocumentationReader.GetMethodComments(methodCallExpression.Method)); + memberAccessor.UniqueId = $"{typeof(TForType).Name}_{getter.GetUniqueId()}"; + + + return WithCustomAC(methodCallExpression.Method.DeclaringType, methodCallExpression.Method.Name, memberAccessor, canBeUsed, kind, () => RevitDocumentationReader.GetMethodComments(methodCallExpression.Method)); } - public static ISnoopableMemberTemplate Create(Type declaringType, string memberName, IAccessor memberAccessor, Func canBeUsed = null, MemberKind kind = MemberKind.StaticMethod, Func documentationFactoryMethod = null) + + + public static ISnoopableMemberTemplate WithCustomAC(Type declaringType, + string memberName, + IAccessor memberAccessor, + Func canBeUsed = null, + MemberKind kind = MemberKind.StaticMethod, + Func documentationFactoryMethod = null) { + if (string.IsNullOrEmpty(memberAccessor.UniqueId)) + { + memberAccessor.UniqueId= $"{typeof(TForType).Name}_{memberAccessor.GetType().Name}.{memberName}"; + } + if (string.IsNullOrEmpty(memberAccessor.DefaultInvocation.Syntax)) + { + + } + return new MemberTemplate() { Descriptor = new MemberDescriptor(typeof(TForType), kind, memberName, declaringType, memberAccessor, documentationFactoryMethod), diff --git a/sources/RevitDBExplorer/Domain/DataModel/Members/MemberAccessorFactory.cs b/sources/RevitDBExplorer/Domain/DataModel/Members/MemberAccessorFactory.cs index baa92916..f859c3b8 100644 --- a/sources/RevitDBExplorer/Domain/DataModel/Members/MemberAccessorFactory.cs +++ b/sources/RevitDBExplorer/Domain/DataModel/Members/MemberAccessorFactory.cs @@ -61,7 +61,7 @@ public static IAccessor CreateMemberAccessor(MethodInfo getMethod, MethodInfo se memberAccessor.UniqueId = getMethod.GetUniqueId(); if (string.IsNullOrEmpty(memberAccessor.DefaultInvocation.Syntax)) { - memberAccessor.DefaultInvocation.Syntax = getMethod.GenerateInvocation(); + memberAccessor.DefaultInvocation.Syntax = "item." + getMethod.GenerateInvocation(); } return memberAccessor; diff --git a/sources/RevitDBExplorer/Domain/DataModel/MembersOverrides/Document/Document.cs b/sources/RevitDBExplorer/Domain/DataModel/MembersOverrides/Document/Document.cs new file mode 100644 index 00000000..b8f1ac2d --- /dev/null +++ b/sources/RevitDBExplorer/Domain/DataModel/MembersOverrides/Document/Document.cs @@ -0,0 +1,17 @@ +using System.Collections.Generic; +using Autodesk.Revit.DB; +using RevitDBExplorer.Domain.DataModel.Members; +using RevitDBExplorer.Domain.DataModel.Members.Base; + +// (c) Revit Database Explorer https://github.com/NeVeSpl/RevitDBExplorer/blob/main/license.md + +namespace RevitDBExplorer.Domain.DataModel.MembersOverrides +{ + internal class Document_Overrides : IHaveMembersOverrides + { + public IEnumerable GetOverrides() => + [ + MemberOverride.ByFunc((doc, document) => Document.GetDocumentVersion(document)), + ]; + } +} diff --git a/sources/RevitDBExplorer/Domain/DataModel/MembersOverrides/HostObject/HostObject_FindInserts.cs b/sources/RevitDBExplorer/Domain/DataModel/MembersOverrides/HostObject/HostObject_FindInserts.cs index 90779238..621d59a1 100644 --- a/sources/RevitDBExplorer/Domain/DataModel/MembersOverrides/HostObject/HostObject_FindInserts.cs +++ b/sources/RevitDBExplorer/Domain/DataModel/MembersOverrides/HostObject/HostObject_FindInserts.cs @@ -15,7 +15,7 @@ internal class HostObject_FindInserts : MemberAccessorByFunc hostObject.FindInserts(true, true, true, true)) { - DefaultInvocation.Syntax = "FindInserts(true, true, true, true)"; + DefaultInvocation.Syntax = "item.FindInserts(true, true, true, true)"; } } } \ No newline at end of file diff --git a/sources/RevitDBExplorer/Domain/DataModel/MembersOverrides/Rebar/Rebar_GetCenterlineCurves.cs b/sources/RevitDBExplorer/Domain/DataModel/MembersOverrides/Rebar/Rebar_GetCenterlineCurves.cs index cda680c1..66de0183 100644 --- a/sources/RevitDBExplorer/Domain/DataModel/MembersOverrides/Rebar/Rebar_GetCenterlineCurves.cs +++ b/sources/RevitDBExplorer/Domain/DataModel/MembersOverrides/Rebar/Rebar_GetCenterlineCurves.cs @@ -18,7 +18,7 @@ internal class Rebar_GetCenterlineCurves : MemberAccessorByType, ICanCrea public Rebar_GetCenterlineCurves() { - DefaultInvocation.Syntax = "GetCenterlineCurves(false, true, false, MultiplanarOption.IncludeOnlyPlanarCurves, 0)"; + DefaultInvocation.Syntax = "item.GetCenterlineCurves(false, true, false, MultiplanarOption.IncludeOnlyPlanarCurves, 0)"; } diff --git a/sources/RevitDBExplorer/Domain/DataModel/MembersOverrides/Rebar/Rebar_GetTransformedCenterlineCurves.cs b/sources/RevitDBExplorer/Domain/DataModel/MembersOverrides/Rebar/Rebar_GetTransformedCenterlineCurves.cs index c149e20b..77b8b0af 100644 --- a/sources/RevitDBExplorer/Domain/DataModel/MembersOverrides/Rebar/Rebar_GetTransformedCenterlineCurves.cs +++ b/sources/RevitDBExplorer/Domain/DataModel/MembersOverrides/Rebar/Rebar_GetTransformedCenterlineCurves.cs @@ -19,7 +19,7 @@ internal class Rebar_GetTransformedCenterlineCurves : MemberAccessorByType GetTemplates() => [ - MemberTemplate.Create(typeof(BoundingBoxXYZ), "BoundingBoxIntersectsFilter", new BoundingBox_BoundingBoxIntersectsFilter(), kind: MemberKind.Extra), + MemberTemplate.WithCustomAC(typeof(BoundingBoxXYZ), "BoundingBoxIntersectsFilter", new BoundingBox_BoundingBoxIntersectsFilter(), kind: MemberKind.Extra, documentationFactoryMethod: () => new DocXml() { Summary ="TEST" }), ]; } } diff --git a/sources/RevitDBExplorer/Domain/DataModel/MembersTemplates/Document_Templates.cs b/sources/RevitDBExplorer/Domain/DataModel/MembersTemplates/Document_Templates.cs index a3ace4a7..1beb947c 100644 --- a/sources/RevitDBExplorer/Domain/DataModel/MembersTemplates/Document_Templates.cs +++ b/sources/RevitDBExplorer/Domain/DataModel/MembersTemplates/Document_Templates.cs @@ -11,8 +11,7 @@ namespace RevitDBExplorer.Domain.DataModel.MembersTemplates internal class Document_Templates : IHaveMemberTemplates { public IEnumerable GetTemplates() => - [ - MemberTemplate.Create((doc, target) => Document.GetDocumentVersion(target), kind: MemberKind.StaticMethod), + [ #if R2023_MIN MemberTemplate.Create((doc, target) => target.GetChangedElements(Guid.Empty), kind: MemberKind.Method), #endif diff --git a/sources/RevitDBExplorer/Domain/DataModel/MembersTemplates/Element_Templates.cs b/sources/RevitDBExplorer/Domain/DataModel/MembersTemplates/Element_Templates.cs index a5d10199..5e4d7cf5 100644 --- a/sources/RevitDBExplorer/Domain/DataModel/MembersTemplates/Element_Templates.cs +++ b/sources/RevitDBExplorer/Domain/DataModel/MembersTemplates/Element_Templates.cs @@ -22,13 +22,13 @@ public IEnumerable GetTemplates() => #if R2023_MIN MemberTemplate.Create((doc, target) => AnalyticalNodeData.GetAnalyticalNodeData(target), kind: MemberKind.StaticMethod, canBeUsed: x => x is ReferencePoint), - MemberTemplate.Create(typeof(AnalyticalToPhysicalAssociationManager), nameof(AnalyticalToPhysicalAssociationManager.HasAssociation), new AnalyticalToPhysicalAssociationManager_HasAssociation(), kind: MemberKind.AsArgument), - MemberTemplate.Create(typeof(AnalyticalToPhysicalAssociationManager), nameof(AnalyticalToPhysicalAssociationManager.GetAssociatedElementId), new AnalyticalToPhysicalAssociationManager_GetAssociatedElementId(), kind: MemberKind.AsArgument), + MemberTemplate.WithCustomAC(typeof(AnalyticalToPhysicalAssociationManager), nameof(AnalyticalToPhysicalAssociationManager.HasAssociation), new AnalyticalToPhysicalAssociationManager_HasAssociation(), kind: MemberKind.AsArgument), + MemberTemplate.WithCustomAC(typeof(AnalyticalToPhysicalAssociationManager), nameof(AnalyticalToPhysicalAssociationManager.GetAssociatedElementId), new AnalyticalToPhysicalAssociationManager_GetAssociatedElementId(), kind: MemberKind.AsArgument), #endif #if R2024_MIN MemberTemplate.Create((doc, target) => AnalyticalToPhysicalAssociationManager.IsAnalyticalElement(doc, target.Id), kind: MemberKind.StaticMethod), MemberTemplate.Create((doc, target) => AnalyticalToPhysicalAssociationManager.IsPhysicalElement(doc, target.Id), kind: MemberKind.StaticMethod), - MemberTemplate.Create(typeof(AnalyticalToPhysicalAssociationManager), nameof(AnalyticalToPhysicalAssociationManager.GetAssociatedElementIds), new AnalyticalToPhysicalAssociationManager_GetAssociatedElementIds(), kind: MemberKind.AsArgument), + MemberTemplate.WithCustomAC(typeof(AnalyticalToPhysicalAssociationManager), nameof(AnalyticalToPhysicalAssociationManager.GetAssociatedElementIds), new AnalyticalToPhysicalAssociationManager_GetAssociatedElementIds(), kind: MemberKind.AsArgument), #endif ]; } diff --git a/sources/RevitDBExplorer/Domain/DataModel/MembersTemplates/HostObject_Templates.cs b/sources/RevitDBExplorer/Domain/DataModel/MembersTemplates/HostObject_Templates.cs index 4658326d..9f047f85 100644 --- a/sources/RevitDBExplorer/Domain/DataModel/MembersTemplates/HostObject_Templates.cs +++ b/sources/RevitDBExplorer/Domain/DataModel/MembersTemplates/HostObject_Templates.cs @@ -14,7 +14,7 @@ public IEnumerable GetTemplates() => [ MemberTemplate.Create((doc, target) => HostObjectUtils.GetTopFaces(target), kind: MemberKind.StaticMethod), MemberTemplate.Create((doc, target) => HostObjectUtils.GetBottomFaces(target), kind: MemberKind.StaticMethod), - MemberTemplate.Create(typeof(HostObjectUtils), "GetSideFaces", new HostObjectUtils_GetSideFaces(), kind: MemberKind.StaticMethod ), + MemberTemplate.WithCustomAC(typeof(HostObjectUtils), "GetSideFaces", new HostObjectUtils_GetSideFaces(), kind: MemberKind.StaticMethod ), ]; } } \ No newline at end of file diff --git a/sources/RevitDBExplorer/Domain/DataModel/MembersTemplates/IExternalApplication_Templates.cs b/sources/RevitDBExplorer/Domain/DataModel/MembersTemplates/IExternalApplication_Templates.cs index 626b3eca..f702b2b9 100644 --- a/sources/RevitDBExplorer/Domain/DataModel/MembersTemplates/IExternalApplication_Templates.cs +++ b/sources/RevitDBExplorer/Domain/DataModel/MembersTemplates/IExternalApplication_Templates.cs @@ -13,7 +13,7 @@ internal class IExternalApplication_Templates : IHaveMemberTemplates { public IEnumerable GetTemplates() => [ - MemberTemplate.Create(typeof(AddInManifestUtility), "GetRevitAddInManifest", new MemberAccessorByFunc((doc, target) => AddInManifestWizard.Get(target.GetType().Assembly.Location))), + MemberTemplate.WithCustomAC(typeof(AddInManifestUtility), "GetRevitAddInManifest", new MemberAccessorByFunc((doc, target) => AddInManifestWizard.Get(target.GetType().Assembly.Location))), ]; } } \ No newline at end of file diff --git a/sources/RevitDBExplorer/Domain/DataModel/MembersTemplates/JoinGeometryUtils_Templates.cs b/sources/RevitDBExplorer/Domain/DataModel/MembersTemplates/JoinGeometryUtils_Templates.cs index d9306e3d..716484ac 100644 --- a/sources/RevitDBExplorer/Domain/DataModel/MembersTemplates/JoinGeometryUtils_Templates.cs +++ b/sources/RevitDBExplorer/Domain/DataModel/MembersTemplates/JoinGeometryUtils_Templates.cs @@ -13,7 +13,7 @@ internal class JoinGeometryUtils_Templates : IHaveMemberTemplates public IEnumerable GetTemplates() => [ MemberTemplate.Create((doc, target) => JoinGeometryUtils.GetJoinedElements(doc, target)), - MemberTemplate.Create(typeof(JoinGeometryUtils), nameof(JoinGeometryUtils.IsCuttingElementInJoin), new JoinGeometryUtils_IsCuttingElementInJoin()) + MemberTemplate.WithCustomAC(typeof(JoinGeometryUtils), nameof(JoinGeometryUtils.IsCuttingElementInJoin), new JoinGeometryUtils_IsCuttingElementInJoin()) ]; } } \ No newline at end of file diff --git a/sources/RevitDBExplorer/Domain/DataModel/MembersTemplates/RebarHostData_Templates.cs b/sources/RevitDBExplorer/Domain/DataModel/MembersTemplates/RebarHostData_Templates.cs new file mode 100644 index 00000000..9293e947 --- /dev/null +++ b/sources/RevitDBExplorer/Domain/DataModel/MembersTemplates/RebarHostData_Templates.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Autodesk.Revit.DB; +using RevitDBExplorer.Domain.DataModel.Members.Base; +using RevitDBExplorer.Domain.DataModel.Members; +using Autodesk.Revit.DB.Structure; + +namespace RevitDBExplorer.Domain.DataModel.MembersTemplates +{ + internal class RebarHostData_Templates : IHaveMemberTemplates + { + + public IEnumerable GetTemplates() => + [ + MemberTemplate.Create((doc, target) => RebarHostData.IsValidHost(target), kind: MemberKind.StaticMethod), + MemberTemplate.Create((doc, target) => RebarHostData.GetRebarHostData(target), canBeUsed: element => RebarHostData.IsValidHost(element) , kind: MemberKind.StaticMethod), +#if R2025_MIN + MemberTemplate.Create((doc, target) => RebarHostData.GetRebarHostDirectNeighbors(target), canBeUsed: element => RebarHostData.IsValidHost(element) , kind: MemberKind.StaticMethod), +#endif + ]; + } +} diff --git a/sources/RevitDBExplorer/Domain/DataModel/MembersTemplates/Schema_Templates.cs b/sources/RevitDBExplorer/Domain/DataModel/MembersTemplates/Schema_Templates.cs index 795f3b0e..94446632 100644 --- a/sources/RevitDBExplorer/Domain/DataModel/MembersTemplates/Schema_Templates.cs +++ b/sources/RevitDBExplorer/Domain/DataModel/MembersTemplates/Schema_Templates.cs @@ -12,8 +12,8 @@ internal class Schema_Templates : IHaveMemberTemplates { public IEnumerable GetTemplates() => [ - MemberTemplate.Create(typeof(Schema), "Get all elements that have entity of this schema", new Schema_GetAllElements(), kind: MemberKind.Extra), - MemberTemplate.Create(typeof(Schema), "Erase schema and all entities from the document", new Schema_EraseSchemaAndAllEntities(), kind: MemberKind.Extra), + MemberTemplate.WithCustomAC(typeof(Schema), "Get all elements that have entity of this schema", new Schema_GetAllElements(), kind: MemberKind.Extra), + MemberTemplate.WithCustomAC(typeof(Schema), "Erase schema and all entities from the document", new Schema_EraseSchemaAndAllEntities(), kind: MemberKind.Extra), ]; } } \ No newline at end of file diff --git a/sources/RevitDBExplorer/Domain/DataModel/MembersTemplates/UpdaterInfo_Templates.cs b/sources/RevitDBExplorer/Domain/DataModel/MembersTemplates/UpdaterInfo_Templates.cs index 02281752..2e891967 100644 --- a/sources/RevitDBExplorer/Domain/DataModel/MembersTemplates/UpdaterInfo_Templates.cs +++ b/sources/RevitDBExplorer/Domain/DataModel/MembersTemplates/UpdaterInfo_Templates.cs @@ -12,7 +12,7 @@ internal class UpdaterInfo_Templates : IHaveMemberTemplates { public IEnumerable GetTemplates() => [ - MemberTemplate.Create(typeof(IUpdater), "GetUpdaterId", new MemberAccessorByFunc((doc, target) => UpdaterInfoWizard.Get(target.ApplicationName, target.UpdaterName))), + MemberTemplate.WithCustomAC(typeof(IUpdater), "GetUpdaterId", new MemberAccessorByFunc((doc, target) => UpdaterInfoWizard.Get(target.ApplicationName, target.UpdaterName))), ]; } } \ No newline at end of file diff --git a/sources/RevitDBExplorer/Domain/DataModel/SnoopableItem.cs b/sources/RevitDBExplorer/Domain/DataModel/SnoopableItem.cs index 85e2a8a9..9abde583 100644 --- a/sources/RevitDBExplorer/Domain/DataModel/SnoopableItem.cs +++ b/sources/RevitDBExplorer/Domain/DataModel/SnoopableItem.cs @@ -116,7 +116,7 @@ public string GenerateScript(TemplateInputsKind inputsKind) { return accessorWithCodeGeneration.GenerateInvocationForScript(inputsKind); } - var invocation = accessor.DefaultInvocation.Syntax ?? Name; + var invocation = accessor.DefaultInvocation.Syntax ?? $"item.{Name}"; return new MemberInvocationTemplateSelector().Evaluate(parent.Object.GetType(), invocation, TemplateCmdKind.Select, inputsKind); } diff --git a/sources/RevitDBExplorer/Domain/RevitDatabaseScripting/MemberInvocationTemplateSelector.cs b/sources/RevitDBExplorer/Domain/RevitDatabaseScripting/MemberInvocationTemplateSelector.cs index dc22500b..d65098d7 100644 --- a/sources/RevitDBExplorer/Domain/RevitDatabaseScripting/MemberInvocationTemplateSelector.cs +++ b/sources/RevitDBExplorer/Domain/RevitDatabaseScripting/MemberInvocationTemplateSelector.cs @@ -13,7 +13,11 @@ internal class MemberInvocationTemplateSelector { public string Evaluate(MethodInfo getMethod, string invocation, TemplateInputsKind inputsKind) { - invocation ??= getMethod.GenerateInvocation(); + if (string.IsNullOrEmpty(invocation)) + { + var prefix = getMethod.IsStatic == false ? "item." : $"{getMethod.DeclaringType.Name}."; + invocation = prefix + getMethod.GenerateInvocation(); + } var cmdkind = getMethod.ReturnType == typeof(void) ? TemplateCmdKind.Update : TemplateCmdKind.Select; return Evaluate(getMethod.DeclaringType, invocation, cmdkind, inputsKind); @@ -22,7 +26,7 @@ public string Evaluate(Type type, string invocation, TemplateCmdKind cmdkind, Te { var template = GetTemplateType(cmdkind, inputsKind); - return Evaluate(template, type, invocation); + return EvaluateInternal(template, type, invocation); } private Type GetTemplateType(TemplateCmdKind cmdKind, TemplateInputsKind inputsKind) { @@ -48,13 +52,13 @@ private Type GetTemplateType(TemplateCmdKind cmdKind, TemplateInputsKind inputsK - private string Evaluate(System.Type templateType, System.Type type, string invocation) + private string EvaluateInternal(System.Type templateType, System.Type type, string invocation) { var template = CodeToStringRepo.GetText(templateType.Name, true); var result = template.ReplaceMany(new[] { ("TypePlaceholder", type.GetCSharpName()), - ("MethodPlaceholder()", invocation) + ("item.MethodPlaceholder()", invocation) }); return result; diff --git a/sources/RevitDBExplorer/Domain/RevitDatabaseScripting/MemberInvocationTemplates.cs b/sources/RevitDBExplorer/Domain/RevitDatabaseScripting/MemberInvocationTemplates.cs index ff70f52f..a13144b8 100644 --- a/sources/RevitDBExplorer/Domain/RevitDatabaseScripting/MemberInvocationTemplates.cs +++ b/sources/RevitDBExplorer/Domain/RevitDatabaseScripting/MemberInvocationTemplates.cs @@ -26,8 +26,8 @@ internal class MemberInvocation_SelectSingle_Template [CodeToString(nameof(MemberInvocation_SelectSingle_Template))] object Select(Document document, IEnumerable inputs) { - var input = inputs.FirstOrDefault(); - return input.MethodPlaceholder(); + var item = inputs.FirstOrDefault(); + return item.MethodPlaceholder(); } } @@ -50,8 +50,8 @@ internal class MemberInvocation_UpdateSingle_Template [CodeToString(nameof(MemberInvocation_UpdateSingle_Template))] void Update(Document document, IEnumerable inputs) { - var input = inputs.FirstOrDefault(); - input.MethodPlaceholder(); + var item = inputs.FirstOrDefault(); + item.MethodPlaceholder(); } } } \ No newline at end of file