MAX Plus strange method

Does anyone know how to call a method with this signature?

CombineMaterials(Mtl mat1, Mtl mat2, int & mat2Offset)

How to pass the BitWise operator?

Python bitwise operators are like so:

sorry I made same test and found this page as well, I’m not really comfortable with this in python.
Can you write a 2 line example on how to call this method?

CombineMaterials(Mtl mat1, Mtl mat2, int & mat2Offset)

If that is a C++ signature, than that isn’t asking for the bitwise operator, instead its asking for a reference to the mat2Offset integer variable.

should be easy…I agree…I tested everything
i’m in a loop:
x = 0
MaxPlus.Mtl.CombineMaterials(multiMats[i], multiMats[i+1], x )
and i get this pretty clear error

“TypeError: in method ‘Mtl_CombineMaterials’, argument 3 of type ‘int &’”

Is this from python? because you can’t actually pass a reference to an int in python.
Maya gets around this with the MScriptUtil class that effectively lets you make a pointer stand-in and pass those. I do not know if Max has a similar feature though.

1 Like

I tried passing 0 directly but it doesn’t work.
I’ll write on the Autodesk forum to see if they have a solution
thanks any way

Hi @elpie89,

Looking at the api:

CombineMaterials(Mtl mat1, Mtl mat2, int & mat2Offset) -> Mtl

I think this is the long int pointer to the item (mat2Offset) in memory:

Edit: Didnt see @bob.w - MScriptUtil callout - this exactly is my thinking too. :+1:

Yeah, given that MaxPlus doesn’t appear to have a corollary to MScriptUtil, I’m thinking its just something they need to fix during the binding generation process. Really that should be tweaked so that it is the return value.

You can use the standard library ctypes.byref() for passing things by reference. Depending on the expected length of the integer (or if you want to actually use the resulting value or not) you may need to explicitly create a ctypes.c_int32(), as numbers in python are always long (64 bit) and thus the results might not be correct when passing an already used number variable.

import ctypes
offset = ctypes.c_int32()
MaxPlus.Mtl.CombineMaterials(multiMats[i], multiMats[i+1], ctypes.byref(offset))

Didn’t test it though :wink:

Interesting. I’m curious how well mixing ctypes and SWIG extensions works.