protected override void SolveInstance(IGH_DataAccess DA) { // Declare a variable for the input String string filename = null; bool activate = false; // 1. Declare placeholder variables and assign initial invalid data. // This way, if the input parameters fail to supply valid data, we know when to abort. // 2. Retrieve input data. if (!DA.GetData(0, ref filename)) { return; } if (!DA.GetData(1, ref activate)) { return; } // If the retrieved data is Nothing, we need to abort. if (filename == null) { return; } if (!File.Exists(filename)) { return; } if (activate) { GH_Cluster cluster = new GH_Cluster(); cluster.CreateFromFilePath(filename); GH_Document doc = OnPingDocument(); doc.AddObject(cluster, false); } }
protected override void SolveInstance(IGH_DataAccess DA) { bool S = false; DA.GetData(0, ref S); PythonScript script = PythonScript.Create(); script.SetVariable("bakeornot", S ? 1 : 0); script.ExecuteScript("import scriptcontext as sc\nsc.sticky['NOAH_BAKE_INFO'] = bakeornot"); foreach (IGH_DocumentObject obj in ghDoc.Objects) { if (obj is GH_Cluster) { GH_Cluster objCluster = (GH_Cluster)obj; GH_Document clusterDoc = objCluster.Document(""); foreach (IGH_DocumentObject clusterObj in clusterDoc.Objects) { if (clusterObj.ComponentGuid == new Guid("79EF4718-2B5A-4BFF-AB97-76A036598DB9")) { clusterObj.ExpireSolution(true); } } obj.ExpireSolution(true); } else { if (obj.ComponentGuid == new Guid("79EF4718-2B5A-4BFF-AB97-76A036598DB9")) { obj.ExpireSolution(true); } } } }
/*******************************************/ protected override void SolveInstance(IGH_DataAccess DA) { BH.Engine.Base.Compute.ClearCurrentEvents(); try { // Get the input component IGH_Param source = Params.Input[0].Sources.FirstOrDefault(); if (source == null) { return; } IGH_DocumentObject component = source.Attributes.GetTopLevel.DocObject; GH_Cluster cluster = source.Attributes.GetTopLevel.DocObject as GH_Cluster; List <IGH_DocumentObject> content = cluster.Document("").Objects.ToList(); List <GH_ClusterInputHook> inputs = content.OfType <GH_ClusterInputHook>().ToList(); List <GH_ClusterOutputHook> outputs = content.OfType <GH_ClusterOutputHook>().ToList(); List <GH_Component> components = content.OfType <GH_Component>().ToList(); List <GH_Group> groups = content.OfType <GH_Group>().ToList(); List <IGH_Param> parameters = content.OfType <IGH_Param>().ToList(); groups = groups.Except(groups.SelectMany(x => x.Objects().OfType <GH_Group>())).ToList(); ClusterContent nodeContent = new ClusterContent { Name = cluster.NickName, Inputs = inputs.Select(x => new DataParam { Name = x.NickName, Description = x.Description, TargetIds = x.Recipients.Select(r => r.InstanceGuid).ToList(), BHoM_Guid = x.InstanceGuid }).ToList(), Outputs = outputs.Select(x => new ReceiverParam { Name = x.NickName, Description = x.Description, SourceId = x.Sources.First().InstanceGuid, BHoM_Guid = x.InstanceGuid }).ToList(), InternalNodes = components.Select(x => ToNode(x)).Concat(parameters.Select(x => ToNode(x))).Where(x => x != null).ToList(), NodeGroups = ClearUnsafeGroups(groups.Select(x => x.ToNodeGroup()).ToList()), BHoM_Guid = cluster.InstanceGuid }; nodeContent = nodeContent.PopulateTypes(); DA.SetData(0, nodeContent); Helpers.ShowEvents(this, BH.Engine.Base.Query.CurrentEvents()); } catch (Exception e) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, e.Message); } }
protected override void SolveInstance(IGH_DataAccess DA) { // Declare a variable for the input String string filename = null; bool activate = false; Rhino.Geometry.Point3d point = Rhino.Geometry.Point3d.Unset; // 1. Declare placeholder variables and assign initial invalid data. // This way, if the input parameters fail to supply valid data, we know when to abort. // 2. Retrieve input data. if (!DA.GetData(0, ref filename)) { return; } if (!DA.GetData(1, ref activate)) { return; } if (!DA.GetData(2, ref point)) { return; } // If the retrieved data is Nothing, we need to abort. if (filename == null) { return; } if (!File.Exists(filename)) { return; } if (activate) { GH_Cluster cluster = new GH_Cluster(); cluster.CreateFromFilePath(filename); GH_Document doc = OnPingDocument(); doc.AddObject(cluster, false); Grasshopper.Kernel.Parameters.Param_Point paramIn = new Grasshopper.Kernel.Parameters.Param_Point(); Grasshopper.Kernel.Parameters.Param_Geometry paramOut = new Grasshopper.Kernel.Parameters.Param_Geometry(); paramIn.SetPersistentData(point); cluster.Params.RegisterInputParam(paramIn); cluster.Params.RegisterOutputParam(paramOut); cluster.CollectData(); cluster.ComputeData(); //Grasshopper.DataTree<object> test = new DataTree<object>(); //test.Add(paramIn, 0); DA.SetData(1, paramOut); } }
public void InitCluster() { debugText = ""; // if we had a previous document, then let's delete it and start over if (wormDoc != null) { wormDoc.Enabled = false; wormDoc.RemoveObject(wormCluster, false); wormDoc.Dispose(); wormDoc = null; } //////////////////////// // get clusterFileURL param again, since inputs may not have run if invalid //////////////////////// string clusterName = Params.Input[0].VolatileData.get_Branch(0)[0].ToString(); //////////////////////// // get clustername and process/validate into URL //////////////////////// string clusterUrl = processValidateClusterName(clusterName); //////////////////////// // set path for temporary file location //////////////////////// string tempPath = System.IO.Path.GetTempPath(); Uri uri = new Uri(clusterUrl); string filename = System.IO.Path.GetFileName(uri.LocalPath); fullTempFilePath = tempPath + filename; //////////////////////// // attempt to downloadCluster file //////////////////////// using (WebClient Client = new WebClient()) { try { Client.DownloadFile(clusterUrl, fullTempFilePath); } catch (WebException webEx) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Network error: " + webEx.Message); } } debugText += "Downloaded file " + clusterUrl + ", " + filename + "\n"; debugText += "into " + fullTempFilePath + "\n"; // if gh file doesn't exist in temporary location, abort if (!File.Exists(fullTempFilePath)) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "File does not exist!"); } //////////////////////// // Create a cluster //////////////////////// // create cluster wormCluster = new GH_Cluster(); wormCluster.CreateFromFilePath(fullTempFilePath); // set cluster parameter count clusterParamNumInput = wormCluster.Params.Input.Count; clusterParamNumOutput = wormCluster.Params.Output.Count; debugText += "\ncluster input params # = " + clusterParamNumInput; debugText += "\ncluster output params # = " + clusterParamNumOutput; // add/remove/rename parameters to match cluster parameter count. MatchParameterCount(); // change hairworm name to match cluster name if (wormCluster.Name == "Cluster") { HairwormClusterName = System.IO.Path.GetFileNameWithoutExtension(uri.LocalPath); HairwormClusterNickName = System.IO.Path.GetFileNameWithoutExtension(uri.LocalPath); } else { HairwormClusterName = wormCluster.Name; HairwormClusterNickName = wormCluster.NickName; } Name = HairwormBaseName + " (" + HairwormClusterName + ")"; NickName = HairwormBaseName + " (" + this.HairwormClusterNickName + ")"; debugText += "cluster is named = " + wormCluster.Name; debugText += "cluster is nicknamed = " + wormCluster.NickName; //get new document, enable it, and add cluster to it wormDoc = new GH_Document(); wormDoc.Enabled = true; wormDoc.AddObject(wormCluster, true, 0); // loading cluster worked. (it's important that this is almost last, because MatchParameterCount scans this to know when to disconnect params) loadedClusterUrlParam = clusterUrlParam; ExpireSolution(true); }
public void InitCluster() { debugText = ""; // if we had a previous document, then let's delete it and start over if (wormDoc != null) { wormDoc.Enabled = false; wormDoc.RemoveObject(wormCluster, false); wormDoc.Dispose(); wormDoc = null; } //////////////////////// // get clusterFileURL param again, since inputs may not have run if invalid //////////////////////// string clusterName = Params.Input[0].VolatileData.get_Branch(0)[0].ToString(); //////////////////////// // get clustername and process/validate into URL //////////////////////// string clusterUrl = processValidateClusterName(clusterName); //////////////////////// // set path for temporary file location //////////////////////// string tempPath = System.IO.Path.GetTempPath(); Uri uri = new Uri(clusterUrl); string filename = System.IO.Path.GetFileName(uri.LocalPath); fullTempFilePath = tempPath + filename; //////////////////////// // attempt to downloadCluster file //////////////////////// using (WebClient Client = new WebClient()) { try { Client.DownloadFile(clusterUrl, fullTempFilePath); } catch(WebException webEx) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Network error: " + webEx.Message); } } debugText += "Downloaded file " + clusterUrl + ", " + filename + "\n"; debugText += "into " + fullTempFilePath + "\n"; // if gh file doesn't exist in temporary location, abort if (!File.Exists(fullTempFilePath)) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "File does not exist!"); } //////////////////////// // Create a cluster //////////////////////// // create cluster wormCluster = new GH_Cluster(); wormCluster.CreateFromFilePath(fullTempFilePath); // set cluster parameter count clusterParamNumInput = wormCluster.Params.Input.Count; clusterParamNumOutput = wormCluster.Params.Output.Count; debugText += "\ncluster input params # = " + clusterParamNumInput; debugText += "\ncluster output params # = " + clusterParamNumOutput; // add/remove/rename parameters to match cluster parameter count. MatchParameterCount(); // change hairworm name to match cluster name if(wormCluster.Name == "Cluster") { HairwormClusterName = System.IO.Path.GetFileNameWithoutExtension(uri.LocalPath); HairwormClusterNickName = System.IO.Path.GetFileNameWithoutExtension(uri.LocalPath); } else { HairwormClusterName = wormCluster.Name; HairwormClusterNickName = wormCluster.NickName; } Name = HairwormBaseName + " (" + HairwormClusterName + ")"; NickName = HairwormBaseName + " (" + this.HairwormClusterNickName + ")"; debugText += "cluster is named = " + wormCluster.Name; debugText += "cluster is nicknamed = " + wormCluster.NickName; //get new document, enable it, and add cluster to it wormDoc = new GH_Document(); wormDoc.Enabled = true; wormDoc.AddObject(wormCluster, true, 0); // loading cluster worked. (it's important that this is almost last, because MatchParameterCount scans this to know when to disconnect params) loadedClusterUrlParam = clusterUrlParam; ExpireSolution(true); }