Grasshopper

algorithmic modeling for Rhino

c#: Missing constructor in GH_ComponentAttributes derived class?

Hi Guys,

After several unsuccessful attempts based on this great thread, I still have not managed to place the right constructor in the class derived from the GH_ComponentAttributes. What should I use there, for what reason and how could I have guessed this information using the GH SDK?

public class SettingsComponentAttributes : GH_ComponentAttributes
    {
//Which constructor?
        public override GH_ObjectResponse    RespondToMouseDoubleClick(GH_Canvas sender, GH_CanvasMouseEvent e)
        {
            ((SettingsComponent)Owner).ShowSettingsGui();
            return GH_ObjectResponse.Handled;
        }  
    }

Visual Studio Express suggests the following constructor with a TO DO but I am not sure what member initialization means in that context:

   private SettingsComponent settingsComponent;
        public SettingsComponentAttributes(SettingsComponent settingsComponent)
        {
            // TODO: Complete member initialization
            this.settingsComponent = settingsComponent;
        }

Many many thanks,

Arthur

Views: 457

Replies to This Discussion

GH_ComponentAttributes only has a single constructor, so you really don't have any choice in the matter. Your constructor must call this one and only base class constructor. Since the base class constructor looks like this:

public GH_ComponentAttributes(IGH_Component component){...}

you have to get an IGH_Component from somewhere too. Easiest would be to simply duplicate the constructor signature:

public class SettingsComponentAttributes : GH_ComponentAttributes

{

  public SettingsComponentAttributes(IGH_Component component) : base(component) {...}

}

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Thank you very much David, it is working now :)

       

public class SettingsComponentAttributes : GH_ComponentAttributes
            {   
                  public SettingsComponentAttributes(IGH_Component SettingsComponent) : base(SettingsComponent) {}
            
             public override GH_ObjectResponse RespondToMouseDoubleClick(GH_Canvas sender, GH_CanvasMouseEvent e)
           
               {
                   ((SettingsComponent)Owner).ShowSettingsGui();
                    return GH_ObjectResponse.Handled;
               }  
            } 

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service