/// <summary> /// This function gets the nodes which have created the elements with the /// given element IDs /// </summary> /// <param name="ids">The given element IDs</param> /// <returns>the related nodes</returns> public static IEnumerable<NodeModel> GetNodesFromElementIds(IEnumerable<ElementId> ids) { List<NodeModel> nodes = new List<NodeModel>(); if (!ids.Any()) return nodes.AsEnumerable(); var workspace = dynSettings.Controller.DynamoModel.CurrentWorkspace; ProtoCore.Core core = null; if (dynSettings.Controller != null) { var engine = dynSettings.Controller.EngineController; if ((engine != null) && (engine.LiveRunnerCore != null)) core = engine.LiveRunnerCore; } if (core == null) return null; // Selecting all nodes that are either a DSFunction, // a DSVarArgFunction or a CodeBlockNodeModel into a list. var nodeGuids = workspace.Nodes.Where((n) => { return (n is DSFunction || (n is DSVarArgFunction) || (n is CodeBlockNodeModel)); }).Select((n) => n.GUID); var nodeTraceDataList = core.GetCallsitesForNodes(nodeGuids); List<ElementId> copiedIds = new List<ElementId>(ids); bool areElementsFoundForThisNode; foreach (Guid guid in nodeTraceDataList.Keys) { areElementsFoundForThisNode = false; List<ElementId> idsToRemove = new List<ElementId>(); foreach (ProtoCore.CallSite cs in nodeTraceDataList[guid]) { foreach (ProtoCore.CallSite.SingleRunTraceData srtd in cs.TraceData) { List<ISerializable> traceData = srtd.RecursiveGetNestedData(); foreach (ISerializable thingy in traceData) { SerializableId sid = thingy as SerializableId; if (sid != null) { ElementId tempId = null; foreach (var id in copiedIds) { if (sid.IntID == id.IntegerValue) { //FOUND ONE tempId = id; areElementsFoundForThisNode = true; } } if (tempId != null) copiedIds.Remove(tempId); if (!copiedIds.Any()) { if (areElementsFoundForThisNode) { NodeModel inm = workspace.Nodes.Where((n) => n.GUID == guid).FirstOrDefault(); nodes.Add(inm); } return nodes.AsEnumerable(); } } } } } if (areElementsFoundForThisNode) { NodeModel inm = workspace.Nodes.Where((n) => n.GUID == guid).FirstOrDefault(); nodes.Add(inm); } } return nodes.AsEnumerable(); }