protected override void SolveInstance(IGH_DataAccess DA) { IGH_Component Component = this; GH_Document GrasshopperDocument = this.OnPingDocument(); List <object> data = new List <object>(); string groupName = ""; bool trigger = false; object template = null; DA.GetDataList <object>(0, data); DA.GetData <string>(1, ref groupName); DA.GetData <object>(2, ref template); DA.GetData <bool>(3, ref trigger); // Trigger input if (!trigger) { return; } // Taking out the position and attributes of the template panel Grasshopper.Kernel.IGH_Param templateInput = Component.Params.Input[2]; IList <Grasshopper.Kernel.IGH_Param> sources = templateInput.Sources; if (!sources.Any()) { return; } IGH_DocumentObject templateComp = sources[0].Attributes.GetTopLevel.DocObject; IGH_Attributes att = templateComp.Attributes; // taking out the measures from the template panel and adding a shift RectangleF bounds = att.Bounds; int vShift = (int)Math.Round(bounds.Height) + 10; float refX = bounds.X; float refY = bounds.Y + 30 + vShift; int nbCopy = data.Count; // Creating a group, naming it, assigning color, adding it to the document Grasshopper.Kernel.Special.GH_Group g = new Grasshopper.Kernel.Special.GH_Group(); g.NickName = groupName; g.Colour = Grasshopper.GUI.Canvas.GH_Skin.group_back; GrasshopperDocument.AddObject(g, false); // Putting in all the new components in the document and grouping them for (int i = 0; i < nbCopy; i++) { Grasshopper.Kernel.Parameters.Param_GenericObject comp = new Grasshopper.Kernel.Parameters.Param_GenericObject(); comp.CreateAttributes(); comp.SetPersistentData(data[i]); float w = comp.Attributes.Bounds.Width; comp.Attributes.Pivot = new PointF(refX + w / 2, refY + i * vShift); GrasshopperDocument.AddObject(comp, false); g.AddObject(comp.InstanceGuid); } GrasshopperDocument.DeselectAll(); }
// Originally this was done from the right-click menu. // It has since been changed to run whenever parameters are added/removed private void SyncInputs() { // Find out how many parameters there are and if inputs should be added or removed. if (inputParameters.Count == Params.Input.Count - 6) { // Parameters quantities match up with inputs, do nothing RefreshParameters(); return; } RecordUndoEvent("Sync Inputs"); // Check if we need to add inputs if (inputParameters.Count > Params.Input.Count - 6) { for (int i = Params.Input.Count + 1; i <= inputParameters.Count + 6; i++) { Grasshopper.Kernel.Parameters.Param_GenericObject param = new Grasshopper.Kernel.Parameters.Param_GenericObject { Name = "Parameter" + (i - 6).ToString(CultureInfo.InvariantCulture), NickName = "P" + (i - 6).ToString(CultureInfo.InvariantCulture), Description = "Parameter Name: " + inputParameters[i - 7].ParameterName + "\nIs Type: " + inputParameters[i - 7].IsType.ToString() + "\nStorageType: " + inputParameters[i - 7].StorageType, Optional = true, Access = GH_ParamAccess.tree }; Params.RegisterInputParam(param); } } // Remove unnecessay inputs else if (inputParameters.Count < Params.Input.Count - 6) { while (Params.Input.Count > inputParameters.Count + 6) { IGH_Param param = Params.Input[Params.Input.Count - 1]; Params.UnregisterInputParameter(param); } } RefreshParameters(); Params.OnParametersChanged(); ExpireSolution(true); }
private void AdjustParams() { #region Invidual Outputs if (individualOutputs) { int nonWayParams = 1; if (show3dMenuItem.Enabled && show3d) { nonWayParams = 2; } if (Params.Output.Count < selectedTypes.Count + nonWayParams) { // Add parameters for (int i = Params.Output.Count - 1; i <= selectedTypes.Count - nonWayParams; i++) { try { IGH_Param param = new Grasshopper.Kernel.Parameters.Param_GenericObject(); Params.RegisterOutputParam(param); } catch { } } } else if (Params.Output.Count > selectedTypes.Count + nonWayParams) { // Remove parameters for (int i = Params.Output.Count - 1; i >= selectedTypes.Count + nonWayParams; i--) { try { Params.UnregisterOutputParameter(Params.Output[i]); } catch { } } } // reset the parameters based on the selected types for (int i = 0; i < Params.Output.Count - nonWayParams; i++) { try { Params.Output[i].Name = selectedTypes[i]; Params.Output[i].NickName = selectedTypes[i]; Params.Output[i].Access = GH_ParamAccess.tree; } catch (Exception ex) { System.Windows.Forms.MessageBox.Show("Error\n" + ex.Message); } } if (show3d && show3dMenuItem.Enabled) { Params.Output[Params.Output.Count - 1].Name = "Buildings"; Params.Output[Params.Output.Count - 1].NickName = "Bldg"; Params.Output[Params.Output.Count - 1].Description = "3d massing of buildings from the OSM data."; Params.Output[Params.Output.Count - 1].Access = GH_ParamAccess.tree; } // Set the last output to be the way's Key Params.Output[Params.Output.Count - nonWayParams].Name = "Feature Key"; Params.Output[Params.Output.Count - nonWayParams].NickName = "K"; Params.Output[Params.Output.Count - nonWayParams].Description = "Key to identify ways from the OSM file."; Params.Output[Params.Output.Count - nonWayParams].Access = GH_ParamAccess.tree; } #endregion #region Single Outputs else { int paramCount = 2; if (show3d && show3dMenuItem.Enabled) { paramCount = 3; } if (Params.Output.Count < paramCount) { // Add parameters for (int i = Params.Output.Count - 1; i < paramCount - 1; i++) { try { IGH_Param param = new Grasshopper.Kernel.Parameters.Param_GenericObject(); Params.RegisterOutputParam(param); } catch { } } } else if (Params.Output.Count > paramCount) { // Remove parameters for (int i = Params.Output.Count - 1; i >= paramCount; i--) { try { Params.UnregisterOutputParameter(Params.Output[i]); } catch { } } } // Set the first output to be the ways Params.Output[0].Name = "Ways"; Params.Output[0].NickName = "W"; Params.Output[0].Description = "Point collections that represent Ways, Multi-Polygons, and Nodes from OSM."; Params.Output[0].Access = GH_ParamAccess.tree; int wayIndex = 1; if (show3d && show3dMenuItem.Enabled) { wayIndex = 2; Params.Output[1].Name = "Buildings"; Params.Output[1].NickName = "Bldg"; Params.Output[1].Description = "3d massing of buildings from the OSM data."; Params.Output[1].Access = GH_ParamAccess.tree; } // Set the last output to be the way's Key Params.Output[wayIndex].Name = "Feature Key"; Params.Output[wayIndex].NickName = "K"; Params.Output[wayIndex].Description = "Key to identify ways from the OSM file."; Params.Output[wayIndex].Access = GH_ParamAccess.tree; } #endregion Params.OnParametersChanged(); ExpireSolution(true); }