Grasshopper

algorithmic modeling for Rhino

Hi David,
Is there a way to automatically flatten an input for a custom component? I know we can set an input as a list but there is no guarantee that this list is flat.

For example, if a component has 20 inputs, I would like to work on the flattened list every time. If a drop in a new instance of the custom component, I have to right click and set "flatten" for each variable. This can be an issue when larger number of variables are involved and we miss one and then the component runs forever cos it's working on each input variable.

Thanks.

Kermin

Views: 1792

Replies to This Discussion

I would say the "simplest" way would be to flatten the data yourself, as this would be pretty quick and simple. See below.

'replace object with your specific type....
Dim myInputDataTree as New DataTree(of Object)
Dim myFlattenedList as New List(of Object)

DA.GetDataTree(someIndex, myInputDataTree)

myFlattenedList = myInputDataTree.AllData()
Damien,
Ok that sounds like a way. Thus when we use a "list" as an input, we will "trick" the component by using "GetDataTree"? This will ensure that the component will not run multiple times. Is this correct?
That code is really for developing compiled components, not working within a scripting component, so don't worry about the "DA.GetDataTree" line. If you're trying to do this from a scripting component, then set the item's access to Tree. Once your in your script, use the AllData method on your tree input and assign that to a list that you've created.
Damien,
I seem to be getting an error just trying to bring the data tree in. This is for a complied component.

Any ideas?
Thanks.
Kermin


pManager.Register_LineParam("WireFrame1", "WireFrame1", "WireFrame1 to import (Prop Num 210)", GH_ParamAccess.tree)
Dim TempDataTree As New DataTree(Of Line)
DA.GetDataTree(1, TempDataTree)



Error 1 Overload resolution failed because no accessible 'GetDataTree' can be called with these arguments:
'Public Function GetDataTree(Of T As Grasshopper.Kernel.Types.IGH_Goo)(name As String, ByRef tree As Grasshopper.Kernel.Data.GH_Structure(Of T)) As Boolean': Data type(s) of the type parameter(s) cannot be inferred from these arguments. Specifying the data type(s) explicitly might correct this error.
I'm having the exact same problem. I have no trouble bringing in items or lists to my custom components, but the DA.GetDataTree line always throws this error for me.

Anyone know what's going on?

-Jon
If you're developing 'real' components, forget DataTree. DataTree is only there to make life easier for VB and C# scripters. Compiled components need to use the class GH_Structure(Of T As IGH_Goo) in the Grasshopper.Kernel.Data namespace.

So when you declare an input parameter to have GH_ParamAccess.tree, you need to use the following inside SolveInstance:

Dim data As GH_Structure(Of GH_Line) = Nothing
If (Not DA.GetDataTree(0, data)) Then Return


Depending on the type of input parameter, you need to use different types for T.

--
David Rutten
david@mcneel.com
Poprad, Slovakia
perfect. thank you!

I found this tread very useful, thank you. For anyone interested in flattening input data in C#, I found that the following works:

<code> GH_Structure<GH_String> in_IDtree = new GH_Structure<GH_String>();
            if(! DA.GetDataTree<GH_String>(0,out in_IDtree)) return;
            List<GH_String> inIDList = new List<GH_String>(in_IDtree.FlattenData());</code>

 

I might add one thing here, could be useful for someone.

If you want to "enforce" flattening refer above, but if you want to leave flattening at the discretion of the user, but set the default to be flattened when the component is added to the canvas, add a line of code like below to the register input method:

pManager[0].DataMapping = GH_DataMapping.flatten;

Cheers,

Jon

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

© 2020   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service