Hi all
How am I gonna add the degrees option in component’s input ? (In Visual Studio , using C#)
I think just using an Angle input will give the input that option.
pManager.AddAngleParameter
That’s it , But How to tell it when the degrees option is on convert degrees to radians ?
As far as I can see those options are called StateTags and associated with the parameter from the component. I don’t know if this is the smartest way to do it, but you can for example access them (if it is the first input…) inside the SolveInstance method of your component:
for (int i = 0; i < this.Params.Input[0].StateTags.Count; i++)
{
string description = this.Params.Input[0].StateTags[i].Description;
string name = this.Params.Input[0].StateTags[i].Name;
string stateDescription = Params.Input[0].StateTags[i].StateDescription);
}
If the Degrees Tag is set/activated/clicked on, there exists a StateTag with Name “Degrees”. I guess clicking on the Degrees Tag will expire the component, so placing it inside SolveInstance should be fine. Probably there are easier / smarter solutions for that though.
The best way (which I admit is a terrible way) is to override BeforeSolveInstance()
, cast the appropriate input parameter to Param_Number
and read the UseDegrees
property. Store this value in a class level variable on your component.
Then inside SolveInstance()
get the angle, and if your cached UseDegrees bool is true, convert the value from degrees into radians.
This is all disgusting and horrible, which is why GH2 will use a separate data type for angles, which is able to represent angles in degrees, radians, turns, gradiants, slopes and spread.
Hi And Thank You David , I hope I’m doing it right
Nope. You need to access the existing parameter:
// Inside BeforeSolveInstance:
_useDegrees = false;
Param_Number angleParameter = Params.Input[2] as Param_Number;
if (angleParameter != null)
_useDegrees = angleParameter.UseDegrees;
// Class level:
private bool _useDegrees = false;
// Inside SolveInstance:
double angle = 0.0;
if (!Da.GetData(2, ref angle)) return;
if (_useDegrees)
angle = RhinoMath.ToRadians(angle);
Hi,Dear David
When I use Implements IGH_VariableParameterComponent, the degree Angle Param not work well.
when I copy and paste the component the angle param’s degree icon missed.