Skip to content

Commit

Permalink
add PickOrderLinkElements
Browse files Browse the repository at this point in the history
  • Loading branch information
chuongmep committed Aug 29, 2023
1 parent 1413f7a commit 7f2d0aa
Show file tree
Hide file tree
Showing 3 changed files with 205 additions and 5 deletions.
55 changes: 50 additions & 5 deletions OpenMEPRevit/Document/Selection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Revit.GeometryConversion;
using RevitServices.Persistence;
using RevitServices.Transactions;
using OperationCanceledException = Autodesk.Revit.Exceptions.OperationCanceledException;
using Point = Autodesk.DesignScript.Geometry.Point;

namespace OpenMEPRevit.Document;
Expand Down Expand Up @@ -213,6 +214,50 @@ public static List<Point> PickPointOnCurveElement(bool flag)
}
}

/// <summary>
/// Retrieves a list of linked elements from the host Revit document based on the user's selection.
/// </summary>
/// <param name="flag">A boolean flag indicating fresh the selection process.</param>
/// <returns>A list of Revit elements from linked documents.</returns>
/// <exception cref="System.ArgumentException">Thrown when an error occurs during the element retrieval process.</exception>
/// <example>
/// ![](../OpenMEPPage/document/dyn/pic/Selection.PickOrderLinkElements.png)
/// [Selection.PickOrderLinkElements.dyn](../OpenMEPPage/document/dyn/Selection.PickOrderLinkElements.dyn)
/// </example>
public static List<Revit.Elements.Element> PickOrderLinkElements(bool flag)
{
List<Revit.Elements.Element> elements = new List<Revit.Elements.Element>();
UIDocument uiDoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument;
Autodesk.Revit.DB.Document doc = uiDoc.Document;
if (doc==null) return elements;
try
{
StringBuilder sb = new StringBuilder();
sb.AppendLine("1.Select Ordered By Pick Link Element");
sb.AppendLine("2.Press Esc to Cancel");
TaskDialog.Show("OpenMEP", sb.ToString(), TaskDialogCommonButtons.Ok);
while (true)
{
var reference = uiDoc.Selection.PickObject(ObjectType
.LinkedElement);
var representation = reference.ConvertToStableRepresentation(doc).Split(':')[0];
var parsedReference = Reference.ParseFromStableRepresentation(doc, representation);
var revitLinkInstance = (RevitLinkInstance)doc.GetElement(parsedReference);
var linkedDocument = revitLinkInstance.GetLinkDocument();
var linkedElement = linkedDocument.GetElement(reference.LinkedElementId);
Revit.Elements.Element? element = linkedElement.ToDynamoType();
elements.Add(element);
}
}
catch (OperationCanceledException e)
{
return elements;
}
catch (Exception e)
{
throw new ArgumentException(e.Message);
}
}

/// <summary>
/// Pick Element By Rectangle In Current View
Expand Down Expand Up @@ -303,6 +348,7 @@ public static List<Point> PickPointOnCurveElement(bool flag)
return elements;
}


/// <summary>
/// Set selected element in Revit Project
/// </summary>
Expand Down Expand Up @@ -340,6 +386,7 @@ public static void ZoomToElement(List<Revit.Elements.Element> elements)
ZoomToLinkElement(elements);
return;
}

if (!elements.Any()) return;
List<ElementId> elementIds = new List<ElementId>();
elements.ForEach(x => elementIds.Add(x.InternalElement.Id));
Expand All @@ -357,9 +404,9 @@ public static void ZoomToElement(List<Revit.Elements.Element> elements)
/// ![](../OpenMEPPage/document/dyn/pic/Selection.ZoomToLinkElement.png)
/// [Selection.ZoomToLinkElement.dyn](../OpenMEPPage/document/dyn/Selection.ZoomToLinkElement.dyn)
/// </example>
public static void ZoomToLinkElement(List<Revit.Elements.Element> elements,bool isCropView=false)
public static void ZoomToLinkElement(List<Revit.Elements.Element> elements, bool isCropView = false)
{
if(elements==null) throw new ArgumentNullException($"{nameof(elements)} is null");
if (elements == null) throw new ArgumentNullException($"{nameof(elements)} is null");
UIDocument uidoc = DocumentManager.Instance.CurrentUIDocument;
ElementId viewId = uidoc.ActiveView.Id;
List<UIView> uiViews = uidoc.GetOpenUIViews().Where(x => x.ViewId == viewId).ToList();
Expand All @@ -379,6 +426,7 @@ public static void ZoomToLinkElement(List<Revit.Elements.Element> elements,bool
Math.Max(boundingBoxXYZ.Max.Y, boundingBox.Max.Y),
Math.Max(boundingBoxXYZ.Max.Z, boundingBox.Max.Z));
}

uiView.ZoomAndCenterRectangle(boundingBoxXYZ.Min, boundingBoxXYZ.Max);
if (isCropView)
{
Expand All @@ -389,10 +437,7 @@ public static void ZoomToLinkElement(List<Revit.Elements.Element> elements,bool
TransactionManager.Instance.TransactionTaskDone();
}
}





