pymxs equivalent of Maxscript "bitarray as array"

pymxs equivalent of Maxscript "bitarray as array"

Anonymous
Not applicable
3,730 Views
3 Replies
Message 1 of 4

pymxs equivalent of Maxscript "bitarray as array"

Anonymous
Not applicable

Is there a python equivalent of converting a bitarray to a List / Tuple?

In Maxscript:

 

-- BitArray to Array
selectedFaces = getFaceSelection $

faceIndices = selectedFaces as array

 

-- Array to BitArray

newBitArray = faceIndices as bitarray

 

 

I can get the list of face indices I need, it's quick and most importantly fast, especially on a dense mesh.
In Python however, I cannot find any equivalent function or help on the "as" keyword, nor a conversion function from pymxs.runtime.BitArray to pymxs.runtime.Array / List / Tuple

Currently I'm using a work around, with involves going through all of the vertices and retrieving it using a list comprehension.

 

In Python:


from pymxs import runtime as rt

 

# BitArray to Array 

selectedFaces = rt.getFaceSelection(rt.selection[0])
faceIndices = [(index+1) for index in range(len(selectedFaces.count)) if selectedFaces[index] == True]

 

# Array to BitArray

newBitArray = rt.BitArray()

newBitArray.count = selectedFaces.count
for index in faceIndices: newBitArray[index] = True

 

I have been looking for an answer for a while now, to no avail. There is no documentation on pymxs, and maxscript documentation just tells me to use the "as" keyword. rt.show(rt.BitArray) just returns be the wrapper functions, and help(rt.BitArray) gives me nothing as well.

 

As you can imagine, everytime i need to convert an array to a bitarray or an array to a bitarray, i'm going through all of the indices, and with dense meshes, this slows down a lot.

Help is very much appreciated, if anyone could provide an alternative method to convert these data types, or know of the python wrapping function. This would help my optimization pass on my tool. Thank you.

0 Likes
Accepted solutions (1)
3,731 Views
3 Replies
Replies (3)
Message 2 of 4

drew_avis
Autodesk
Autodesk
Accepted solution

Hi there, I can't find any way to replicate the "as" coercion syntax in pymxs directly, but you can define a MAXScript method that does it, and use that.  For example:

 

>>> MaxPlus.Core.EvalMAXScript("fn b2a b = (return b as Array)")
<MaxPlus.FPValue; proxy of <Swig Object of type 'Autodesk::Max::FPValue *' at 0x0000023952D46F90> >
>>> rt.b2a
<MAXScriptFunction<b2a()>>
>>> rt.b2a(selectedFaces)
<Array<#(10, 55, 56, 57, 60, 61, 62, 63, 64, 69, 70, 71, 74, 75, 76, 77, 78, 79, 80, 81, ...)>>
>>> 

Hope that helps,

Drew



Drew Avis
Content Experience Designer
Message 3 of 4

Anonymous
Not applicable

Ah... awesome, i thought we could only use EvalMAXScript to only evaluate Maxscript lines. Never thought that we could use it to declare functions as well, and use it from pymxs.runtime.

Thanks!

0 Likes
Message 4 of 4

ManniiCode
Contributor
Contributor

If someone comes across this thread with Max 2022 or later, you'll find that the solution above doesn't work anymore. MaxPlus is no longer available. This is the new solution.

from pymxs import runtime as rt
#Define a function by executing maxscript
rt.execute("fn b2a the_birray = (return the_birray as Array)")
#Call the function b2a with rt.b2a
rt.b2a(selectedFaces)