Convert IBitArray to IArray

 
 
 
Posted by:mmorais
Data created:25 June 2013

Hi

i'm start  using  MAX.NET using C#  to  get  more speed in my scripts.

I need to  get the  coordinates of selected vertex from a Mesh. I get  selected  vertex  in a IBitArray like in  MAXscript. But Need to  convert  to IArray or a array of ints to get  the vertexID.

How i convert Ibitarary to Iarray or array of int?

 

 IInterface ip = this.global.COREInterface;
 IINode selNode = ip.GetSelNode( 0 ); //get first
 IObjectState os = selNode.EvalWorldState(0,false);
 IObject selobj = os.Obj;
 ITriObject tobj = selobj as ITriObject;
 IMesh mesh = tobj.Mesh;
 IBitArray selverts =  mesh.VertSel;  //get selected vertex

// Not work -->  IArray a_selvert = (IArray)selverts; //How to convert to IArray ???
 // selverts.NumberSet  get's the number of selected  in INumberSetProxy  How to get a int??
  if (  !selverts.IsEmpty )
{
   int vertID =  ??? ?   // How to loop  through the selected vertices ??  (foreach don't work)
   IPoint3 point = mesh.GetVert(vertID);

{

 

Thanks

I think your best bet is to create a list of ints and then to iterate over selverts and add the index to the int list whenever selverts at that index is set to true.

Marsel Khadiyev (Software Developer, EPHERE Inc.)

I do a function to create a List of ints

private List<int> GetArraySelverts(IBitArray SelBitarray, int numVert)
        {
            List<int> intarray = new List<int>();
           
            for (int i = 0; i < numVert; i++)
               {
                   int vitval = SelBitarray[i];
                   if ( vitval > 0 ) intarray.Add(i);
               }
            return intarray;
        }