/// <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 static void MergeDocuments(GH_DocumentIO docIO, GH_Document doc, string name = "Merge") { docIO.Document.SelectAll(); docIO.Document.ExpireSolution(); docIO.Document.MutateAllIds(); IEnumerable <IGH_DocumentObject> objs = docIO.Document.Objects; doc.DeselectAll(); doc.UndoUtil.RecordAddObjectEvent(name, objs); doc.MergeDocument(docIO.Document); //doc.ScheduleSolution(10); }
/// <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 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(); }
// This is the method that actually does the work. protected override void SolveInstance(IGH_DataAccess DA) { // Creating this component in the grasshopperdocument IGH_Component Component = this; GH_Document GrasshopperDocument = this.OnPingDocument(); // Creating input parameters //object component = null; int nbCopy = 0; string groupName = null; bool trigger = false; // Getting the data from Grasshopper //DA.GetData<object>(0, ref component); DA.GetData <string>(1, ref groupName); DA.GetData <int>(2, ref nbCopy); DA.GetData <bool>(3, ref trigger); // If the botton is pressed it will proceed if (!trigger) { return; } Grasshopper.Kernel.IGH_Param selNumsInput = Component.Params.Input[0]; IList <Grasshopper.Kernel.IGH_Param> sources = selNumsInput.Sources; if (!sources.Any()) { return; } IGH_DocumentObject comp = sources[0].Attributes.GetTopLevel.DocObject; // Gets component attributes like the bounds of the component which is used to shift // the next one and get the size of the panels IGH_Attributes att = comp.Attributes; RectangleF bounds = att.Bounds; int vShift = (int)Math.Round(bounds.Height) + 10; int vStart = 30 + vShift; List <Guid> objectsToCopy = new List <Guid>(); objectsToCopy.Add(comp.InstanceGuid); // Creating a Grasshopper Group g and assignning a nickname and color to it. // Adding group g to the GrasshopperDocument 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); List <IGH_Component> components = new List <IGH_Component>(); // For-loop used to duplicate component and to assign properties to it (size, datalist...) for (int i = 0; i < nbCopy; i++) { GH_DocumentIO documentIO = new GH_DocumentIO(GrasshopperDocument); documentIO.Copy(GH_ClipboardType.System, objectsToCopy); documentIO.Paste(GH_ClipboardType.System); documentIO.Document.TranslateObjects(new Size(0, vStart + i * vShift), false); documentIO.Document.SelectAll(); documentIO.Document.MutateAllIds(); GrasshopperDocument.DeselectAll(); GrasshopperDocument.MergeDocument(documentIO.Document); g.AddObject(documentIO.Document.Objects[0].InstanceGuid); } GrasshopperDocument.DeselectAll(); }
// This is the method that actually does the work. protected override void SolveInstance(IGH_DataAccess DA) { IGH_Component Component = this; GH_Document GrasshopperDocument = this.OnPingDocument(); // Creating input parameters List <string> data = new List <string>(); string groupName = ""; bool trigger = false; object template = null; // Getting the data from Grasshopper DA.GetDataList <string>(0, data); DA.GetData <string>(1, ref groupName); DA.GetData <object>(2, ref template); DA.GetData <bool>(3, ref trigger); // If the botton is pressed it will proceed if (!trigger) { return; } // Detecting the the source parameter for the templateInput 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; // Gets component attributes like the bounds of the Panel which is used to shift //the next one and get the size of the panels IGH_Attributes att = templateComp.Attributes; RectangleF bounds = att.Bounds; int vShift = (int)Math.Round(bounds.Height) + 10; float refX = bounds.X; float refY = bounds.Y + 30 + vShift; // Creating a Grasshopper Group g and assignning a nickname and color to it. //Adding group g to the GrasshopperDocument 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); List <IGH_Component> components = new List <IGH_Component>(); // For-loop used to create panels and assign properties to it (size, datalist...) int nbCopy = data.Count; for (int i = 0; i < nbCopy; i++) { Grasshopper.Kernel.Special.GH_Panel panel = new Grasshopper.Kernel.Special.GH_Panel(); panel.CreateAttributes(); panel.SetUserText(data[i]); panel.Attributes.Bounds = bounds; panel.Attributes.Pivot = new PointF(refX, refY + i * vShift); GrasshopperDocument.AddObject(panel, false); g.AddObject(panel.InstanceGuid); } GrasshopperDocument.DeselectAll(); }
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(); }
static public void SetValueList(GH_Document doc, GH_Component comp, int InputIndex, List <KeyValuePair <string, string> > valuePairs, string name) { if (valuePairs.Count == 0) { return; } GH_DocumentIO docIO = new GH_DocumentIO(); docIO.Document = new GH_Document(); if (docIO.Document == null) { return; } doc.MergeDocument(docIO.Document); 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, chanegValuelist); void chanegValuelist(GH_Document document) { IList <IGH_Param> sources = comp.Params.Input[InputIndex].Sources; int inputs = sources.Count; // If nothing has been conected create a new component if (inputs == 0) { //instantiate new value list and clear it GH_ValueList vl = new GH_ValueList(); vl.ListItems.Clear(); vl.NickName = name; vl.Name = name; //Create values for list and populate it for (int i = 0; i < valuePairs.Count; ++i) { var item = new GH_ValueListItem(valuePairs[i].Key, valuePairs[i].Value); vl.ListItems.Add(item); } //Add value list to the document document.AddObject(vl, false, 1); //get the pivot of the "accent" param System.Drawing.PointF currPivot = comp.Params.Input[InputIndex].Attributes.Pivot; //set the pivot of the new object vl.Attributes.Pivot = new System.Drawing.PointF(currPivot.X - 210, currPivot.Y - 11); // Connect to input comp.Params.Input[InputIndex].AddSource(vl); } // If inputs exist replace the existing ones else { for (int i = 0; i < inputs; ++i) { if (sources[i].Name == "Value List" | sources[i].Name == name) { //instantiate new value list and clear it GH_ValueList vl = new GH_ValueList(); vl.ListItems.Clear(); vl.NickName = name; vl.Name = name; //Create values for list and populate it for (int j = 0; j < valuePairs.Count; ++j) { var item = new GH_ValueListItem(valuePairs[j].Key, valuePairs[j].Value); vl.ListItems.Add(item); } document.AddObject(vl, false, 1); //set the pivot of the new object vl.Attributes.Pivot = sources[i].Attributes.Pivot; var currentSource = sources[i]; comp.Params.Input[InputIndex].RemoveSource(sources[i]); currentSource.IsolateObject(); document.RemoveObject(currentSource, false); //Connect new vl comp.Params.Input[InputIndex].AddSource(vl); } else { //Do nothing if it dosent mach any of the above } } } } }