Wpf window- working with event handlers to select curves

I am new to WPF. I have created a Rhino command to perform certain actions after selecting a few curves. I have created a xaml file and added buttons and created an event handler for the button. What I am trying to achieve is to use the button to automatically select all the curves from a particular layer. How do I proceed from here to be able to select all the curves from a layer?

 private void Button_Click(object sender, RoutedEventArgs e)
        {

        }

Hey @sujal,

I’d need more code to give you a proper solution, but maybe this will help enough for now, the below code will get you all the curves on a given layer that are selected (remove the boolean if I misunderstood that). I assume somewhere in your UI the user chooses a layer name, and that can be fed into the below code to get you what you need.

RhinoDoc doc = RhinoDoc.ActiveDoc;

Layer lay = doc.Layers.FindName(layerName);
var filter = new ObjectEnumeratorSettings()
{
	LayerIndexFilter = lay.Index,
	ObjectTypeFilter = ObjectType.Curve,
	SelectedObjectsFilter = true
}

RhinoObject[] objects = doc.Objects.FindByFilter(filter);

– cs

Maybe a simpler example would help here.

I have created a function called BakeRoad. It is saving the curve to a layer

        public void BakeRoad(RhinoDoc doc,Curve c,Rhino.DocObjects.ObjectAttributes o)
        {
            doc.Objects.AddCurve(c, o);
        }

But I have an error when I call this inside the button event handler. I’m not sure the correct format in which I can input the parameters for the method inside the event handler.

Hey @sujal, ahh, it would seem in your screenshot at the bottom you’re not passing in a curve and object attributes you’re passing in the types (you need to pass instances). You’ll need to pass in the curve and attributes you are actually trying to save. Are they currently selected? More code would certainly help, are you able to post the project you’re working on?

– cs

1 Like
 public void BakeRoad(RhinoDoc doc,Curve c,Rhino.DocObjects.ObjectAttributes o)
        {
            doc.Objects.AddCurve(c, o);
        }

protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            var dialog = new Window1();

            dialog.Show();

            var layer_name = "Default";
var rhino_object = doc.Objects.FindByLayer(layer_name);

 List<ObjRef> objrefList = new List<ObjRef>();

             for (int i = 0; i < rhino_object.Length; i++)
              {
                  ObjRef o = new ObjRef(rhino_object[i]);            
                objrefList.Add(o);
              }

//CREATE PARENT LAYER
            String myLayerP = "Plans";
            var linetype_indexP = doc.Linetypes.Find("Continuous");
            var layerP = new Layer
            {
                Name = myLayerP,              
                LinetypeIndex = linetype_indexP
            };

            // Add the layer to the document
            var layerIndexP = doc.Layers.Add(layerP);

            Rhino.RhinoDoc thisDocP = Rhino.RhinoDoc.ActiveDoc;
            Rhino.DocObjects.ObjectAttributes myAttP = new Rhino.DocObjects.ObjectAttributes();
            myAttP.LayerIndex = layerIndexP;

var objrefs=new ObjRef[objrefList.Count];
            objrefList.ToArray().CopyTo(objrefs, 0);

  List<Curve> inCurves = new List<Curve>();
for (int i = 0; i < objrefs.Length; i++)
            {
                var roadWidth = Double.Parse(objrefs[i].Object().Attributes.GetUserString("RoadWidth"));

                var roadType = objrefs[i].Object().Attributes.GetUserString("RoadType");
    Curve curve = objrefs[i].Curve();

  if (curve != null)
{
if(roadType=="MainRoad") 
{
       inCurves.Add(curve);
}       
}     
            }

 foreach (var fillet_curve in InCurves)
                {

//Adding the function here  instead of doc.Objects.AddCurve(fillet_curve,myAttP);
  BakeRoad(fillet_curve,myAttP);
                //    doc.Objects.AddCurve(fillet_curve,myAttP);
                }

I have added a part of code for your understanding. I hope it is clear enough to understand where I am using the function. I would be calling the BakeRoad function to add the curves to the document.