Extrusion Can not Set UserDictory Data ;

Hi,
I’m have some problerm about set UserDictory data on Extrusion Object.
I want to Set an key to all of the Object when the object once add into the Rhino Document.
But I find that . Only the Extrusion could not to be set UserDictory. My C# is As Fellow:

(The Code is to set UserDictory to the object when object add to the RhinoDocument)

     private void RhinoDoc_AddRhinoObject(object sender, Rhino.DocObjects.RhinoObjectEventArgs e)
        {
            try
            {
                GeometryBase Geom = e.TheObject.Geometry;
                if (Geom is Surface)
                {
                    Geom = (Geom as Surface).ToBrep();
                }
                Geom.UserDictionary.Set("Label", "");
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

(To View the UserDictory has setting to the Geometry)

          GeometryBase Geom = default(GeometryBase);

            if (!DA.GetData(0, ref Geom)) return;
                    
            List<string> TempOutPutString = Geom.UserDictionary.Keys.ToList();
            DA.SetDataList(0, TempOutPutString);

Thanks

The above make a new object - one that isn’t in the document.

– Dale

Thanks Dale, But When I Remove the Code

Geom = (Geom as Surface).ToBrep();

I could not view the UserDictory has setting to the Geometry.

Hi @1056960357,

This is quick and dirty, but I think it works.

TestCughudson.cs (2.0 KB)

– Dale

Thanks, @Dale I Knew where the problerm is?But I don’t know why.

The Problerm is in the Code:

  GeometryBase Geom = default(GeometryBase);
  if (!DA.GetData(0, ref Geom)) return;        
  List<string> TempOutPutString = Geom.UserDictionary.Keys.ToList();
  DA.SetDataList(0, TempOutPutString);

Whe I debug the code , Extrusion will be automate convert to an Brep, and all the UserDictionary
will be Wipe Out:scream: , And I don’t know Why?


ExtrusionObject will AutoMate Convert to Brep In Grasshopper and After the UserDictory attached to the Extrusion
Was Wipe out

Hi @1056960357,

I don’t know what AutoMate is, sorry. However, what you describe about extrusions being converted to Breps in Grasshopper is true.

Feel free to post sample code that isn’t working for you and I’ll try my best to help.

– Dale

Sorry, Thankyou for your attention @dale
The code is attached below;
1、Get KeysComponent.cs file is an Grasshopper component to get all the key of an geometry
2、GrasshopperPluginInfo.cs file is used to add an keys when the geometry was created and add into Rhino WorkPlace.
GetKeysComponent.cs (2.4 KB)
GrasshopperPluginInfo.cs (3.0 KB)