Bitarray and Edit Poly headache


I always have problems with bitarrays :frowning: Here’s what I have

  1. Create a Box
  2. Place on it an EditPoly modifier
  3. Select an edge

Run this…

a = ((modPanel.getCurrentObject()).GetSelection #Edge) as array

I get


now type…

(modPanel.getCurrentObject()).SetSelection #Edge (a as BitArray)

And I am now selecting nothing, instead of the Edge I started with.

Any idea what I’m doing wrong?

  • Neil


Hmm… seems odd. It works if you don’t convert the GetSelection call to an array and instead just leave it as a bitArray. Also doesn’t work when supplying SetSelection a hardcoded bitArray. Not sure why though! The bitArray from GetSelection appears to be magical.


i tested and found this problem too but i also found the solution…

apparently the bitarray that you supply must be the same size as the number of edges. So in your example the box has 12 edges. when you use GetSelection you will find that the bitarray that is returned has a count of 12 but only bit 8 is set. when cast to an array and then back to a bitarray, the new bitarray is only as long as the highest set bit ie. 8. so you need to set the count of the bitarray to the number of edges before calling SetSelection. see below:

ep = modPanel.getCurrentObject()
  -- Edit_Poly:Edit Poly
  ba = ep.GetSelection #edge
  -- #{8}
  -- 12
  a = ba as array
  -- #(8)
  b = a as bitarray
  -- #{8}
  -- 8
  b.count = ep.GetNumEdges()
  -- 12
  ep.SetSelection #edge b
  -- true


Hi Neil, I always have problems with <Edit_Poly>.setSelection. I found the <Edit_Poly>.select is a little more predictable. The only issue is you got to set selection in two steps: first deselect current selection, then set the new one. Follows the code of the function I use to set selection both in Editable Poly objects, and Edit Poly Modifiers.

function setEdgeSelection theNode theEditObj baEdges =
    if ((classOf theEditObj) == Editable_Poly) then
        polyOp.setEdgeSelection theEditObj baEdges
    else if ((classOf theEditObj) == Edit_Poly) then
        if (modPanel.getCurrentObject() != theEditObj) do
            modPanel.setCurrentObject theEditObj

        local nLevel = theEditObj.getEPolySelLevel()

        if (nLevel != #Edge) do
            theEditObj.setEPolySelLevel #Edge #Edge (theEditObj.getSelection #Edge) select:false node:theNode #Edge baEdges select:true node:theNode

        if (nLevel != #Edge) do
            theEditObj.setEPolySelLevel nLevel

@ Gravey: that is nice. I’ll run some tests too, and eventually update my functions.

  • Enrico


Thanks guys. It’s an odd workaround, but it works.

  • Neil


Officially logged as a bug. At the very least I hope for a mention of the issue in the help file.

  • Neil


If it really is a bug! probably not. Something for sure, is that Autodesk is aware of this.

Macrorecorder uses $.modifiers[#Edit_Poly].SetSelection #Edge #{} to clean the selection


$.modifiers[#Edit_Poly].Select #Edge #{5}

to actually select edges


Well as I said, if it’s not a bug, it at least should have a mention of this in the help file, which is what I asked for in my bug report. But thanks for the extra info, good to know.

  • Neil


it seems it happens that way because edit_poly is a modifier
and “SetSelection” is meant to baseobjects

then $.modifiers[1].select is additive

I think the idea is that edit_poly is relative to the baseobject itself

but definitely agree that those things should be clarified in the help file


Well, SetSelection is inside the edit poly help page, so if SetSelection is for baseobjects, then ya, they need to clarify that. :slight_smile:

  • Neil


I don’t think it is a bug but yes it should be described in the help. It makes sense if you think about it for a second. Given that it works as expected when the bitarray you supply is the same length as the number of edges, I can take an educated guess and say that the bitarray is either indented to replace the internal bitarray that defines selected edges or is looped over to explicitly set each selected edge flag. A supplied bitarray which is smaller than the number of edges seems to be handled by clearing all edge flags and returning without attempting to set any. I guess they do not wish to assume that the ‘extra’ bits are intended to be set to false.


Personally I’d like to just get rid of the bitarray all together, since they always give me trouble everytime I have to use them :slight_smile: But since that’s not gonna happen, better documentation with example code is a close second.

  • Neil


Are you not famous enough already, Neil? :slight_smile:


Haha! Read more carefully, I said “A mention of the issue”, as in, tell people about the problem in the helpfile so they will already have the answer, not “a mention of myself”. Who the hell wants to know the name of the people who came across the issue? :slight_smile:

  • Neil


This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.