Get a number

(F Leon Marquez95) #1

Hello I am trying to ask the user to type in a number in order to perform operations, but I cannot at least I ask with th AddCommandNumber method and click on the option, but if I just type the number and press enter I get nothing. Here is the code I am using.

CRhinoGetNumber gD;
	gD.SetCommandPrompt( L"Insert first measure" );
	double m_dVal = 50;
	int dval_option_index = gD.AddCommandOptionNumber(RHCMDOPTNAME(L"Dimension"), &m_dVal, L"double value", FALSE, 20, 100);
	CRhinoGet::result res = gD.GetNumber();

    if( res == CRhinoGet::nothing )
    if( res == CRhinoGet::cancel )
      return CRhinoCommand::cancel;

    if( res != CRhinoGet::option )
      return CRhinoCommand::failure;

	double new_in = gD.Number();

	ON_wString prompt("");

	prompt.Format( L"Original (m2): %lf \n", new_in);
	RhinoApp().Print( prompt );

	double adition = new_in *2 + 50;

	prompt.Format( L"Adition oRIGINAL(m2): %lf \n", adition);
	RhinoApp().Print( prompt );

	prompt.Format( L"First Gorilla (m2): %lf \n", m_dVal);
	RhinoApp().Print( prompt );

	double mult = m_dVal *2;

	prompt.Format( L"Mult (m2): %lf \n", mult);
	RhinoApp().Print( prompt );

(Dale Fugier) #2

Hi @f.leon.marquez95,

Is this more or less what you are looking for?

double dvalue = 50.0;

CRhinoGetNumber gn;
gn.SetCommandPrompt(L"First measure");
gn.AddCommandOptionNumber(RHCMDOPTNAME(L"Dimension"), &dvalue, L"Double value", FALSE, 20, 100);
for (;;)
  CRhinoGet::result res = gn.GetNumber();
  if (res == CRhinoGet::option)
  else if (res != CRhinoGet::number)
    return CRhinoCommand::cancel;

double value = gn.Number();

RhinoApp().Print(L"First measure = %g\n", value);
RhinoApp().Print(L"Double value = %g\n", dvalue);

– Dale