Как передать значение из одного класса в другой C# Grasshopper
Я пытаюсь передать значение bool bake из одного класса (класса атрибута) в экземпляр решения (класс buttonTest). Я уже пробовал несколько вещей, как метод Get и написать свойство без успеха.
namespace buttonTest
{
public class buttonTestComponent : GH_Component
{
public override void CreateAttributes()
{
m_attributes = new Attributes_Custom(this);
}
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()
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);
}
}
}
Я новичок, поэтому я надеюсь, что это можно понять.
Спасибо всем
если я пытаюсь использовать m_attributes.Bake, я получаю следующее сообщение об ошибке: сообщение об ошибке
1 ответ
Если я правильно понял вопрос, вам нужно что-то вроде следующего.
Класс buttonTestComponent:
public class buttonTestComponent : GH_Component
{
private Attributes_Custom m_attributes;
public override void CreateAttributes()
{
m_attributes = new Attributes_Custom(this);
}
protected override void SolveInstance(IGH_DataAccess DA)
{
Circle circle = new Circle(2.00);
//use m_attributes.Bake here
}
}
И вы оставляете класс Attributes_Custom как есть.