1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
| using Grasshopper.Kernel; using Rhino.Geometry; using System; using System.Collections.Generic;
namespace CustomGhComponents { public class ComponentWithDropDown : GH_Component { public ComponentWithDropDown() : base("DropDownComponent", "DropDown", "A component with dropdown menus", "Category", "Subcategory") { }
public override void CreateAttributes() { if (first) { FunctionToSetSelectedContent(0, 0); first = false; } m_attributes = new CustomUI.DropDownUIAttributes(this, FunctionToSetSelectedContent, dropdowncontents, selections, spacerDescriptionText); }
public void FunctionToSetSelectedContent(int dropdownListId, int selectedItemId) { if (dropdowncontents == null) { dropdowncontents = new List<List<string>>(); selections = new List<string>();
dropdowncontents.Add(dropdownTopLevelContent); selections.Add(dropdownTopLevelContent[0]);
dropdowncontents.Add(dropdownLevel2_A_Content); selections.Add(dropdownLevel2_A_Content[0]);
dropdownLevel2_Content.Add(dropdownLevel2_A_Content); dropdownLevel2_Content.Add(dropdownLevel2_B_Content); dropdownLevel2_Content.Add(dropdownLevel2_C_Content); dropdownLevel2_Content.Add(dropdownLevel2_D_Content); }
if (dropdownListId == 0) { dropdowncontents[1] = dropdownLevel2_Content[selectedItemId];
selections[1] = dropdowncontents[1][0]; }
if (dropdownListId == 1) { selections[1] = dropdowncontents[1][selectedItemId];
System.Windows.Forms.MessageBox.Show("You selected: " + dropdowncontents[1][selectedItemId]); }
Params.OnParametersChanged(); ExpireSolution(true); }
#region dropdownmenu content
List<List<string>> dropdowncontents; List<List<string>> dropdownLevel2_Content = new List<List<string>>();
List<string> selections; bool first = true; readonly List<string> spacerDescriptionText = new List<string>(new string[] { "TopLevel List", "Level2 Items" }); readonly List<string> dropdownTopLevelContent = new List<string>(new string[] { "ListA", "ListB", "ListC", "ListD" }); readonly List<string> dropdownLevel2_A_Content = new List<string>(new string[] { "Item A1", "Item A2", "Item A3", "Item A4", "Item A5", "Item A6", "Item A7", "Item A8", "Item A9", "Item A10", "Item A11", "Item A12", "Item A13", });
readonly List<string> dropdownLevel2_B_Content = new List<string>(new string[] { "Item B1", "Item B2", "Item B3", "Item B4", "Item B5", "Item B6", "Item B7", "Item B8", "Item B9", });
readonly List<string> dropdownLevel2_C_Content = new List<string>(new string[] { "Item C1", "Item C2", "Item C3", "Item C4", "Item C5", "Item C6", "Item C7", "Item C8", "Item C9", "Item C10", "Item C11", "Item C12", "Item C13", "Item C14", "Item C15", "Item C16", });
readonly List<string> dropdownLevel2_D_Content = new List<string>(new string[] { "Item D1", "Item D2", "Item D3", "Item D4", "Item D5", "Item D6", }); #endregion
protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager) { pManager.AddGenericParameter("Input1", "I1", "First Input", GH_ParamAccess.item); pManager[0].Optional = true; }
protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager) { pManager.AddGenericParameter("Output1", "O1", "First Output", GH_ParamAccess.item); }
protected override void SolveInstance(IGH_DataAccess DA) { DA.SetData(0, selections[1]); }
protected override System.Drawing.Bitmap Icon { get { return null; } }
public override Guid ComponentGuid { get { return new Guid("020959db-8b03-4a62-9a25-5b34e4e44812"); } } } }
|