C# Exporting to an OBJ using Rhino Script

Hello,

Im iterating through geometries, creating GUIDs for them, baking them into Rhino. Then using a Rhino Script to select the objects by the GUIDs and export them to an Obj.

What i want to do is give them (the geometries) a name (attribute name) so that when they are objs they have some information to them.

I’ve created name attributes but when assigned the baking process creates 49 instances, 7 objects and bakes and names them 7 times over to make 49 objects.

I dont know how to integrate the Names into the script, attached is the gh file and the code in the body any assistance would be appreciated.

I dont know where this part goes to make it all work:
Rhino.DocObjects.ObjectAttributes att = new Rhino.DocObjects.ObjectAttributes();
att.Name = objName;*

C# Code
private void RunScript(DataTree geometries, string objName, string directory, string filename, bool export, ref object A)
{

if(export)
{
  var guids = new List<Guid>();

  for(int i = 0; i < geometries.BranchCount; i++)
  {
    for(int n = 0; n < geometries.Branches[i].Count; n++)
    {

      Rhino.DocObjects.ObjectAttributes att = new Rhino.DocObjects.ObjectAttributes();
      att.Name = objName;

      var geom = geometries.Branches[i][n];
      var guid = Rhino.RhinoDoc.ActiveDoc.Objects.Add(geom, att);
      guids.Add(guid);
    }
  }


  Rhino.RhinoDoc.ActiveDoc.Objects.Select(guids);

  string filepath = Path.Combine(directory, filename);
  string cmd = "_-Export " + "\"" + filepath + "\"" + " _Enter _Enter _D";

  Rhino.RhinoApp.RunScript(cmd, false);
  //Rhino.RhinoDoc.ActiveDoc.Objects.Delete(guids, true);
}

Thank you
ExporterTest.gh (8.5 KB)