/// <summary> /// Get a dynFunction from a guid, also stores type internally info for future instantiation. /// And add the compiled node to the enviro /// As a side effect, any of its dependent nodes are also initialized. /// </summary> /// <param name="environment">The environment from which to get the </param> /// <param name="guid">Open a definition from a path, without instantiating the nodes or dependents</param> public bool GetNodeInstance(Guid guid, out dynFunction result) { var controller = dynSettings.Controller; if (!this.Contains(guid)) { result = null; return(false); } FunctionDefinition def = null; if (!this.IsInitialized(guid)) { if (!GetDefinitionFromPath(guid, out def)) { result = null; return(false); } } else { def = this.loadedNodes[guid]; } dynWorkspaceModel ws = def.Workspace; IEnumerable <string> inputs = ws.Nodes.Where(e => e is dynSymbol) .Select(s => (s as dynSymbol).Symbol); IEnumerable <string> outputs = ws.Nodes.Where(e => e is dynOutput) .Select(o => (o as dynOutput).Symbol); if (!outputs.Any()) { var topMost = new List <Tuple <int, dynNodeModel> >(); IEnumerable <dynNodeModel> topMostNodes = ws.GetTopMostNodes(); foreach (dynNodeModel topNode in topMostNodes) { foreach (int output in Enumerable.Range(0, topNode.OutPortData.Count)) { if (!topNode.HasOutput(output)) { topMost.Add(Tuple.Create(output, topNode)); } } } outputs = topMost.Select(x => x.Item2.OutPortData[x.Item1].NickName); } result = controller.DynamoViewModel.CreateFunction(inputs, outputs, def); result.NickName = ws.Name; return(true); }
/// <summary> /// Get a guid from the name of a node. If it doesn't exist, returns Guid.Empty. /// </summary> /// <param name="guid">Open a definition from a path, without instantiating the nodes or dependents</param> public bool GetNodeInstance(DynamoController controller, string name, out dynFunction result) { if (!this.Contains(name)) { result = null; return(false); } return(this.GetNodeInstance(controller, GetGuidFromName(name), out result)); }