Grasshopper

algorithmic modeling for Rhino

How to get the component that links with the current component in Grasshopper?

Hello,

I get one question. I have two components here, and now I want use some Input parameters of component 1(BUI Modifier) inside component 2(Connector). Is that possible? I think, as those two components are connected, there is maybe a brigde between them.

best regards

Yi

Views: 2051

Replies to This Discussion

GH_Document.ExpandSelection Method might be what you are looking for.

Attachments:

thanks, i'll give it a try

I'm still trying to get the current GH_Document Object inside the SolveInstance method :(

I hope the GH_DocumentObject.OnPingDocument Method is the right one

Sorry I cannot help more I only knew about the growselection because it is available in the UI 

thank you all the same

Connections are made between parameters. A parameter maintains a list of sources it gets data from and each parameter also has a list of recipients to which it disseminates data.

Both of those properties are publicly accessible so you should be able to figure out which objects are 'upstream' from a specific component.

--

David Rutten

david@mcneel.com

Hi David,

first of all, thank you for your relay. But your description is a little abstract for me at this moment.

Specifically speaking, I want use the EW and PW parameter of the "BUI Modifier " component(the left one) inside the "Connector" component. You mean I should first find the GUID of the B17 parameter and look for the "BUI Modifier" Component in the whole Document? Or there is a way to backtrace it directly? 

Right now I can only get the InstanceGuid of each Input Parameter of the "Connector" component using the method you mentioned with "sources". It is still not clear for me, how to get it work. 

I'd appreciate it if you cound explain it more explicitly. 

Thank you!

Here is an example that does what David mentioned:

https://github.com/mostaphaRoudsari/ladybug/blob/master/src/Ladybug...

Thank you for sharing this, I'll look your code. I'm using C# by the way. Hope there is no difficult to read it.

now I can get the Component connected to it.

GH_Document ghDocument = this.OnPingDocument();

foreach (IGH_Param param in this.Params.Input)
{
foreach (IGH_Param source in param.Sources)
{
//MessageBox.Show(source.Attributes.GetTopLevel.DocObject.Name);
if (source.Attributes.GetTopLevel.DocObject.Name == "BUI/B17 File Modifier")
{
Guid guid = source.Attributes.GetTopLevel.DocObject.InstanceGuid;
IGH_Component ghComponent = ghDocument.FindComponent(guid);
}
}
}

next step will be how to get the input parameters

Now I can get the position of each input parameter of the Midifier Component, but still can not find the right method to get the value, which is marked with "// get input value from Modifier Component" in following code, any idea?

foreach (IGH_Param param in this.Params.Input)
{
  foreach (IGH_Param source in param.Sources)
  {
  //MessageBox.Show(source.Attributes.GetTopLevel.DocObject.Name);
  if (source.Attributes.GetTopLevel.DocObject.Name == "BUI/B17 File Modifier")
    {
    Guid guid = source.Attributes.GetTopLevel.DocObject.InstanceGuid;
    IGH_Component ghComponent = ghDocument.FindComponent(guid);
    foreach (IGH_Param input in ghComponent.Params.Input)
    {
      switch (input.Name)
        {
        case "EW Type":
          EW_Type = input.Name;
          EW_ID = // get input value from Modifier Component
          break;

        case "PW Type":
          PW_Type = input.Name;

          PW_ID =    // get input value from Modifier Component
          break;

        case "IF Type":
          IF_Type = input.Name;
          IF_ID =    // get input value from Modifier Component
          break;

        case "WIN Type":
          WIN_Type = input.Name;
          WIN_ID =    // get input value from Modifier Component
          break;

        }
      }
    }
  }
}

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service