Is there any "unpublished" method to cast and get a python object in the MAX C++ SDK?

Is there any "unpublished" method to cast and get a python object in the MAX C++ SDK?

denisT.MaxDoctor
Advisor Advisor
740 Views
6 Replies
Message 1 of 7

Is there any "unpublished" method to cast and get a python object in the MAX C++ SDK?

denisT.MaxDoctor
Advisor
Advisor

I want Qt objects to be passed as PyWrapperBase to the SDK...is there something that can be done?

def_visible_primitive(isPyWrapper, "isPyWrapper");
Value* isPyWrapper_cf(Value** arg_list, int count)
{
	check_arg_count_with_keys(isPyWrapper, 1, count);
	auto val = arg_list[0];
	if is_pywrapperbase(val)
	{
		// ... some cast is expected here ...  ;
		return &true_value;
	}
	return &false_value;
}

 

0 Likes
Accepted solutions (1)
741 Views
6 Replies
Replies (6)
Message 2 of 7

denisT.MaxDoctor
Advisor
Advisor

for QWidgets, you can pass winId() and then find the widget, but I'm interested in a more universal solution

0 Likes
Message 3 of 7

eric.brosseau
Autodesk
Autodesk

@denisT.MaxDoctor

The answer to the question in the title is no, there is no hidden method to suit your request as of today. We currently only interface with Python using the MAXScript/pymxs interface. From C++, you would have to extend the MAXScript exposure with the methods you need to interface with. For Qt objects, it is preferable to use the Qt/PySide2 Python module and not use the pymxs interface.

 

Is there anything blocking you from achieving your goal?

 

Eric Brosseau

Eric Brosseau
Senior Software Developer, 3ds Max, Autodesk
0 Likes
Message 4 of 7

denisT.MaxDoctor
Advisor
Advisor

@eric.brosseau wrote:

@denisT.MaxDoctor

The answer to the question in the title is no, there is no hidden method to suit your request as of today. We currently only interface with Python using the MAXScript/pymxs interface. From C++, you would have to extend the MAXScript exposure with the methods you need to interface with.


As you might guess, it's for developing MaxScript extensions that I would like to be able to pass Py-Wrapped MXS values to the MAX SDK.
I think that this mechanism is simple and transparent if you know how it works, and I don't understand why this should be made a "secret".

 

Here is a simple task... 

I have:

qwds = python.import "PySide2.QtWidgets"
wd = qwds.QWidget()

now I want to pass "wd" to some visible SDK primitive function to get a wrapped QWidget in C++. How? (not using the winId)

0 Likes
Message 5 of 7

458569
Participant
Participant

I just want to confirm what Eric said. A python object can only become visible to max through pymxs. Pymxs wraps a python object as a maxscript object. From the moment it is wrapped, its properties and methods become usable as maxscript properties and methods. This is the only thing that exists right now.

0 Likes
Message 6 of 7

denisT.MaxDoctor
Advisor
Advisor

@458569 wrote:

I just want to confirm what Eric said. A python object can only become visible to max through pymxs. Pymxs wraps a python object as a maxscript object. From the moment it is wrapped, its properties and methods become usable as maxscript properties and methods. This is the only thing that exists right now.


But I still want an answer to a simple question: How can I pass a pointer to a QObject wrapped as a Python object to the MAX SDK?

 

If 'pymax' can do it, why can't I do the same? ... just answer what exactly does PyWrapperBase point to or how to get a pointer to a python object?

0 Likes
Message 7 of 7

denisT.MaxDoctor
Advisor
Advisor
Accepted solution

@458569 wrote:

I just want to confirm what Eric said. A python object can only become visible to max through pymxs. Pymxs wraps a python object as a maxscript object. From the moment it is wrapped, its properties and methods become usable as maxscript properties and methods. This is the only thing that exists right now.


using shiboken2 and its getCppPointer method, we can get the address of the c++ instance pointer wrapped by the given object... after that, everything is clear.

0 Likes