void RefreshList() { var selectedItems = new List <string>(); { foreach (var item in ListItems) { if (item.Selected) { selectedItems.Add(item.Expression); } } } ListItems.Clear(); if (Revit.ActiveDBDocument != null) { foreach (var group in Revit.ActiveDBDocument.Settings.Categories.Cast <Category>().GroupBy((x) => x.CategoryType).OrderBy((x) => x.Key)) { foreach (var category in group.OrderBy((x) => x.Name)) { var item = new GH_ValueListItem(category.Name, category.Id.IntegerValue.ToString()); item.Selected = selectedItems.Contains(item.Expression); ListItems.Add(item); } } } }
public void RefreshList() { var selectedItems = ListItems.Where(x => x.Selected).Select(x => x.Expression).ToList(); ListItems.Clear(); var profileNames = new HashSet <string>(); var standards = Bricscad.Bim.BIMProfile.GetAllProfileStandards(null); foreach (var standard in standards) { foreach (var entry in Bricscad.Bim.BIMProfile.GetAllProfileNames(standard, null)) { foreach (var profileName in entry.Value) { if (!profileNames.Contains(profileName)) { var item = new GH_ValueListItem(profileName, "\"" + profileName + "\""); item.Selected = selectedItems.Contains(item.Expression); ListItems.Add(item); profileNames.Add(profileName); } } } } }
void RefreshList() { var selectedItems = new List <string>(); { foreach (var item in ListItems) { if (item.Selected) { selectedItems.Add(item.Expression); } } } ListItems.Clear(); if (Revit.ActiveDBDocument != null) { using (var collector = new FilteredElementCollector(Revit.ActiveDBDocument)) { foreach (var family in collector.OfClass(typeof(Family)).Cast <Family>().OrderBy((x) => x.Name)) { var item = new GH_ValueListItem(family.Name, family.Id.IntegerValue.ToString()); item.Selected = selectedItems.Contains(item.Expression); ListItems.Add(item); } } } }
protected override void CollectVolatileData_Custom() { var selectedItems = ListItems.Where(x => x.Selected).Select(x => x.Expression).ToList(); ListItems.Clear(); if (Revit.ActiveDBDocument is object) { foreach (var group in Revit.ActiveDBDocument.Settings.Categories.Cast <DB.Category>().GroupBy(x => x.CategoryType).OrderBy(x => x.Key)) { foreach (var category in group.OrderBy(x => x.Name).Where(x => CategoryIsInSet(x))) { if (category.CategoryType == DB.CategoryType.Invalid) { continue; } var item = new GH_ValueListItem(category.Name, category.Id.IntegerValue.ToString()); item.Selected = selectedItems.Contains(item.Expression); ListItems.Add(item); } } if (selectedItems.Count == 0 && ListMode != GH_ValueListMode.CheckList) { foreach (var item in ListItems) { item.Selected = item.Expression == ((int)DefaultBuiltInCategory).ToString(); } } } base.CollectVolatileData_Custom(); }
void RefreshList() { var selectedItems = ListItems.Where(x => x.Selected).Select(x => x.Expression).ToList(); ListItems.Clear(); if (Revit.ActiveDBDocument != null) { foreach (var group in Revit.ActiveDBDocument.Settings.Categories.Cast <Category>().GroupBy((x) => x.CategoryType).OrderBy((x) => x.Key)) { foreach (var category in group.OrderBy((x) => x.Name)) { var item = new GH_ValueListItem(category.Name, category.Id.IntegerValue.ToString()); item.Selected = selectedItems.Contains(item.Expression); ListItems.Add(item); } } // Preselect OST_GenericModel category by default if (selectedItems.Count == 0 && ListMode != GH_ValueListMode.CheckList) { foreach (var item in ListItems) { item.Selected = item.Expression == ((int)BuiltInCategory.OST_GenericModel).ToString(); } } } }
void RefreshList() { var selectedItems = new List <string>(); { foreach (var item in ListItems) { if (item.Selected) { selectedItems.Add(item.Expression); } } } ListItems.Clear(); if (Revit.ActiveDBDocument != null) { using (var collector = new FilteredElementCollector(Revit.ActiveDBDocument)) { foreach (var level in collector.OfClass(typeof(Level)).ToElements().Cast <Level>().OrderByDescending((x) => x.Elevation)) { var item = new GH_ValueListItem(level.Name, level.Id.IntegerValue.ToString()); item.Selected = selectedItems.Contains(item.Expression); ListItems.Add(item); } } } }
internal static bool CreateIfEmpty(GH_Document document, GH_Component component, ElementType type, string?selected = null) { var inputParam = component.Params.First(); if (inputParam.SourceCount > 0) { return(false); } var libraryParam = new LibraryParam { _type = type }; if (selected is not null) { var selectedItem = new GH_ValueListItem(selected, $"\"{selected}\"") { Selected = true }; libraryParam.ListItems.Add(selectedItem); } libraryParam.Update(); var pivot = component.Attributes.Pivot; libraryParam.Attributes.Pivot = new PointF(pivot.X - 240, pivot.Y - 21); document.AddObject(libraryParam, false); inputParam.AddSource(libraryParam); return(true); }
protected override void CollectVolatileData_Custom() { var selectedItems = ListItems.Where(x => x.Selected).Select(x => x.Expression).ToList(); ListItems.Clear(); if (Revit.ActiveDBDocument != null) { foreach (var group in Revit.ActiveDBDocument.Settings.Categories.Cast <Autodesk.Revit.DB.Category>().GroupBy(x => x.CategoryType).OrderBy(x => x.Key)) { foreach (var category in group.OrderBy(x => x.Name).Where(x => !x.IsHidden())) { if (CategoryType != CategoryType.Invalid && category.CategoryType != CategoryType) { continue; } var item = new GH_ValueListItem(category.Name, category.Id.IntegerValue.ToString()); item.Selected = selectedItems.Contains(item.Expression); ListItems.Add(item); } } // Preselect OST_GenericModel category by default if (selectedItems.Count == 0 && ListMode != GH_ValueListMode.CheckList) { foreach (var item in ListItems) { item.Selected = item.Expression == ((int)DefaultBuiltInCategory).ToString(); } } } base.CollectVolatileData_Custom(); }
private void SetDropdownBounds(GH_ValueListItem item, RectangleF bounds) { RectangleF rectangleF = new RectangleF(bounds.X, bounds.Y, 0f, bounds.Height); item.BoxLeft = rectangleF; rectangleF = new RectangleF(bounds.X, bounds.Y, bounds.Width - 22f, bounds.Height); item.BoxName = rectangleF; rectangleF = new RectangleF(bounds.Right - 22f, bounds.Y, 22f, bounds.Height); item.BoxRight = rectangleF; }
private void RenderDropDown(GH_Canvas canvas, Graphics graphics, Color color) { GH_ValueListItem firstSelectedItem = this.Owner.FirstSelectedItem; if (firstSelectedItem != null) { graphics.DrawString("30", GH_FontServer.Standard, Brushes.Black, firstSelectedItem.BoxName, GH_TextRenderingConstants.CenterCenter); RenderDownArrow(canvas, graphics, firstSelectedItem.BoxRight, color); } }
private void SetEmptyBounds(GH_ValueListItem item, RectangleF bounds) { RectangleF rectangleF = new RectangleF(bounds.X, bounds.Y, 0f, 0f); item.BoxLeft = rectangleF; rectangleF = new RectangleF(bounds.X, bounds.Y, 0f, 0f); item.BoxName = rectangleF; rectangleF = new RectangleF(bounds.X, bounds.Y, 0f, 0f); item.BoxRight = rectangleF; }
/// <summary> /// Creates a value list pre-populated with possible accent colors and adds it to the Grasshopper Document, located near the component pivot. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> private void CreateRasterList(object sender, System.EventArgs e) { string source = sender.ToString(); source = source.Replace("Create ", ""); source = source.Replace(" Source List", ""); GH_DocumentIO docIO = new GH_DocumentIO(); docIO.Document = new GH_Document(); ///Initialize object GH_ValueList vl = new GH_ValueList(); ///Clear default contents vl.ListItems.Clear(); foreach (var service in rasterJson["REST Raster"]) { if (service["source"].ToString() == source) { GH_ValueListItem vi = new GH_ValueListItem(service["service"].ToString(), String.Format("\"{0}\"", service["url"].ToString())); vl.ListItems.Add(vi); } } ///Set component nickname vl.NickName = source; ///Get active GH doc GH_Document doc = OnPingDocument(); if (docIO.Document == null) { return; } ///Place the object docIO.Document.AddObject(vl, false, 1); ///Get the pivot of the "URL" param PointF currPivot = Params.Input[4].Attributes.Pivot; ///Set the pivot of the new object vl.Attributes.Pivot = new PointF(currPivot.X - 400, currPivot.Y - 11); docIO.Document.SelectAll(); docIO.Document.ExpireSolution(); docIO.Document.MutateAllIds(); IEnumerable <IGH_DocumentObject> objs = docIO.Document.Objects; doc.DeselectAll(); doc.UndoUtil.RecordAddObjectEvent("Create REST Raster Source List", objs); doc.MergeDocument(docIO.Document); }
private void ValueMenuItem_Click(object sender, EventArgs e) { ToolStripMenuItem menuItem = (ToolStripMenuItem)sender; if (!menuItem.Checked) { GH_ValueListItem item = menuItem.Tag as GH_ValueListItem; if (item != null) { this.Owner.SelectItem(this.Owner.ListItems.IndexOf(item)); } } }
protected override void RefreshList(string ParamName) { var selectedItems = ListItems.Where(x => x.Selected).Select(x => x.Expression).ToList(); ListItems.Clear(); if (ParamName.Length == 0 || ParamName[0] == '\'') { return; } if (Revit.ActiveDBDocument != null) { int selectedItemsCount = 0; { foreach (var builtInParameter in Enum.GetNames(typeof(DB.BuiltInParameter))) { if (!builtInParameter.IsSymbolNameLike(ParamName)) { continue; } if (SourceCount == 0) { // If is a no pattern match update NickName case if (string.Equals(builtInParameter, ParamName, StringComparison.OrdinalIgnoreCase)) { ParamName = builtInParameter; } } var builtInParameterValue = (DB.BuiltInParameter)Enum.Parse(typeof(DB.BuiltInParameter), builtInParameter); var label = string.Empty; try { label = DB.LabelUtils.GetLabelFor(builtInParameterValue); } catch (Autodesk.Revit.Exceptions.InvalidOperationException) { } var item = new GH_ValueListItem(builtInParameter + " - \"" + label + "\"", ((int)builtInParameterValue).ToString()); item.Selected = selectedItems.Contains(item.Expression); ListItems.Add(item); selectedItemsCount += item.Selected ? 1 : 0; } } // If no selection and we are not in CheckList mode try to select default model types if (ListItems.Count == 0) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, string.Format("No ElementType found using pattern \"{0}\"", ParamName)); } } }
public PropCategoryPicker() : base() { Category = "BricsCAD"; SubCategory = GhUI.BimData; Name = "Property Categories"; NickName = "Property category"; Description = "Provides a category picker for all the property categories available in BricsCAD."; ListMode = GH_ValueListMode.DropDown; ListItems.Clear(); foreach (var suit in Enum.GetValues(typeof(Bricscad.Bim.BimCategory))) { var item = new GH_ValueListItem(suit.ToString(), ((int)suit).ToString()); ListItems.Add(item); } }
public void RefreshList() { var selectedItems = ListItems.Where(x => x.Selected).Select(x => x.Expression).ToList(); ListItems.Clear(); if (GhDrawingContext.LinkedDocument.Database != null) { var allStory = Bricscad.Bim.BIMBuilding.AllObjectBuildings(GhDrawingContext.LinkedDocument.Database); allStory.ForEach(building => { var item = new GH_ValueListItem(building.Name, "\"" + building.Name + "\""); item.Selected = selectedItems.Contains(item.Expression); ListItems.Add(item); }); } }
private void createAccentList(object sender, System.EventArgs e) { GH_ValueList vl = new GH_ValueList(); vl.ListItems.Clear(); foreach (string color in ACCENT_COLORS) { GH_ValueListItem vi = new GH_ValueListItem(color, String.Format("\"{0}\"", color)); vl.ListItems.Add(vi); } vl.NickName = "Accent Colors"; GH_Document doc = OnPingDocument(); doc.AddObject(vl, false, doc.ObjectCount + 1); PointF currPivot = Params.Input[3].Attributes.Pivot; vl.Attributes.Pivot = new PointF(currPivot.X - 120, currPivot.Y - 11); }
/// <summary> /// Creates a value list pre-populated with possible accent colors and adds it to the Grasshopper Document, located near the component pivot. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> private void createAccentList(object sender, System.EventArgs e) { GH_DocumentIO docIO = new GH_DocumentIO(); docIO.Document = new GH_Document(); //initialize object GH_ValueList vl = new GH_ValueList(); //clear default contents vl.ListItems.Clear(); //add all the accent colors as both "Keys" and values foreach (string color in ACCENT_COLORS) { GH_ValueListItem vi = new GH_ValueListItem(color, String.Format("\"{0}\"", color)); vl.ListItems.Add(vi); } //set component nickname vl.NickName = "Accent Colors"; //get active GH doc GH_Document doc = OnPingDocument(); if (docIO.Document == null) { return; } // place the object docIO.Document.AddObject(vl, false, 1); //get the pivot of the "accent" param PointF currPivot = Params.Input[3].Attributes.Pivot; //set the pivot of the new object vl.Attributes.Pivot = new PointF(currPivot.X - 120, currPivot.Y - 11); docIO.Document.SelectAll(); docIO.Document.ExpireSolution(); docIO.Document.MutateAllIds(); IEnumerable <IGH_DocumentObject> objs = docIO.Document.Objects; doc.DeselectAll(); doc.UndoUtil.RecordAddObjectEvent("Create Accent List", objs); doc.MergeDocument(docIO.Document); //doc.ScheduleSolution(10); }
private IGH_Param CreateTupleValueList(int d) { //instantiate new value list var valueList = new GH_ValueList(); valueList.CreateAttributes(); valueList.ListMode = GH_ValueListMode.Sequence; //populate value list with our own data valueList.ListItems.Clear(); for (int i = 0; i < ghGrid.Value.NodeDimCount[d]; i++) { var val = "" + i; var item = new GH_ValueListItem(val, val); valueList.ListItems.Add(item); } return(valueList); }
/*******************************************/ /**** Override Methods ****/ /*******************************************/ protected override void CollectVolatileData_Custom() { this.m_data.Clear(); List <GH_ValueListItem> .Enumerator enumerator = this.SelectedItems.GetEnumerator(); while (enumerator.MoveNext()) { GH_ValueListItem item = enumerator.Current; int index = 0; item.Value.CastTo <int>(out index); object result = Caller.Run(new List <object> { index }); this.m_data.Append(result.IToGoo(), new GH_Path(0)); } GH_Document doc = GH.Instances.ActiveCanvas.Document; Engine.UI.Compute.LogUsage("Grasshopper", GH.Versioning.VersionString, InstanceGuid, Caller.GetType().Name, Caller.SelectedItem, null, doc.DocumentID.ToString(), doc.FilePath); }
public static GH_ValueList CreateValueList(string name, Dictionary <string, string> valuePairs) { //initialize object Grasshopper.Kernel.Special.GH_ValueList vl = new Grasshopper.Kernel.Special.GH_ValueList(); //clear default contents vl.ListItems.Clear(); //set component nickname vl.NickName = name; vl.Name = name; foreach (KeyValuePair <string, string> entety in valuePairs) { GH_ValueListItem vi = new GH_ValueListItem(entety.Key, entety.Value); vl.ListItems.Add(vi); } return(vl); }
private IGH_Param CreateNumberValueList(int d) { //instantiate new value list var valueList = new GH_ValueList(); valueList.CreateAttributes(); valueList.ListMode = GH_ValueListMode.Cycle; //populate value list with our own data valueList.ListItems.Clear(); for (int i = 0; i < ghGrid.Value.NodeDimCount[d]; i++) { var val = String.Format("{0:F3}", ghGrid.Value.Data[d][i]); var item = new GH_ValueListItem(val, val); valueList.ListItems.Add(item); } return(valueList); }
void RefreshList() { var selectedItems = ListItems.Where(x => x.Selected).Select(x => x.Expression).ToList(); ListItems.Clear(); if (Revit.ActiveDBDocument != null) { using (var collector = new FilteredElementCollector(Revit.ActiveDBDocument)) { foreach (var family in collector.OfClass(typeof(Autodesk.Revit.DB.Family)).Cast <Autodesk.Revit.DB.Family>().OrderBy((x) => $"{x.FamilyCategory.Name} : {x.Name}")) { var item = new GH_ValueListItem($"{family.FamilyCategory.Name} : {family.Name}", family.Id.IntegerValue.ToString()); item.Selected = selectedItems.Contains(item.Expression); ListItems.Add(item); } } } }
void RefreshList() { var selectedItems = ListItems.Where(x => x.Selected).Select(x => x.Expression).ToList(); ListItems.Clear(); if (Revit.ActiveDBDocument is DB.Document doc) { using (var collector = new DB.FilteredElementCollector(doc)) { foreach (var level in collector.OfClass(typeof(DB.Level)).Cast <DB.Level>().OrderByDescending(x => x.GetHeight())) { var referenceId = FullUniqueId.Format(doc.GetFingerprintGUID(), level.UniqueId); var item = new GH_ValueListItem(level.Name, $"\"{ referenceId }\""); item.Selected = selectedItems.Contains(item.Expression); ListItems.Add(item); } } } }
protected override void CollectVolatileData_Custom() { this.m_data.Clear(); List <GH_ValueListItem> .Enumerator enumerator = this.SelectedItems.GetEnumerator(); try { Bool6D result = new Bool6D(); while (enumerator.MoveNext()) { GH_ValueListItem item = enumerator.Current; Direction value = (Direction)Enum.Parse(typeof(Direction), item.Expression); result = result.With(value, true); } this.m_data.Append(new Bool6DGoo(result), new GH_Path(0)); } finally { ((System.IDisposable)enumerator).Dispose(); } }
void RefreshList() { var selectedItems = ListItems.Where(x => x.Selected).Select(x => x.Expression).ToList(); ListItems.Clear(); if (Revit.ActiveDBDocument is DB.Document doc) { using (var collector = new DB.FilteredElementCollector(doc)) { foreach (var family in collector.OfClass(typeof(DB.Family)).Cast <DB.Family>().OrderBy((x) => $"{x.FamilyCategory.Name} : {x.Name}")) { var referenceId = FullUniqueId.Format(doc.GetFingerprintGUID(), family.UniqueId); var item = new GH_ValueListItem($"{family.FamilyCategory.Name} : {family.Name}", $"\"{ referenceId }\""); item.Selected = selectedItems.Contains(item.Expression); ListItems.Add(item); } } } }
public ElementTypePicker() { Category = "BricsCAD"; SubCategory = GhUI.BimData; Name = "BIM Types"; MutableNickName = false; Description = "Provides a type picker for all the BIM Types available in BricsCAD."; ListMode = GH_ValueListMode.DropDown; NickName = "BIM type"; var selectedItems = ListItems.Where(x => x.Selected).Select(x => x.Expression).ToList(); ListItems.Clear(); foreach (var suit in Enum.GetValues(typeof(Bricscad.Bim.BimTypeElement))) { var item = new GH_ValueListItem(suit.ToString(), ((int)suit).ToString()); item.Selected = selectedItems.Contains(item.Expression); ListItems.Add(item); } }
private void CreateAccentList(string[] values, string nick, int inputParam, int offsetX, int offsetY) { GH_DocumentIO docIO = new GH_DocumentIO(); docIO.Document = new GH_Document(); GH_ValueList vl = new GH_ValueList(); vl.ListItems.Clear(); foreach (string item in values) { GH_ValueListItem vi = new GH_ValueListItem(item, String.Format("\"{0}\"", item)); vl.ListItems.Add(vi); } vl.NickName = nick; GH_Document doc = OnPingDocument(); if (docIO.Document == null) { return; } docIO.Document.AddObject(vl, false, inputParam); PointF currPivot = Params.Input[inputParam].Attributes.Pivot; vl.Attributes.Pivot = new PointF(currPivot.X - offsetX, currPivot.Y + offsetY); docIO.Document.SelectAll(); docIO.Document.ExpireSolution(); docIO.Document.MutateAllIds(); IEnumerable <IGH_DocumentObject> objs = docIO.Document.Objects; doc.MergeDocument(docIO.Document); Component.Params.Input[inputParam].AddSource(vl); doc.DeselectAll(); }
//////////////////////////////////////////////////////////////////////// // Create a drop down to select supported robot if no robot selected. private void RobotOptionList() { // TODO: check instead if alreeady set. // Create robot Option List. GH_ValueList robotValueList = new GH_ValueList(); robotValueList.CreateAttributes(); robotValueList.Attributes.Pivot = new PointF(this.Attributes.Pivot.X - 300, this.Attributes.Pivot.Y - 41); robotValueList.ListItems.Clear(); robotValueList.NickName = "Robot"; // Add supported robot names. foreach (string robotName in HoloBot.listRobotNames) { GH_ValueListItem item = new GH_ValueListItem(robotName, "\"" + robotName + "\""); robotValueList.ListItems.Add(item); } // Update grasshopper document. GH_Document document = this.OnPingDocument(); document.AddObject(robotValueList, false); this.Params.Input[0].AddSource(robotValueList); this.Params.Input[0].CollectData(); }
protected override void CollectVolatileData_Custom() { List <GH_ValueListItem> .Enumerator enumerator = new List <GH_ValueListItem> .Enumerator(); this.m_data.Clear(); try { List <int> DOFs = new List <int>(); bool physical = false; enumerator = this.SelectedItems.GetEnumerator(); while (enumerator.MoveNext()) { GH_ValueListItem item = enumerator.Current; int DOF; item.Value.CastTo <int>(out DOF); DOFs.Add(DOF); if (DOF == 100) { physical = true; DOFs = new List <int> { 1, 2, 3 }; break; } } Guanaco.SupportType supportType = new SupportType(DOFs, physical); this.m_data.Append(GH_Convert.ToGoo(supportType), new GH_Path(0)); } finally { enumerator.Dispose(); } }