Hi everyone,
I am trying to access a bool created in my Attributes_Costum Class in my Geometry generating class in order to bake.
I tried so far to make a get property, since I thought that may be the problem:
public bool Bake
{
get { return bake; }
}
I also tried making the bool public, but without success, it never appears to be possible to use that bool in the other class.
Here the complete code:
using System;
using System.Collections.Generic;
using Grasshopper.Kernel;
using Rhino.Geometry;
using GH_IO;
using GH_IO.Serialization;
using Grasshopper;
using Grasshopper.Kernel.Data;
using Grasshopper.Kernel.Types;
using Grasshopper.GUI;
using Grasshopper.GUI.Canvas;
using System.Windows.Forms;
using Grasshopper.Kernel.Attributes;
using System.Drawing;
namespace buttonTest
{
public class buttonTestComponent : GH_Component
{
public buttonTestComponent()
: base("buttonTest", "Nickname",
"Description",
"Category", "Subcategory")
{
}
public override void CreateAttributes()
{
m_attributes = new Attributes_Custom(this);
}
protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)
{
pManager.AddBooleanParameter("test", "t", "test", GH_ParamAccess.item);
}
protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager)
{
pManager.AddBooleanParameter("test", "t", "test", GH_ParamAccess.item);
}
protected override void SolveInstance(IGH_DataAccess DA)
{
Circle circle = new Circle(2.00);
//here I want to bake
}
public class Attributes_Custom : GH_ComponentAttributes
{
public Attributes_Custom(GH_Component owner) : base(owner) { }
protected override void Layout()
{
base.Layout();
Rectangle rec0 = GH_Convert.ToRectangle(Bounds);
rec0.Height += 22;
Rectangle rec1 = rec0;
rec1.Y = rec1.Bottom - 22;
rec1.Height = 22;
rec1.Inflate(-2, -2);
Bounds = rec0;
ButtonBounds = rec1;
}
private Rectangle ButtonBounds { get; set; }
protected override void Render(GH_Canvas canvas, Graphics graphics, GH_CanvasChannel channel)
{
base.Render(canvas, graphics, channel);
if (channel == GH_CanvasChannel.Objects)
{
GH_Capsule button = GH_Capsule.CreateTextCapsule(ButtonBounds, ButtonBounds, GH_Palette.Black, "Bake", 2, 0);
button.Render(graphics, Selected, Owner.Locked, false);
button.Dispose();
}
}
bool bake;
public bool Bake
{
get { return bake; }
}
public override GH_ObjectResponse RespondToMouseDown(GH_Canvas sender, GH_CanvasMouseEvent e)
{
if (e.Button == MouseButtons.Left)
{
RectangleF rec = ButtonBounds;
if (rec.Contains(e.CanvasLocation))
{
bool bake = true;
MessageBox.Show("Hello World", "Hello World", MessageBoxButtons.OK);
return GH_ObjectResponse.Handled;
}
}
return base.RespondToMouseDown(sender, e);
}
}
protected override System.Drawing.Bitmap Icon
{
get
{
return null;
}
}
public override Guid ComponentGuid
{
get { return new Guid("20b81d57-ef4f-4ecf-973e-9c7caa9d24a8"); }
}
}
}
and the cs file:buttonTestComponent.cs (5.1 KB)
If someone may explain me I would be really grateful.
Baris