Get diffrent return value when use c++ and python api to execute same command

Get diffrent return value when use c++ and python api to execute same command

Anonymous
Not applicable
1,806 Views
7 Replies
Message 1 of 8

Get diffrent return value when use c++ and python api to execute same command

Anonymous
Not applicable

    I'm tring to use both c++ and python api to execute maxscript command -- maxversion().According to maxscript help document,the return should be an Array with three integers.In python script,i get #(21000, 52, 0),that's actually what i need.But when it comes to c++ api,i get a int table,which has a lot of items.This is obviously not correct.So i think there is something wrong in my code.

    My python code:

import MaxPlus
localMaxVerValue = MaxPlus.FPValue()
MaxPlus.Core.EvalMAXScript('maxversion()', localMaxVerValue)
localMaxVer = localMaxVerValue.Get().GetItem(0)

    My c++ code:

FPValue retValue = FPValue();
int version;
if (!ExecuteMAXScriptScript(LPCWSTR("maxversion()"), FALSE, &retValue)) {
    return ret;
}
if (retValue.type != TYPE_VALUE) {
    return ret;
}
else {
    Tab<INT_PTR>* result = retValue.i64_tab;
    int number = result->Count();
    INT_PTR* versionPtr = result->Addr(0);
    version = *versionPtr;       
}

    localMaxVer is correct,the value is 21000.version is incorrect,the value is 526772528.number is incorrect too,it's too huge,the value is 525918705,i think it should be 3.

    Can somebody help me find where is wrong,thank you!

0 Likes
Accepted solutions (1)
1,807 Views
7 Replies
Replies (7)
Message 2 of 8

istan
Advisor
Advisor

I usually check the type of the return value and the type of each array value (which could be different of course), before I cast.. Have no clue, what MaxVersion should return. You could also test your own C++ code, by simply calling this in MXS: "#(1,2,3)". The you'll see, which types go back to C++.

0 Likes
Message 3 of 8

Anonymous
Not applicable

Thanks for your reply istan.

I tried to find the return type in python by MaxPlus.FPTypeGetName(),the return type is IntTab.So in my c++ code,as you see,i transformed retValue into int64 tab.After your reply,i checked the return type in C++,it's TYPE_VALUE.Maybe it should be int64 tab(or other int tab) before transform.

Thank you again!

0 Likes
Message 4 of 8

denisT.MaxDoctor
Advisor
Advisor
Accepted solution

@Anonymous wrote:

Thanks for your reply istan.

I tried to find the return type in python by MaxPlus.FPTypeGetName(),the return type is IntTab.So in my c++ code,as you see,i transformed retValue into int64 tab.After your reply,i checked the return type in C++,it's TYPE_VALUE.Maybe it should be int64 tab(or other int tab) before transform.

Thank you again!


c++ gives you FPValue of type TYPE_INT_TAB. So you have to check it's i_tab property. It's Tab<int>* with count of 3.

No difference with Python or MaxScript

 

0 Likes
Message 5 of 8

Anonymous
Not applicable

Thank you for your reply.

I tried to turn the FPValue to a Tab<int>*,using i_tab.But it still has lots of items,more than three,and the value is obviously not release version.Could you show me how to receive a return FPValue(include check it's type)?Maybe some of my operation is wrong.

Thank you again!

0 Likes
Message 6 of 8

Anonymous
Not applicable

I find a mistake when i turn my std::string to const wchar_t* type.Now i get a TYPE_INT_TAB return with count of 3.

Thank you! 

0 Likes
Message 7 of 8

denisT.MaxDoctor
Advisor
Advisor


@Anonymous wrote:

Could you show me how to receive a return FPValue(include check it's type)?




 

 

		MSTR str = L"maxversion()";
		FPValue val;
		if (ExecuteMAXScriptScript(str, quiet, &val))
		{
			if (val.type == TYPE_INT_TAB)
			{
				for (int k=0; k < val.i_tab->Count(); k++)
				{
					mprintf(L"%i\n", (*val.i_tab)[k]);
				}
			}
		}
0 Likes
Message 8 of 8

Anonymous
Not applicable

Thanks!

I can get correct return value now!

0 Likes