Get Object Volume, Block Instances causing me issues. C# Rhinocommon

It doesnt account for the transformations and how many times an object is present in the moidel. It just checks the blocks and finds it exist 1block. Then that block can be repaeted 10times inthe model and scaled differently, however this will always add to the table the object as is in the definition (bigger and once only)

Can you help me fix this? Ideally I’d like to have the CSV in output to just contain every object that is actually present as a 3d object in the model and compute the volume.

This blockinstances added complications. Can you fix my code please so that I get as output the correct CSV with ALL the objects including the blocks that are present (not their definition, the actual block object present in the model)

I cant seem to work my head around it

@dale

Thank you very much to whoever can help me !!

(as you ca see in this attached file, my code returns only 1object with 206 volume, reality is 8objects with different scale than the definition so their volume is even lower!!!)
oscarbugtesting.3dm (409.7 KB)

Hi @ReyMysterio,

To the the volume of a block instance, you’ll need a function similar to this:

public VolumeMassProperties GetInstanceReferenceVolume(
  File3dm file3dm, 
  InstanceReferenceGeometry iref
  )
{
  VolumeMassProperties totalMP = null;
  if (null != file3dm && null != iref)
  {
    var idef = file3dm.AllInstanceDefinitions.FindId(iref.ParentIdefId);
    if (null == idef)
    {
      foreach (var id in idef.GetObjectIds())
      {
        var obj3dm = file3dm.Objects.FindId(id);
        if (null != obj3dm)
        {
          var brep = obj3dm.Geometry as Brep;
          if (null != brep && brep.IsSolid)
          {
            // Copy and transform
            var newBrep = brep.DuplicateBrep();
            newBrep.Transform(iref.Xform);

            var mp = VolumeMassProperties.Compute(newBrep, true, false, false, false);
            if (null != mp)
            {
              if (null == totalMP)
                totalMP = mp;
              else
                totalMP.Sum(mp);
            }
          }
        }
      }
    }
  }
  return totalMP;
}

Note, the above is only a sample, as it does not take tested instances into account. Also, the sample above only look for solid Breps and does not handle solid meshes or lightweight extrusions. But this should be a good starting point.

– Dale

1 Like

Thank you very much Dale, works like a charm
WIsh I could pay you guys back somehow :hearts: