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); } }