Check if File3dmObject read from file is a picture frame in C#

Hello. I want to batch process a number of 3dm files, and as i load them I want to know if the object type is a picture frame.

for example, if i want to extract all the surfaces from a file using this:

 List<GeometryBase> result = new List<GeometryBase>();

        try
        {
            File3dm rhinoFile = File3dm.Read(FilePath);

            if (rhinoFile == null)
            {
                Print("Failed to open the Rhino file.");
                return;
            }

            foreach (var obj in rhinoFile.Objects)
            {
                GeometryBase geometry = obj.Geometry;
                
                if (geometry is Surface)result.Add(geometry);
                else if (geometry is Brep) {
                    var brep = (Brep)geometry;
                    var bfaces = brep.Faces;
                    foreach (var srf in bfaces) if (srf is Surface) result.Add(srf);

                }
            }      

        }
        catch (Exception ex) {Print ("Could not return objects");}

it also adds all the picture frames, which is not desireable. IsPictureFrame() can only be called on DocObjects.RhinoObject, and I failed to find a workaround or an alternative.

Hi @adel.albloushi,

A Picture object in Rhino is just a planar surface with a Picture material.

In Rhino, you can detect picture objects using RhinoObject.IsPictureFrame.

Outside of Rhino, you can search for Rhino objects who render material is of the PictureMaterialType type.

Another approach is to check the attributes of the File3dmObject and see if it has Picture user data.

private static readonly Guid PictureFrameId = new Guid("3F460FF7-9289-4fc0-BF66-7D7B7DC658BF");

public static bool IsPictureFrame(File3dmObject obj)
{
  var rc = false;
  if (null != obj)
    rc = obj.Attributes.UserData.Contains(PictureFrameId );
  return rc;
}

Hope this helps.

– Dale

1 Like

Thanks Dale!
The C# snipped was exactly what i needed.

btw, where can I find these guids?

private static readonly Guid PictureFrameId = new Guid("3F460FF7-9289-4fc0-BF66-7D7B7DC658BF");