Skip to content

Commit

Permalink
Merge pull request #18 from chuongmep/dev
Browse files Browse the repository at this point in the history
Fix null value connector farthest, Element connected with
  • Loading branch information
chuongmep authored Feb 27, 2023
2 parents b5c18f5 + d1d048b commit fe9ca76
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 99 deletions.
1 change: 0 additions & 1 deletion .idea/.idea.OpenMEP/.idea/.name

This file was deleted.

26 changes: 12 additions & 14 deletions OpenMEP/ConnectorManager/Connector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public static double Radius(Autodesk.Revit.DB.Connector connector)
/// </summary>
/// <param name="c">origin connector</param>
/// <param name="connectors">an collection connector to check</param>
/// <returns></returns>
/// <returns name="connector">connector</returns>
public static Autodesk.Revit.DB.Connector? GetConnectorFarthest(Autodesk.Revit.DB.Connector? c,
List<Autodesk.Revit.DB.Connector?> connectors)
{
Expand All @@ -208,20 +208,15 @@ public static double Radius(Autodesk.Revit.DB.Connector connector)
}

/// <summary>
/// Return Farthest Connector between element1 from element2
/// Return Farthest Connector between element1 with element2
/// </summary>
/// <param name="element1">first element</param>
/// <param name="element2">second element</param>
/// <returns name="connector">Farthest connector of element1</returns>
public static Autodesk.Revit.DB.Connector? GetConnectorFarthest(Revit.Elements.Element? element1,
Revit.Elements.Element? element2)
{
ConnectorSet? connectorSet = GetConnectorSet(element1);
if (connectorSet == null)
{
return null;
}

List<Autodesk.Revit.DB.Connector?> connectorSet = GetConnectors(element1);
Autodesk.Revit.DB.Connector? connector = GetConnectorFarthest(element2, connectorSet);
return connector;
}
Expand All @@ -230,15 +225,15 @@ public static double Radius(Autodesk.Revit.DB.Connector connector)
/// Get Farthest Connector With Element
/// </summary>
/// <param name="element">element to check</param>
/// <param name="connectorSet">an collection connectors</param>
/// <param name="connectors">an collection connectors</param>
/// <returns name="connector">farthest connector</returns>
internal static Autodesk.Revit.DB.Connector? GetConnectorFarthest(Revit.Elements.Element? element,
ConnectorSet? connectorSet)
List<Autodesk.Revit.DB.Connector?> connectors)
{
Autodesk.Revit.DB.Connector? farthest = null;
Point? locationCenter = global::OpenMEP.Element.Element.LocationCenter(element);
double distance = Double.MaxValue;
foreach (Autodesk.Revit.DB.Connector? connector in connectorSet!)
double distance = Double.MinValue;
foreach (Autodesk.Revit.DB.Connector? connector in connectors!)
{
if (locationCenter != null)
{
Expand Down Expand Up @@ -605,11 +600,14 @@ public static double AssignedKCoefficient(Autodesk.Revit.DB.Connector connector)
/// <returns name="element">element has connected with connector</returns>
public static Revit.Elements.Element? GetElementConnectedWith(Autodesk.Revit.DB.Connector connector)
{
if (connector == null) throw new ArgumentNullException(nameof(connector));
if (connector.IsConnected)
{
return connector.AllRefs.Cast<Autodesk.Revit.DB.Connector>().First().Owner.ToDynamoType();
return connector.AllRefs.Cast<Autodesk.Revit.DB.Connector>()
.Where(x=>x.Owner.Id!=connector.Owner.Id)
.Where(x => x.ConnectorType != ConnectorType.Logical)
.Select(x => x.Owner.ToDynamoType()).FirstOrDefault();
}

return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"ConcreteType": "Dynamo.Nodes.DSModelElementSelection, DSRevitNodesUI",
"NodeType": "ExtensionNode",
"InstanceId": [
"4aded12f-bb3e-43d3-a764-654a0a8454e4-00098720"
"be616ece-f29c-41ea-90be-1913ce942448-00094146"
],
"Id": "933da09ce5494d8e8ff9a9e935c8266f",
"Inputs": [],
Expand All @@ -30,14 +30,35 @@
],
"Replication": "Disabled"
},
{
"ConcreteType": "Dynamo.Nodes.DSModelElementSelection, DSRevitNodesUI",
"NodeType": "ExtensionNode",
"InstanceId": [
"be616ece-f29c-41ea-90be-1913ce942448-00094147"
],
"Id": "84ddd8ae072b487086eb86ae672934f8",
"Inputs": [],
"Outputs": [
{
"Id": "ed7bd73c577f4418b7c363d4618415ee",
"Name": "Element",
"Description": "The selected elements.",
"UsingDefaultValue": false,
"Level": 2,
"UseLevels": false,
"KeepListStructure": false
}
],
"Replication": "Disabled"
},
{
"ConcreteType": "Dynamo.Graph.Nodes.ZeroTouch.DSFunction, DynamoCore",
"NodeType": "FunctionNode",
"FunctionSignature": "Exyte.Revit.MEPModel[email protected],Revit.Elements.Element",
"Id": "96d641ab37ba4402a3aba521f0d2b346",
"FunctionSignature": "OpenMEP.ConnectorManager[email protected],Revit.Elements.Element",
"Id": "78c050b27eaa41378389c5c648afc655",
"Inputs": [
{
"Id": "0e6d7e7e296b4233965a5aa6e3d5447f",
"Id": "4a15f03771a849e483ac4c03f7eee768",
"Name": "element1",
"Description": "first element\n\nElement",
"UsingDefaultValue": false,
Expand All @@ -46,7 +67,7 @@
"KeepListStructure": false
},
{
"Id": "37610db8d29b4b45975dc04494a573d5",
"Id": "cd86016fd4ec4571b10d81dcd4effe64",
"Name": "element2",
"Description": "second element\n\nElement",
"UsingDefaultValue": false,
Expand All @@ -57,62 +78,41 @@
],
"Outputs": [
{
"Id": "590ccf9c9ed64e3bab0a9567facd809e",
"Id": "faadcc2fca994cb58e6c19009fbe0f87",
"Name": "connector",
"Description": "farthest connector of fist element with second element",
"Description": "Farthest connector of element1",
"UsingDefaultValue": false,
"Level": 2,
"UseLevels": false,
"KeepListStructure": false
}
],
"Replication": "Auto",
"Description": "return farthest connector between two element\n\nConnector.GetConnectorFarthest (element1: Element, element2: Element): var"
},
{
"ConcreteType": "Dynamo.Nodes.DSModelElementSelection, DSRevitNodesUI",
"NodeType": "ExtensionNode",
"InstanceId": [
"4aded12f-bb3e-43d3-a764-654a0a8454e4-00098720"
],
"Id": "84ddd8ae072b487086eb86ae672934f8",
"Inputs": [],
"Outputs": [
{
"Id": "ed7bd73c577f4418b7c363d4618415ee",
"Name": "Element",
"Description": "The selected elements.",
"UsingDefaultValue": false,
"Level": 2,
"UseLevels": false,
"KeepListStructure": false
}
],
"Replication": "Disabled"
"Description": "Return Farthest Connector between element1 from element2\n\nConnector.GetConnectorFarthest (element1: Element, element2: Element): var"
}
],
"Connectors": [
{
"Start": "bc3d8a2f13064925b0f7243b7ab8d156",
"End": "0e6d7e7e296b4233965a5aa6e3d5447f",
"Id": "82efc67048b3400c9b503fe9502d88ea",
"End": "4a15f03771a849e483ac4c03f7eee768",
"Id": "8906af616a614bd49724919464fd7d29",
"IsHidden": "False"
},
{
"Start": "ed7bd73c577f4418b7c363d4618415ee",
"End": "37610db8d29b4b45975dc04494a573d5",
"Id": "2409036a85a44637b9c70887ed88cc72",
"End": "cd86016fd4ec4571b10d81dcd4effe64",
"Id": "7ddfe56c6d874ad5aa464a25ea2d0275",
"IsHidden": "False"
}
],
"Dependencies": [],
"NodeLibraryDependencies": [
{
"Name": "Exyte",
"Version": "1.0.1",
"Name": "OpenMEP",
"Version": "1.0.0",
"ReferenceType": "Package",
"Nodes": [
"96d641ab37ba4402a3aba521f0d2b346"
"78c050b27eaa41378389c5c648afc655"
]
}
],
Expand Down Expand Up @@ -174,29 +174,29 @@
"Y": 47.66857901662172
},
{
"Name": "Connector.GetConnectorFarthest",
"Name": "Select Model Element",
"ShowGeometry": true,
"Id": "96d641ab37ba4402a3aba521f0d2b346",
"Id": "84ddd8ae072b487086eb86ae672934f8",
"IsSetAsInput": false,
"IsSetAsOutput": false,
"Excluded": false,
"X": 691.0304802560803,
"Y": 85.214248708368117
"X": 322.287764461925,
"Y": 214.87863420638075
},
{
"Name": "Select Model Element",
"Name": "Connector.GetConnectorFarthest",
"ShowGeometry": true,
"Id": "84ddd8ae072b487086eb86ae672934f8",
"Id": "78c050b27eaa41378389c5c648afc655",
"IsSetAsInput": false,
"IsSetAsOutput": false,
"Excluded": false,
"X": 318.29575711222788,
"Y": 197.1997445148649
"X": 629.09107257563983,
"Y": 113.98429002584527
}
],
"Annotations": [],
"X": -185.68967427309019,
"Y": 114.91770839408963,
"Zoom": 1.1917937712929563
"X": -468.52478404786416,
"Y": 56.538597228254616,
"Zoom": 1.2928910957911353
}
}
Loading

0 comments on commit fe9ca76

Please sign in to comment.