Units
i find solution
byte[] imageArray = System.IO.File.ReadAllBytes(@"image file path");
string base64ImageRepresentation = Convert.ToBase64String(imageArray);
When you convert it copy the result to your code to avoid using image file
Really really cool. Can I also add the same button to my canvas? if possible can you share the code? currently, I am learning c# and find this UI modification thing really cool so I wanted to learn this and want to add one extra button that zoom selected geometry button beside the solver.
I don’t Know if there is zoom selected geometry in Grasshopper SDK.
Maybe we need first find selected geometries and use their ids to zoom selected in Rhino.
If i find a way i will add it as a button, and sorry i can’t share c# code, python code is enough you can use it.
sure sure no problem
but where can I find python code ??
maybe ill try to write that code in C#.
Python code, you already used it
hi @anon39580149 and @Jay_vayeda
I managed to write python code but my try in c# code not successfully
Maybee @Mahdiyar can help for translation this code from python to ,C# Code
Python succeed +c# unsuccessfully code:
icon-- bar.zip (26.9 KB)
private void RunScript(bool addBtns, bool removeBtns, List<string> icons)
{
var toolbar = (System.Windows.Forms.ToolStrip) (Grasshopper.Instances.DocumentEditor.Controls[0].Controls[1]);
if (addBtns)
{
var button = new ToolStripButton("Enable/Disable", Bitmap.FromFile(icons[0]), (sender, e) => Instances.ActiveCanvas.Document.ToggleEnabledFlags(), "Enable/Disable");
button.Name = "Enable/Disable";
button.CheckOnClick = false;
button.Checked = true;
button.DisplayStyle = ToolStripItemDisplayStyle.Image;
toolbar.Items.Add(button);
}
if (removeBtns)
{
var buttons = new List<ToolStripItem>();
foreach(ToolStripItem item in toolbar.Items)
if (item.Name == "Enable/Disable")
buttons.Add(item);
foreach(var btn in buttons)
toolbar.Items.Remove(btn);
}
}
AddBtns.gh (3.3 KB)
After researching your famous solution on the loading process, I found the GH_AssemblyPriority class:
And indeed, it is really simpler.
nice @Mahdiyar, could you please help me to implement the Delete button? thank you!
private void RunScript(bool addBtns, bool removeBtns, List<string> icons)
{
var toolbar = (System.Windows.Forms.ToolStrip) (Grasshopper.Instances.DocumentEditor.Controls[0].Controls[1]);
if (addBtns)
{
var button = new ToolStripButton("Delete", Bitmap.FromFile(icons[0]), onClick, "Delete");
button.Name = "Delete";
button.DisplayStyle = ToolStripItemDisplayStyle.Image;
toolbar.Items.Add(button);
}
if (removeBtns)
{
var buttons = new List<ToolStripItem>();
foreach(ToolStripItem item in toolbar.Items)
if (item.Name == "Delete")
buttons.Add(item);
foreach(var btn in buttons)
toolbar.Items.Remove(btn);
}
}
// <Custom additional code>
private void onClick(object sender, EventArgs e)
{
GrasshopperDocument.UndoUtil.RecordRemoveObjectEvent("Delete", GrasshopperDocument.SelectedObjects());
GrasshopperDocument.RemoveSelection(true);
}
// </Custom additional code>
AddBtns.gh (2.8 KB)
if (addBtns) { var button = new ToolStripButton("InvertSelect", Bitmap.FromFile(icons[1]), (sender, e) => Instances.ActiveCanvas.Document.InvertSelection(),"InvertSelect"); // this is your code but I changed on function, because I am exproling sometings. button.Name = "InvertSelect"; button.CheckOnClick = false; button.Checked = true; button.DisplayStyle = ToolStripItemDisplayStyle.Image; toolbar.Items.Add(button); } if (removeBtns) { var buttons = new List<ToolStripItem>(); foreach (ToolStripItem item in toolbar.Items) if (item.Name == "InvertSelect") buttons.Add(item); foreach (var btn in buttons) toolbar.Items.Remove(btn); }
hello sir, @Mahdiyar really cool code really liked it
I just modify it with a
GH_Document.InvertSelection Method
but i am having a problem adding
GH_Document.Enabled Property
and
GH_Document.EnableSolutions Property
these two properly in the code.
actually, I am new to learning C# so I am not able to add this.
Because of this code I learn how to assign methods in code but did not have an idea of how to add and modify properties.
if possible can you guide me with this ??
Thank you
- Jay
hi @Mahdiyar and if help for only which Api for Group and UnGroup Component to add bottom?
Very Very thank you for the Plugin.
but I am very curious about how to assign Property in C# code in that existing code. if possible can you tell me ?.
Check this post
Hi, for auto loading button see this post.
Ondřej