pymxs and references parameter with pyhton and UV Editor

pymxs and references parameter with pyhton and UV Editor

Anonymous
Not applicable
2,049 Views
2 Replies
Message 1 of 3

pymxs and references parameter with pyhton and UV Editor

Anonymous
Not applicable

Hello, I'm with UV 😭 . So I want to get information about my UVs. I'm using the "Unwrap UVW" modifier and the UV Editor. I want to use this function :

 

<void><Unwrap_UVW>.getArea <bitArray>faceSelection <&float>x <&float>y <&float>width <&float>height <&float>areaUVW <&float>areaGeom
x is Out parameter
y is Out parameter
width is Out parameter
height is Out parameter
areaUVW is Out parameter
areaGeom is Out parameter

 


You can find everything about it here :  https://help.autodesk.com/view/3DSMAX/2020/ENU/?guid=GUID-496CE46A-EBD3-40C2-9637-3F21E0F0B0FB 
As I understand it, it got 7 parameters and 6 are used to get the information.
Unfortunately, when I use it, my 6 out parameters are not updated (and the function return a boolean instead of nothing but the value is True so it's cool I guess ¯\_(ツ)_/¯).
My code (in python) look like this :

 

selectedPoly = mUnwrap.unwrap.getSelectedPolygons()
print selectedPoly
x = 1
y = 2
w = 3
h = 4
area = 5
areaGeom = 6
print mUnwrap.unwrap4.getArea(selectedPoly, pymxs.mxsreference(x), pymxs.mxsreference(y), pymxs.mxsreference(w), pymxs.mxsreference(h), pymxs.mxsreference(area), pymxs.mxsreference(areaGeom))
print (str(x)+" , "+str(y)+" , "+str(w)+" , "+str(h)+" , "+str(area)+ " , "+str(areaGeom))

 


Sorry, it's badly written code but I'm just trying stuffs... It's no time for good code 😅
Anybody has an idea why my references are not updating ? If you want more informations I'll be glad to answer you 😄
PS : Yes I have selected Polygons in my variable `selectedPoly` and no exception or error are thrown

PS2: It's not the first time I use references with pymxs and everything went well before so I just don't understand

 

Thanks

Accepted solutions (2)
2,050 Views
2 Replies
Replies (2)
Message 2 of 3

eric.brosseau
Autodesk
Autodesk
Accepted solution

Thank you @Anonymous for the question.

 

I will first acknowledge that there is a limitation with the 2020.3 offering in relation to the 'pymxs.mxsreference' feature provided to enable the use of referenced arguments passed to MAXScript functions. Your question made me revisit the reference page on the subject that is currently online for the 3ds Max 2020.3 version. We noticed the wording might indicate all argument types are supported. However, the feature was built to support Python lists that are passed as output parameters. Also, as it is noted, for variables other than Python lists, the variable must be visible in the 'pymxs.runtime' context. We will be revisiting the documentation to correct the misleading note.

 

As an information to you, this problem of not supporting all passed types is resolved in the just-released 3ds Max 2021. We now provide the functionality thru the use of a 'pymxs.byref' object. See related documentation here: http://help.autodesk.com/view/MAXDEV/2021/ENU/?guid=__developer_using_pymxs_pymxs_differences_pymxs_by_ref_parameters_html.

 

For the problem you are trying to solve, you will need to use a call to 'pymxs.runtime.execute' to run a MAXScript code snippet inside a Python script. We cannot use the 'pymxs.mxsreference' because, for the 'getArea' function, the output parameters are all floats and those are not kept in the 'pymxs.runtime' context since they are automatically translate to Python floats. You could make a call like this one:

pymxs.runtime.execute("uv_polygons = $.modifiers[1].getSelectedPolygons()\n$.modifiers[1].getArea uv_polygons &ret_x &ret_y &ret_w &ret_h &ret_area &ret_areaGeom")

First, it fills a MAXScript variable 'uv_polygons' with the selected polygons, like you were doing with 'selectedPoly'. Then it calls 'getArea' with the arguments passed as references (the presence of the ampersand in important). There is no need initialize the output arguments in this specific case. They will be created and filled by the MAXScript function call. You will be able to access the content of those output parameters in your Python script just by using, for example, 'pymxs.runtime.ret_x'. The code might not work as-is in your content but the intention is to provide you with a functional proposition.

 

We understand that this is not totally practical.

 

I sincerely hope this helps you. Do not hesitate to post your questions on the forum.

Eric Brosseau
Senior Software Developer, 3ds Max, Autodesk
Message 3 of 3

Anonymous
Not applicable
Accepted solution

Thank you Eric for your complete and clear answer.

The new byref system seems to be pretty cool.

 

I try your code and it works perfectly.

Thanks you very much for that, you save me a lot of time.