[IsVisibleInDynamoLibrary(false)]
public class SelectionFilter : ISelectionFilter
Expand Down
155 changes: 155 additions & 0 deletions docs/OpenMEPPage/document/dyn/Selection.PickOrderLinkElements.dyn
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
{
"Uuid": "c33a46da-65ac-4ade-a0ff-de530639f054",
"IsCustomNode": false,
"Description": "",
"Name": "Selection.PickOrderLinkElements",
"ElementResolver": {
"ResolutionMap": {}
},
"Inputs": [],
"Outputs": [],
"Nodes": [
{
"ConcreteType": "CoreNodeModels.Input.BoolSelector, CoreNodeModels",
"NodeType": "BooleanInputNode",
"InputValue": true,
"Id": "0d2799e802424f7897d181cbae20591e",
"Inputs": [],
"Outputs": [
{
"Id": "57b8b94788d5491081602ba711fad0a5",
"Name": "",
"Description": "Boolean",
"UsingDefaultValue": false,
"Level": 2,
"UseLevels": false,
"KeepListStructure": false
}
],
"Replication": "Disabled",
"Description": "Selection between a true and false."
},
{
"ConcreteType": "Dynamo.Graph.Nodes.ZeroTouch.DSFunction, DynamoCore",
"NodeType": "FunctionNode",
"FunctionSignature": "OpenMEPRevit.Document.Selection.PickOrderLinkElements@bool",
"Id": "e91a09f465bc42c99a6110e571909465",
"Inputs": [
{
"Id": "2e4c81631f4e465fa7bff65da6e86c1f",
"Name": "flag",
"Description": "A boolean flag indicating fresh the selection process.\n\nbool",
"UsingDefaultValue": false,
"Level": 2,
"UseLevels": false,
"KeepListStructure": false
}
],
"Outputs": [
{
"Id": "f427b3c0807240ea8a75e600f2fe2cc5",
"Name": "Element[]",
"Description": "A list of Revit elements from linked documents.",
"UsingDefaultValue": false,
"Level": 2,
"UseLevels": false,
"KeepListStructure": false
}
],
"Replication": "Auto",
"Description": "Retrieves a list of linked elements from the host Revit document based on the user's selection.\n\nSelection.PickOrderLinkElements (flag: bool): Element[]"
}
],
"Connectors": [
{
"Start": "57b8b94788d5491081602ba711fad0a5",
"End": "2e4c81631f4e465fa7bff65da6e86c1f",
"Id": "806b7cba870d4f55a6a0ff829ed3c46d",
"IsHidden": "False"
}
],
"Dependencies": [],
"NodeLibraryDependencies": [
{
"Name": "OpenMEP",
"Version": "1.0.0",
"ReferenceType": "Package",
"Nodes": [
"e91a09f465bc42c99a6110e571909465"
]
}
],
"Thumbnail": "",
"GraphDocumentationURL": null,
"ExtensionWorkspaceData": [
{
"ExtensionGuid": "28992e1d-abb9-417f-8b1b-05e053bee670",
"Name": "Properties",
"Version": "2.16",
"Data": {}
},
{
"ExtensionGuid": "DFBD9CC0-DB40-457A-939E-8C8555555A9D",
"Name": "Generative Design",
"Version": "3.0",
"Data": {}
}
],
"Author": "",
"Linting": {
"activeLinter": "None",
"activeLinterId": "7b75fb44-43fd-4631-a878-29f4d5d8399a",
"warningCount": 0,
"errorCount": 0
},
"Bindings": [],
"View": {
"Dynamo": {
"ScaleFactor": 1.0,
"HasRunWithoutCrash": true,
"IsVisibleInDynamoLibrary": true,
"Version": "2.16.1.2727",
"RunType": "Automatic",
"RunPeriod": "1000"
},
"Camera": {
"Name": "Background Preview",
"EyeX": -17.0,
"EyeY": 24.0,
"EyeZ": 50.0,
"LookX": 12.0,
"LookY": -13.0,
"LookZ": -58.0,
"UpX": 0.0,
"UpY": 1.0,
"UpZ": 0.0
},
"ConnectorPins": [],
"NodeViews": [
{
"Name": "Boolean",
"ShowGeometry": true,
"Id": "0d2799e802424f7897d181cbae20591e",
"IsSetAsInput": false,
"IsSetAsOutput": false,
"Excluded": false,
"X": 53.485963228311789,
"Y": 563.83377179848321
},
{
"Name": "Selection.PickOrderLinkElements",
"ShowGeometry": true,
"Id": "e91a09f465bc42c99a6110e571909465",
"IsSetAsInput": false,
"IsSetAsOutput": false,
"Excluded": false,
"X": 276.13429152917359,
"Y": 580.177847669747
}
],
"Annotations": [],
"X": 56.682041624627914,
"Y": -436.76396078146468,
"Zoom": 1.442589092933134
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 7f2d0aa

Please sign in to comment.