Script command returning a value

Smart people ~ Great Scripts
Post Reply
stan
Master Chief Petty Officer
Posts: 580
Joined: 21 May 2009, 17:20

Script command returning a value

Post 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));

};
You do not have the required permissions to view the files attached to this post.
stan
Master Chief Petty Officer
Posts: 580
Joined: 21 May 2009, 17:20

Re: Script command returning a value

Post 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.
stan
Master Chief Petty Officer
Posts: 580
Joined: 21 May 2009, 17:20

Re: Script command returning a value

Post 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);
};
User avatar
trueBlue
Captain
Posts: 5208
Joined: 06 Jul 2009, 22:50
Type the number ten into the box: 10

Re: Script command returning a value

Post by trueBlue »

Run the Command twice in your script?
stan
Master Chief Petty Officer
Posts: 580
Joined: 21 May 2009, 17:20

Re: Script command returning a value

Post 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.
User avatar
clintonman
Captain
Posts: 5422
Joined: 21 May 2009, 21:08
Type the number ten into the box: 0
Location: California
Contact:

Re: Script command returning a value

Post by clintonman »

Can you post more code?
Clinton Reese

http://clintons3d.com
stan
Master Chief Petty Officer
Posts: 580
Joined: 21 May 2009, 17:20

Re: Script command returning a value

Post 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.
stan
Master Chief Petty Officer
Posts: 580
Joined: 21 May 2009, 17:20

Re: Script command returning a value

Post 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:
stan
Master Chief Petty Officer
Posts: 580
Joined: 21 May 2009, 17:20

Re: Script command returning a value

Post 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;
}
Post Reply