Page 1 of 1

Script command returning a value

Posted: 11 Oct 2012, 13:13
by stan
Something I've been trying to do that illudes me.
The only example there is that's even close is exampledataobject.cpp and Clinton's dataobjects. I want to return a value to a command not a dataobject. I assume it's done on the RiExamplesPlugin.cpp. I'm trying to pass a float. See my image

Code: Select all

STDMETHODIMP CRiExamplesPlugin::ParameterPassing(float *fFlt/*, BSTR *szStr*/)
{
	//create hello world command
	CComPtr<IRsCommand> spCmd;
	HRESULT hr = CRpExamplesPlugin::CreateCommand(DEF_GUIDNAME_PTR(IRcParameterPassing), &spCmd);
	if (FAILED(hr))
		return hr;

		  CComVariant vFlt;

	//pass input parameter using command node connector
	CComQIPtr<IRsNode> spNode = spCmd;
    spNode->GetValue(CON_PP_FLOAT_PARAM, &CComVariant(vFlt));
	 	if (vFlt.ChangeType(VT_R4) != S_OK)
		return E_INVALIDARG;
	//spNode->SetValue(CON_PP_FLOAT_PARAM, CComVariant(*fFlt));
 
 	fFlt=vFlt.fltVal ;/ 
	//execute it
	return CRpExamplesPlugin::ExecuteCommand(spCmd);
	 //return  spNode->SetValue(CON_PP_FLOAT_PARAM, CComVariant(vFlt));

};

Re: Script command returning a value

Posted: 11 Oct 2012, 21:32
by stan
well I finally got some results, I had my extern variable in the wrong place. There is still an issue as I have to click twice on my command to get the value I set, because my global variable needed to be initialized with a value, maybe I just have it in the wrong place too.

Re: Script command returning a value

Posted: 12 Oct 2012, 14:23
by stan
I'm still having issues with getting my value to show on the first click. Anyone have any ideas? :?:

Code: Select all

STDMETHODIMP CRiExamplesPlugin::ParameterPassing(float *fFlt/*, BSTR *szStr*/)
{
	*fFlt= myflt;  //extern float myflt;
  
   CComPtr<IRsCommand> spCmd;
   HRESULT hr = CRpExamplesPlugin::CreateCommand(DEF_GUIDNAME_PTR(IRcParameterPassing), &spCmd);
   if (FAILED(hr))
      return hr;

 
   //execute it
   return CRpExamplesPlugin::ExecuteCommand(spCmd);
};

Re: Script command returning a value

Posted: 12 Oct 2012, 20:59
by trueBlue
Run the Command twice in your script?

Re: Script command returning a value

Posted: 12 Oct 2012, 21:24
by stan
I thought about that, but it would be better to know how it's done. :lol:

Maybe I need a second command created and executed that passes the variable to the command before the parameterpassing command executes.

Re: Script command returning a value

Posted: 12 Oct 2012, 21:52
by clintonman
Can you post more code?

Re: Script command returning a value

Posted: 12 Oct 2012, 23:38
by stan
Clinton, the command test is just a value(myflt=5.0f) to pass from itself to RiExamplesPlugin.cpp. I have extern float myflt; at the end of both .h files.

My global float myflt; is on the parameterpassng.cpp where my value originated but not in the function where my value is:
STDMETHODIMP CRcParameterPassing::Execute()
I don't seem to be able to use the connectors in the sample to pass the value either.

So my second bit of posted code goes with this.

Re: Script command returning a value

Posted: 13 Oct 2012, 19:32
by stan

Code: Select all

STDMETHODIMP CRiExamplesPlugin::ParameterPassing(float *fFlt/*, BSTR *szStr*/)
{

	CComPtr<IRsCommand> spCmd, spCmd2;
		HRESULT hr = CRpExamplesPlugin::CreateCommand(DEF_GUIDNAME_PTR(IRcParameterPassing2), &spCmd2);
	if (FAILED(hr))
		return hr;

	CRpExamplesPlugin::ExecuteCommand(spCmd2);

			*fFlt= myflt;//

	hr = CRpExamplesPlugin::CreateCommand(DEF_GUIDNAME_PTR(IRcParameterPassing), &spCmd);
	if (FAILED(hr))
		return hr;

	//execute it
	return CRpExamplesPlugin::ExecuteCommand(spCmd);
};
This seems to work. Using a second command, first one creates the value(IRcParameterPassing2) and then it's there for the second one that uses it.
So my original IRcParameterPassing is only a dummy command, but I suppose it too could do stuff. :bananaguitar:

Re: Script command returning a value

Posted: 15 Jul 2016, 13:18
by stan
:bananatyping: I found a good way of doing this while trying to figure out how to return an IRdNumArray:

On RiExamplesPlugin.cpp

Code: Select all

STDMETHODIMP CRiExamplesPlugin::ParameterPassing(float *fFlt)
{

	HRESULT hr;
hr = CRpExamplesPlugin::CreateCommand(DEF_GUIDNAME_PTR(IRcParameterPassing), &spCmd);
	if (FAILED(hr))
       return hr;
CRpExamplesPlugin::ExecuteCommand(spCmd);
 *fFlt = myflt;
	//execute it
  return S_OK;
}
On RiExamplesPlugin.h

Code: Select all

    [id(2), helpstring("method ParameterPassing")] HRESULT ParameterPassing([out, retval]float *fFlt);

STDMETHOD(ParameterPassing)(float *fFlt);

//at end of file
extern  float myflt;

On RcParameterPassing.cpp

Code: Select all

//global under includes
float myflt;

STDMETHODIMP CRcParameterPassing::Execute(void)
{
 //this is just a random int to test code.
	  int a = rand()%10000; 
	  myflt =  (float)a;


	return S_OK;
}