Import parcial file obj

Hello,

I have a question (maybe dummy).

I create one file 3.dm with some objetcs inside and save it like “test.3dm”, so I know all
guid id inside the teste.3dm.

The dummy question:is it possible to import only one specific guid and not all?

Like:

        string guid = "C934BBDD-BD73-48A6-A35A-7C5F8B0EDE82";

        var allObj = Get all objetcs inside teste.3dm;

        foreach (var item in allObj)
        {
            if (item==guid)
            {
                Import item;

            }

This is possible?

Hi Ricardo

This could be done with
https://developer.rhino3d.com/api/RhinoCommon/html/N_Rhino_FileIO.htm

Does that help?
-Willem

Thank you,

Can you give me some pratical example?

Thanks

Hi @MatrixRatrix,

This should work:

protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
  var guid = new Guid("49e96c23-6ab7-4ad2-a299-37099665d241");

  var dialog = new OpenFileDialog
  {
    Filter = @"Rhino 3D Models (*.3dm)|*.3dm",
    DefaultExt = "3dm"
  };
  var rc = dialog.ShowDialog();
  if (rc != DialogResult.OK)
    return Result.Cancel;

  var filename = dialog.FileName;
  if (string.IsNullOrEmpty(filename) || !File.Exists(filename))
    return Result.Failure;

  try
  {
    var f = File3dm.Read(filename);
    foreach (var obj in f.Objects)
    {
      if (obj.Attributes.ObjectId == guid)
      {
        doc.Objects.Add(obj.Geometry, obj.Attributes);
        doc.Views.Redraw();
        break;
      }
    }
  }
  catch
  {
    RhinoApp.WriteLine("Error reading {0}.", filename);
  }

  return Result.Success;
}

– Dale

Hello @dale,

Yes this work.

If I want add the intire group?

One more thing, I make a small example with only two geometry, seams that
this mode is a bit slow, there is some more fast way?

Thank you