diff --git a/OpenMEP/Element/Duct.cs b/OpenMEP/Element/Duct.cs index 00ee7bd5..1172cb1c 100644 --- a/OpenMEP/Element/Duct.cs +++ b/OpenMEP/Element/Duct.cs @@ -1,5 +1,6 @@ using Autodesk.Revit.DB; using Dynamo.Graph.Nodes; +using OpenMEP.Helpers; using Revit.GeometryConversion; using RevitServices.Persistence; using RevitServices.Transactions; @@ -11,6 +12,7 @@ public class Duct private Duct() { } + /// Creates a new duct that connects to two connectors. /// /// The new duct will have the same diameter and system type as the start connector. The creation will also connect the new duct @@ -22,7 +24,7 @@ private Duct() /// The level Element for the new duct. /// The first connector where the new duct starts. /// The second point of the new duct. - /// The created duct. + /// The created duct. /// /// The duct type ductTypeId is not valid duct type. /// -or- @@ -43,16 +45,64 @@ private Duct() /// /// 2017 [NodeCategory("Create")] - public static void Create(global::Revit.Elements.Element ductType, global::Revit.Elements.Element level, + public static Revit.Elements.Element? Create(global::Revit.Elements.Element ductType, + global::Revit.Elements.Element level, Autodesk.Revit.DB.Connector startConnector, Autodesk.Revit.DB.Connector endConnector) { Autodesk.Revit.DB.Document doc = DocumentManager.Instance.CurrentDBDocument; TransactionManager.Instance.EnsureInTransaction(doc); - Autodesk.Revit.DB.Mechanical.Duct.Create(doc, new ElementId(ductType.Id), new ElementId(level.Id), + Autodesk.Revit.DB.Mechanical.Duct duct = Autodesk.Revit.DB.Mechanical.Duct.Create(doc, + new ElementId(ductType.Id), new ElementId(level.Id), startConnector, endConnector); TransactionManager.Instance.TransactionTaskDone(); + return duct.ToDynamoType(); } - + + /// Creates a new duct that connects to two connectors. + /// + /// The new duct will have the same diameter and system type as the start connector. The creation will also connect the new duct + /// to two component who owns the specified connectors. If necessary, additional fitting(s) are included to make a valid connection. + /// If the new duct can not be connected to the next component (e.g., mismatched direction, no valid fitting, and etc), the new duct + /// will still be created at the specified connector position, and an InvalidOperationException is thrown. + /// + /// The Element of the new duct type. + /// The level Element for the new duct. + /// The first connector where the new duct starts. + /// The second point of the new duct. + /// new value width of duct + /// new value height of duct + /// The created duct. + /// + /// The duct type ductTypeId is not valid duct type. + /// -or- + /// The ElementId levelId is not a Level. + /// -or- + /// The connector's domain is not Domain.​DomainHvac. + /// -or- + /// The points of startConnector and endConnector are too close: for MEPCurve, the minimum length is 1/10 inch. + /// + /// + /// A non-optional argument was null + /// + /// + /// None of the following disciplines is enabled: Mechanical Electrical Piping. + /// + /// + /// Thrown when the new duct fails to connect with the connector. + /// + /// 2017 + [NodeCategory("Create")] + public static Revit.Elements.Element? Create(global::Revit.Elements.Element ductType, + global::Revit.Elements.Element level, + Autodesk.Revit.DB.Connector startConnector, Autodesk.Revit.DB.Connector endConnector, double width, + double height) + { + Revit.Elements.Element? element = Create(ductType, level, startConnector, endConnector); + if (element != null) SetDiameter(element, width, height); + return element; + } + + /// Creates a new duct that connects to the connector. /// /// The new duct will have the same diameter and system type as the specified connector. The creation will also connect the new duct @@ -64,7 +114,7 @@ public static void Create(global::Revit.Elements.Element ductType, global::Revit /// The level for the new duct. /// The first connector where the new duct starts. /// The second point of the new duct. - /// The created duct. + /// The created duct. /// /// The duct type ductTypeId is not valid duct type. /// -or- @@ -85,23 +135,69 @@ public static void Create(global::Revit.Elements.Element ductType, global::Revit /// /// 2017 [NodeCategory("Create")] - public static void Create(global::Revit.Elements.Element ductType, global::Revit.Elements.Element level, + public static Revit.Elements.Element? Create(global::Revit.Elements.Element ductType, + global::Revit.Elements.Element level, Autodesk.Revit.DB.Connector startConnector, Autodesk.DesignScript.Geometry.Point endPoint) { Autodesk.Revit.DB.Document doc = DocumentManager.Instance.CurrentDBDocument; TransactionManager.Instance.EnsureInTransaction(doc); - Autodesk.Revit.DB.Mechanical.Duct.Create(doc, new ElementId(ductType.Id), new ElementId(level.Id), - startConnector, endPoint.ToXyz()); + Revit.Elements.Element? element = Autodesk.Revit.DB.Mechanical.Duct.Create(doc, new ElementId(ductType.Id), + new ElementId(level.Id), + startConnector, endPoint.ToXyz()).ToDynamoType(); TransactionManager.Instance.TransactionTaskDone(); + return element; } + /// Creates a new duct that connects to the connector. + /// + /// The new duct will have the same diameter and system type as the specified connector. The creation will also connect the new duct + /// to the component who owns the specified connector. If necessary, additional fitting(s) are included to make a valid connection. + /// If the new duct can not be connected to the next component (e.g., mismatched direction, no valid fitting, and etc), the new duct + /// will still be created at the specified connector position, and an InvalidOperationException is thrown. + /// + /// The Element of the new duct type. + /// The level for the new duct. + /// The first connector where the new duct starts. + /// The second point of the new duct. + /// new value width of duct + /// new value height of duct + /// The created duct. + /// + /// The duct type ductTypeId is not valid duct type. + /// -or- + /// The ElementId levelId is not a Level. + /// -or- + /// The connector's domain is not Domain.​DomainHvac. + /// -or- + /// The points of startConnector and endPoint are too close: for MEPCurve, the minimum length is 1/10 inch. + /// + /// + /// A non-optional argument was null + /// + /// + /// None of the following disciplines is enabled: Mechanical Electrical Piping. + /// + /// + /// Thrown when the new duct fails to connect with the connector. + /// + /// 2017 + [NodeCategory("Create")] + public static Revit.Elements.Element? Create(global::Revit.Elements.Element ductType, + global::Revit.Elements.Element level, + Autodesk.Revit.DB.Connector startConnector, Autodesk.DesignScript.Geometry.Point endPoint,double width,double height) + { + Revit.Elements.Element? element = Create(ductType, level, startConnector, endPoint); + if (element != null) SetDiameter(element, width, height); + return element; + } + /// Creates a new duct from two points. /// The element of the HVAC system type. /// The element of the duct type. /// The level for the duct. /// The start point of the duct. /// The end point of the duct. - /// The created duct. + /// The created duct. /// /// The systemType is not valid HVAC system type. /// -or- @@ -119,23 +215,60 @@ public static void Create(global::Revit.Elements.Element ductType, global::Revit /// /// 2014 [NodeCategory("Create")] - public static void Create(global::Revit.Elements.Element systemType, global::Revit.Elements.Element ductType, global::Revit.Elements.Element level, + public static Revit.Elements.Element? Create(global::Revit.Elements.Element systemType, + global::Revit.Elements.Element ductType, global::Revit.Elements.Element level, Autodesk.DesignScript.Geometry.Point startPoint, Autodesk.DesignScript.Geometry.Point endPoint) { Autodesk.Revit.DB.Document doc = DocumentManager.Instance.CurrentDBDocument; TransactionManager.Instance.EnsureInTransaction(doc); - Autodesk.Revit.DB.Mechanical.Duct.Create(doc,new ElementId(systemType.Id), new ElementId(ductType.Id), new ElementId(level.Id), - startPoint.ToXyz(), endPoint.ToXyz()); + Revit.Elements.Element? duct = Autodesk.Revit.DB.Mechanical.Duct.Create(doc, new ElementId(systemType.Id), + new ElementId(ductType.Id), new ElementId(level.Id), + startPoint.ToXyz(), endPoint.ToXyz()).ToDynamoType(); TransactionManager.Instance.TransactionTaskDone(); + return duct; } - + /// Creates a new duct from two points. + /// The element of the HVAC system type. + /// The element of the duct type. + /// The level for the duct. + /// The start point of the duct. + /// The end point of the duct. + /// new value width of duct + /// new value height of duct + /// The created duct. + /// + /// The systemType is not valid HVAC system type. + /// -or- + /// The duct type ductType is not valid duct type. + /// -or- + /// The Element level is not a Level. + /// -or- + /// The points of startPoint and endPoint are too close: for MEPCurve, the minimum length is 1/10 inch. + /// + /// + /// A non-optional argument was null + /// + /// + /// None of the following disciplines is enabled: Mechanical Electrical Piping. + /// + /// 2014 + [NodeCategory("Create")] + public static Revit.Elements.Element? Create(global::Revit.Elements.Element systemType, + global::Revit.Elements.Element ductType, global::Revit.Elements.Element level, + Autodesk.DesignScript.Geometry.Point startPoint, Autodesk.DesignScript.Geometry.Point endPoint,double width,double height) + { + Revit.Elements.Element? element = Create(systemType, ductType, level, startPoint, endPoint); + if (element != null) SetDiameter(element, width, height); + return element; + } + /// Creates a new placeholder duct. /// The element of the HVAC system type. /// The element of the duct type. /// The element level for the duct. /// The first point of the placeholder line. /// The second point of the placeholder line. - /// The created placeholder duct. + /// The created placeholder duct. /// /// The systemType is not valid HVAC system type. /// -or- @@ -153,14 +286,80 @@ public static void Create(global::Revit.Elements.Element systemType, global::Rev /// /// 2014 [NodeCategory("Create")] - public static void CreatePlaceholder(global::Revit.Elements.Element systemType, global::Revit.Elements.Element ductType, global::Revit.Elements.Element level, + public static Revit.Elements.Element? CreatePlaceholder(global::Revit.Elements.Element systemType, + global::Revit.Elements.Element ductType, global::Revit.Elements.Element level, Autodesk.DesignScript.Geometry.Point startPoint, Autodesk.DesignScript.Geometry.Point endPoint) { Autodesk.Revit.DB.Document doc = DocumentManager.Instance.CurrentDBDocument; TransactionManager.Instance.EnsureInTransaction(doc); - Autodesk.Revit.DB.Mechanical.Duct.CreatePlaceholder(doc,new ElementId(systemType.Id), new ElementId(ductType.Id), new ElementId(level.Id), + Autodesk.Revit.DB.Mechanical.Duct duct = Autodesk.Revit.DB.Mechanical.Duct.CreatePlaceholder(doc, + new ElementId(systemType.Id), new ElementId(ductType.Id), new ElementId(level.Id), startPoint.ToXyz(), endPoint.ToXyz()); TransactionManager.Instance.TransactionTaskDone(); + return duct.ToDynamoType(); + } + + /// Creates a new placeholder duct. + /// The element of the HVAC system type. + /// The element of the duct type. + /// The element level for the duct. + /// new value width of duct + /// new value height of duct + /// The first point of the placeholder line. + /// The second point of the placeholder line. + /// The created placeholder duct. + /// + /// The systemType is not valid HVAC system type. + /// -or- + /// The ductType is not valid duct type. + /// -or- + /// The Element level is not a Level. + /// -or- + /// The points of startPoint and endPoint are too close: for MEPCurve, the minimum length is 1/10 inch. + /// + /// + /// A non-optional argument was null + /// + /// + /// None of the following disciplines is enabled: Mechanical Electrical Piping. + /// + /// 2014 + [NodeCategory("Create")] + public static Revit.Elements.Element? CreatePlaceholder(global::Revit.Elements.Element systemType, + global::Revit.Elements.Element ductType, global::Revit.Elements.Element level, + Autodesk.DesignScript.Geometry.Point startPoint, Autodesk.DesignScript.Geometry.Point endPoint,double width,double height) + { + Revit.Elements.Element? element = Create(systemType, ductType, level, startPoint, endPoint); + if (element != null) SetDiameter(element, width, height); + return element; + } + + /// + /// Set new diameter for duct + /// + /// the duct to set diameter + /// new value width of duct + /// new value height of duct + /// duct with new parameter diameter + public static Revit.Elements.Element? SetDiameter(Revit.Elements.Element duct, double width, double height) + { + Autodesk.Revit.DB.Document doc = DocumentManager.Instance.CurrentDBDocument; + TransactionManager.Instance.EnsureInTransaction(doc); + Autodesk.Revit.DB.Mechanical.Duct? internalElement = duct.InternalElement as Autodesk.Revit.DB.Mechanical.Duct; + // Set the diameter of the duct. +#if R20 + DisplayUnitType unitTypeId = doc.GetUnits().GetFormatOptions(UnitType.UT_HVAC_DuctSize).DisplayUnits; + double widthValue = UnitUtils.ConvertToInternalUnits(width, unitTypeId); + double heightValue = UnitUtils.ConvertToInternalUnits(height, unitTypeId); +#else + Autodesk.Revit.DB.ForgeTypeId unitTypeId = doc.GetUnits().GetFormatOptions(SpecTypeId.DuctSize).GetUnitTypeId(); + double widthValue = UnitUtils.ConvertToInternalUnits(width, unitTypeId); + double heightValue = UnitUtils.ConvertToInternalUnits(height, unitTypeId); +#endif + internalElement?.get_Parameter(BuiltInParameter.RBS_CURVE_WIDTH_PARAM).Set(widthValue); + internalElement?.get_Parameter(BuiltInParameter.RBS_CURVE_HEIGHT_PARAM).Set(heightValue); + TransactionManager.Instance.TransactionTaskDone(); + return duct; } /// Updates the associated system type for the duct. @@ -181,9 +380,11 @@ public static void CreatePlaceholder(global::Revit.Elements.Element systemType, /// 2017 /// duct changed systemType [NodeCategory("Action")] - public static global::Revit.Elements.Element SetSystemType(global::Revit.Elements.Element duct,global::Revit.Elements.Element systemType) + public static global::Revit.Elements.Element SetSystemType(global::Revit.Elements.Element duct, + global::Revit.Elements.Element systemType) { - Autodesk.Revit.DB.Mechanical.Duct? ductInternalElement = duct.InternalElement as Autodesk.Revit.DB.Mechanical.Duct; + Autodesk.Revit.DB.Mechanical.Duct? ductInternalElement = + duct.InternalElement as Autodesk.Revit.DB.Mechanical.Duct; Autodesk.Revit.DB.Document doc = DocumentManager.Instance.CurrentDBDocument; TransactionManager.Instance.EnsureInTransaction(doc); ductInternalElement!.SetSystemType(new ElementId(systemType.Id)); @@ -200,9 +401,11 @@ public static void CreatePlaceholder(global::Revit.Elements.Element systemType, public static bool IsHvacSystemTypeId(global::Revit.Elements.Element systemType) { Autodesk.Revit.DB.Document doc = DocumentManager.Instance.CurrentDBDocument; - bool isHvacSystemTypeId = Autodesk.Revit.DB.Mechanical.Duct.IsHvacSystemTypeId(doc, new ElementId(systemType.Id)); + bool isHvacSystemTypeId = + Autodesk.Revit.DB.Mechanical.Duct.IsHvacSystemTypeId(doc, new ElementId(systemType.Id)); return isHvacSystemTypeId; } + /// /// Check if the element of duct is a valid duct type /// diff --git a/OpenMEP/Element/Family/FamilyParameter.cs b/OpenMEP/Element/Family/FamilyParameter.cs index 6ba37651..fc7ab755 100644 --- a/OpenMEP/Element/Family/FamilyParameter.cs +++ b/OpenMEP/Element/Family/FamilyParameter.cs @@ -9,182 +9,188 @@ public class FamilyParameter { private FamilyParameter() { - } - /// - /// Set the family parameter as an instance parameter. - /// - /// document - /// family parameter - /// family parameter - public static object? MakeInstance(Autodesk.Revit.DB.Document doc, - Autodesk.Revit.DB.FamilyParameter? familyParameter) - { - if (!doc.IsFamilyDocument) throw new ArgumentException("just support family document"); - using Autodesk.Revit.DB.Transaction tran = new Autodesk.Revit.DB.Transaction(doc, "make instance"); - tran.Start(); - try - { - doc.FamilyManager.MakeInstance(familyParameter); - } - catch (Exception e) - { - return null; - } - - tran.Commit(); - return familyParameter; - } - /// - /// Set the family parameter as a reporting parameter. - /// - /// - /// - public static void MakeReporting(Autodesk.Revit.DB.Document doc, Autodesk.Revit.DB.FamilyParameter familyParameter) + /// + /// Set the family parameter as an instance parameter. + /// + /// document + /// family parameter + /// family parameter + public static object? MakeInstance(Autodesk.Revit.DB.Document doc, + Autodesk.Revit.DB.FamilyParameter? familyParameter) + { + if (!doc.IsFamilyDocument) throw new ArgumentException("just support family document"); + using Autodesk.Revit.DB.Transaction tran = new Autodesk.Revit.DB.Transaction(doc, "make instance"); + tran.Start(); + try { - if (!doc.IsFamilyDocument) throw new ArgumentException("just support family document"); - using Autodesk.Revit.DB.Transaction tran = new Autodesk.Revit.DB.Transaction(doc, "make reporting"); - tran.Start(); - doc.FamilyManager.MakeReporting(familyParameter); - tran.Commit(); + doc.FamilyManager.MakeInstance(familyParameter); } - - /// - /// Set the reporting family parameter as a regular/driving parameter. - /// - /// document - /// - public static void MakeNonReporting(Autodesk.Revit.DB.Document doc, - Autodesk.Revit.DB.FamilyParameter familyParameter) + catch (Exception e) { - if (!doc.IsFamilyDocument) throw new ArgumentException("just support family document"); - using Autodesk.Revit.DB.Transaction tran = new Autodesk.Revit.DB.Transaction(doc, "make none reporting"); - tran.Start(); - doc.FamilyManager.MakeNonReporting(familyParameter); - tran.Commit(); + return null; } - /// - /// Set the family parameter as a type parameter. - /// - /// - /// - public static void MakeType(Autodesk.Revit.DB.Document doc, Autodesk.Revit.DB.FamilyParameter familyParameter) - { - if (!doc.IsFamilyDocument) throw new ArgumentException("just support family document"); - using Autodesk.Revit.DB.Transaction tran = new Autodesk.Revit.DB.Transaction(doc, "make reporting"); - tran.Start(); - doc.FamilyManager.MakeType(familyParameter); - tran.Commit(); - } + tran.Commit(); + return familyParameter; + } - /// - /// Gets the identifier of the unit quantifying the parameter value. - /// - /// Old Function Name: DisplayUnitType lower Revit 2022 - /// - /// - /// family parameter - /// forgeTypeId - public static dynamic GetUnitTypeId(Autodesk.Revit.DB.FamilyParameter familyParameter) - { + /// + /// Set the family parameter as a reporting parameter. + /// + /// + /// + public static void MakeReporting(Autodesk.Revit.DB.Document doc, Autodesk.Revit.DB.FamilyParameter familyParameter) + { + if (!doc.IsFamilyDocument) throw new ArgumentException("just support family document"); + using Autodesk.Revit.DB.Transaction tran = new Autodesk.Revit.DB.Transaction(doc, "make reporting"); + tran.Start(); + doc.FamilyManager.MakeReporting(familyParameter); + tran.Commit(); + } + + /// + /// Set the reporting family parameter as a regular/driving parameter. + /// + /// document + /// + public static void MakeNonReporting(Autodesk.Revit.DB.Document doc, + Autodesk.Revit.DB.FamilyParameter familyParameter) + { + if (!doc.IsFamilyDocument) throw new ArgumentException("just support family document"); + using Autodesk.Revit.DB.Transaction tran = new Autodesk.Revit.DB.Transaction(doc, "make none reporting"); + tran.Start(); + doc.FamilyManager.MakeNonReporting(familyParameter); + tran.Commit(); + } + + /// + /// Set the family parameter as a type parameter. + /// + /// + /// + public static void MakeType(Autodesk.Revit.DB.Document doc, Autodesk.Revit.DB.FamilyParameter familyParameter) + { + if (!doc.IsFamilyDocument) throw new ArgumentException("just support family document"); + using Autodesk.Revit.DB.Transaction tran = new Autodesk.Revit.DB.Transaction(doc, "make reporting"); + tran.Start(); + doc.FamilyManager.MakeType(familyParameter); + tran.Commit(); + } + + /// + /// Gets the identifier of the unit quantifying the parameter value. + /// + /// Old Function Name: DisplayUnitType lower Revit 2022 + /// + /// + /// family parameter + /// forgeTypeId + public static dynamic GetUnitTypeId(Autodesk.Revit.DB.FamilyParameter familyParameter) + { #if R22 || R23 dynamic? displayUnitType = familyParameter.GetUnitTypeId(); #elif R21 || R20 dynamic? displayUnitType = familyParameter.DisplayUnitType; #endif - return displayUnitType; - } + return displayUnitType; + } - /// - /// The definition. - /// - /// family parameter - /// Definition - public static Autodesk.Revit.DB.Definition Definition(Autodesk.Revit.DB.FamilyParameter familyParameter) - { - if (familyParameter == null) throw new ArgumentNullException(nameof(familyParameter)); - return familyParameter.Definition; - } + /// + /// The definition. + /// + /// family parameter + /// Definition + public static Autodesk.Revit.DB.Definition Definition(Autodesk.Revit.DB.FamilyParameter familyParameter) + { + if (familyParameter == null) throw new ArgumentNullException(nameof(familyParameter)); + return familyParameter.Definition; + } - /// - /// return all information properties of family parameter - /// - /// family parameter - /// - [MultiReturn("definition", "formula", "id", "associatedParameters", "displayUnitType", "isInstance", "isShared", - "storageType", "userModifiable", - "canAssignFormula", "isReadOnly", "guid", "isDeterminedByFormula", "isReporting")] - public static IDictionary? GetProperties(Autodesk.Revit.DB.FamilyParameter? familyParameter) - { - Definition? definition = familyParameter?.Definition; - string? formula = familyParameter?.Formula; - int? id = familyParameter?.Id.IntegerValue; - ParameterSet? parameterSet = familyParameter?.AssociatedParameters; - List associatedParameters = new List(); - bool? isInstance = familyParameter?.IsInstance; - bool? isShared = familyParameter?.IsShared; - StorageType? storageType = familyParameter?.StorageType; - bool? userModifiable = familyParameter?.UserModifiable; - bool? canAssignFormula = familyParameter?.CanAssignFormula; - bool? isReadOnly = familyParameter?.IsReadOnly; -#if R20 || R21 + /// + /// return all information properties of family parameter + /// + /// family parameter + /// + [MultiReturn("definition", "formula", "id", "associatedParameters", "displayUnitType", "isInstance", "isShared", + "storageType", "userModifiable", + "canAssignFormula", "isReadOnly", "guid", "isDeterminedByFormula", "isReporting")] + public static IDictionary? GetProperties(Autodesk.Revit.DB.FamilyParameter? familyParameter) + { + Definition? definition = familyParameter?.Definition; + string? formula = familyParameter?.Formula; + int? id = familyParameter?.Id.IntegerValue; + ParameterSet? parameterSet = familyParameter?.AssociatedParameters; + List associatedParameters = new List(); + bool? isInstance = familyParameter?.IsInstance; + bool? isShared = familyParameter?.IsShared; + StorageType? storageType = familyParameter?.StorageType; + bool? userModifiable = familyParameter?.UserModifiable; + bool? canAssignFormula = familyParameter?.CanAssignFormula; + bool? isReadOnly = familyParameter?.IsReadOnly; +#if R20 || R21 object? displayUnitType = familyParameter.DisplayUnitType; #else object? displayUnitType = familyParameter?.GetUnitTypeId(); #endif - bool? isReporting = familyParameter?.IsReporting; - Guid? guid = null; - if (familyParameter.IsShared) - { - guid = familyParameter.GUID; - } - - bool isDeterminedByFormula = familyParameter.IsDeterminedByFormula; - foreach (Autodesk.Revit.DB.Parameter p in parameterSet) - { - global::Revit.Elements.Parameter? dynamoType = p.ToDynamoType(); - associatedParameters.Add(dynamoType); - } - - return new Dictionary() - { - {nameof(definition), definition}, - {nameof(formula), formula}, - {nameof(id), id}, - {nameof(associatedParameters), associatedParameters}, - {nameof(displayUnitType), displayUnitType}, - {nameof(isInstance), isInstance}, - {nameof(isShared), isShared}, - {nameof(storageType), storageType}, - {nameof(userModifiable), userModifiable}, - {nameof(canAssignFormula), canAssignFormula}, - {nameof(isReadOnly), isReadOnly}, - {nameof(guid), guid}, - {nameof(isDeterminedByFormula), isDeterminedByFormula}, - {nameof(isReporting), isReporting}, - }; + bool? isReporting = familyParameter?.IsReporting; + Guid? guid = null; + if (familyParameter.IsShared) + { + guid = familyParameter.GUID; } - /// - /// Convert Revit FamilyParameter to Dynamo FamilyParameter - /// - /// family parameter - /// family parameter - public static global::Revit.Elements.FamilyParameter? ToDynamoFamilyParameter(Autodesk.Revit.DB.FamilyParameter familyParameter) + bool isDeterminedByFormula = familyParameter.IsDeterminedByFormula; + foreach (Autodesk.Revit.DB.Parameter p in parameterSet) { - return familyParameter.ToDynamoType(); + global::Revit.Elements.Parameter? dynamoType = p.ToDynamoType(); + associatedParameters.Add(dynamoType); } - /// - /// Convert Dynamo FamilyParameter to Revit FamilyParameter - /// - /// family parameter - /// family parameter - public static Autodesk.Revit.DB.FamilyParameter? ToRevitFamilyParameter( - global::Revit.Elements.FamilyParameter familyParameter) + return new Dictionary() { - return familyParameter.ToRevitType(); - } + {nameof(definition), definition}, + {nameof(formula), formula}, + {nameof(id), id}, + {nameof(associatedParameters), associatedParameters}, + {nameof(displayUnitType), displayUnitType}, + {nameof(isInstance), isInstance}, + {nameof(isShared), isShared}, + {nameof(storageType), storageType}, + {nameof(userModifiable), userModifiable}, + {nameof(canAssignFormula), canAssignFormula}, + {nameof(isReadOnly), isReadOnly}, + {nameof(guid), guid}, + {nameof(isDeterminedByFormula), isDeterminedByFormula}, + {nameof(isReporting), isReporting}, + }; + } + +#if R20 +#else + /// + /// Convert Revit FamilyParameter to Dynamo FamilyParameter + /// + /// family parameter + /// family parameter + public static global::Revit.Elements.FamilyParameter? ToDynamoFamilyParameter( + Autodesk.Revit.DB.FamilyParameter familyParameter) + { + return familyParameter.ToDynamoType(); + } + + /// + /// Convert Dynamo FamilyParameter to Revit FamilyParameter + /// + /// family parameter + /// family parameter + public static Autodesk.Revit.DB.FamilyParameter? ToRevitFamilyParameter( + global::Revit.Elements.FamilyParameter familyParameter) + { + return familyParameter.ToRevitType(); + } +#endif + + } \ No newline at end of file diff --git a/OpenMEP/Element/Pipe.cs b/OpenMEP/Element/Pipe.cs index 8c24b120..765b5d37 100644 --- a/OpenMEP/Element/Pipe.cs +++ b/OpenMEP/Element/Pipe.cs @@ -524,7 +524,6 @@ Autodesk.DesignScript.Geometry.Point point /// first pipe /// second pipe /// three pipe - /// return an collection list connectors closet check by 3 pipe [MultiReturn("Connector1", "Connector2", "Connector3")] public static IDictionary GetThreeConnectorsClosest(global::Revit.Elements.Element? pipe1, global::Revit.Elements.Element? pipe2, global::Revit.Elements.Element? pipe3) diff --git a/OpenMEP/Helpers/Convert.cs b/OpenMEP/Helpers/Convert.cs index 12fd5ee4..19b0347b 100644 --- a/OpenMEP/Helpers/Convert.cs +++ b/OpenMEP/Helpers/Convert.cs @@ -8,7 +8,10 @@ using dynDocument = Revit.Application.Document; using dynElement = Revit.Elements.Element; using dynElementSelector = Revit.Elements.ElementSelector; +#if R20 +#else using dynFamilyParameter = Revit.Elements.FamilyParameter; +#endif using dynParameter = Revit.Elements.Parameter; using Point = Autodesk.DesignScript.Geometry.Point; using rvtCategory = Autodesk.Revit.DB.Category; @@ -23,7 +26,6 @@ namespace OpenMEP.Helpers [IsVisibleInDynamoLibrary(false)] internal static class Convert { - /// /// convert Revit document to Dynamo document /// @@ -110,6 +112,8 @@ internal static rvtCategory ToRevitType( return constructor!.Invoke(new object[] {item}) as dynParameter; } +#if R20 +#else /// /// Convert Revit FamilyParameter to Dynamo FamilyParameter /// @@ -123,37 +127,40 @@ internal static rvtCategory ToRevitType( BindingFlags.NonPublic | BindingFlags.Instance).FirstOrDefault(); return constructor!.Invoke(new object[] {item}) as dynFamilyParameter; } - + /// - /// Convert Dynamo Parameter to Revit Parameter + /// Convert Dynamo FamilyParameter to Revit FamilyParameter /// /// /// /// - internal static rvtParameter? ToRevitType(this dynParameter item) + internal static rvtFamilyParameter? ToRevitType(this dynFamilyParameter item) { if (item == null) throw new ArgumentNullException(nameof(item)); var property = typeof(dynParameter) - .GetProperty("InternalParameter", + .GetProperty("InternalFamilyParameter", BindingFlags.NonPublic | BindingFlags.Instance); - return property!.GetValue(item) as rvtParameter; + return property!.GetValue(item) as rvtFamilyParameter; } +#endif + /// - /// Convert Dynamo FamilyParameter to Revit FamilyParameter + /// Convert Dynamo Parameter to Revit Parameter /// /// /// /// - internal static rvtFamilyParameter? ToRevitType(this dynFamilyParameter item) + internal static rvtParameter? ToRevitType(this dynParameter item) { if (item == null) throw new ArgumentNullException(nameof(item)); var property = typeof(dynParameter) - .GetProperty("InternalFamilyParameter", + .GetProperty("InternalParameter", BindingFlags.NonPublic | BindingFlags.Instance); - return property!.GetValue(item) as rvtFamilyParameter; + return property!.GetValue(item) as rvtParameter; } + /// /// Convert Revit ElementId To Dynamo Element diff --git a/OpenMEP/OpenMEP.csproj b/OpenMEP/OpenMEP.csproj index 9ded85a4..a3fad19f 100644 --- a/OpenMEP/OpenMEP.csproj +++ b/OpenMEP/OpenMEP.csproj @@ -17,7 +17,7 @@ CS1591;CS0168;CS8618;CS1591 - 2.12 + 2.3 2.3 2020 true @@ -25,7 +25,7 @@ $(DefineConstants);R20 - 2.12 + 2.3 2.3 2020 $(DefineConstants);R20