using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using Grasshopper;
using Grasshopper.Kernel;
using Grasshopper.Kernel.Types;
using Grasshopper.Kernel.Data;
using Rhino.Geometry;
namespace YourNameSpace
{
///
///
///
public class MyFirstZUIComponent : GH_Component, IGH_VariableParameterComponent
{
private string m_dataTest = "";
public string DataTest
{
get { return m_dataTest; }
set
{
m_dataTest = value;
Message = m_dataTest;
}
}
///
/// Initializes a new instance of the ProgramAgent_GH class.
///
public ProgramAgent_GH()
: base("Name", "NickName",
"Description",
"Category", "SubCategory")
{
DataTest = "";
}
///
/// Registers all the input parameters for this component.
///
protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)
{
pManager.AddNumberParameter("A", "A", "", GH_ParamAccess.item);
pManager.AddNumberParameter("B", "B", "", GH_ParamAccess.item);
}
///
/// Registers all the output parameters for this component.
///
protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager)
{
pManager.AddNumberParameter("Result", "Result", "", GH_ParamAccess.item);
}
///
/// This is the method that actually does the work.
///
/// The DA object is used to retrieve from inputs and store in outputs.
protected override void SolveInstance(IGH_DataAccess DA)
{
double result = 0;
double data = 0;
// Here you loop throw all your inputs and collect data.
for (int i = 0; i < Params.Input.Count; i++)
{
// Do stuff
// Here is na example were I just add all the inputs
if (DA.GetData(i, ref data))
{
result += data;
}
}
DA.SetData(0, result);
}
#region VARIABLE COMPONENT INTERFACE IMPLEMENTATION
public bool CanInsertParameter(GH_ParameterSide side, int index)
{
// Only insert parameters on input side. This can be changed if you like/need
// side== GH_ParameterSide.Output
if (side == GH_ParameterSide.Input)
{
return true;
}
else
{
return false;
}
}
public bool CanRemoveParameter(GH_ParameterSide side, int index)
{
// Only allowed to remove parameters if there are more than 2
// from the input side
if (side == GH_ParameterSide.Input && Params.Input.Count > 2)
{
return true;
}
else
{
return false;
}
}
public IGH_Param CreateParameter(GH_ParameterSide side, int index)
{
// Has to return a parameter object!
Param_GenericObject param = new Param_GenericObject();
int count = 0;
for (int i = 0; i < Params.Input.Count; i++)
{
count += i;
}
param.Name = "Data"+count.ToString();
param.NickName = param.Name;
param.Description = "A Data input";
param.Optional = true;
return param;
}
public bool DestroyParameter(GH_ParameterSide side, int index)
{
//This function will be called when a parameter is about to be removed.
//You do not need to do anything, but this would be a good time to remove
//any event handlers that might be attached to the parameter in question.
return true;
}
public void VariableParameterMaintenance()
{
//This method will be called when a closely related set of variable parameter operations completes.
//This would be a good time to ensure all Nicknames and parameter properties are correct. This method will also be
//called upon IO operations such as Open, Paste, Undo and Redo.
//throw new NotImplementedException();
}
#endregion
///
/// Provides an Icon for the component.
///
protected override System.Drawing.Bitmap Icon
{
get
{
//You can add image files to your project resources and access them like this:
// return Resources.IconForThisComponent;
return null;
}
}
///
/// Gets the unique ID for this component. Do not change this ID after release.
///
public override Guid ComponentGuid
{
get { return new Guid("5396a78d-7852-4335-bd3b-bf119ace0121"); }
}
}
}