Grasshopper

algorithmic modeling for Rhino

Alright... I know the path mapper is probably the most complex component in grasshopper but bear with me. 

 

I have a GH_Path that needs to be what it is. It's a part of a loop within a loop so the path is ( i, j ). Sometimes (for counting and .toarray and stuff) I need the path to just be ( i ) and sometimes I need it to just be ( j ). The code is really long and has a lot going on so I don't think posting it will help. but the path mapper part (I've been told) goes something like this:

 

 

        Dim lxr1 As New GH_lexer("{A;B}")

        Dim lxr2 As New GH_Lexer("{A}")

        Dim lxr3 As New GH_Lexer("{B}")

        Dim pathmap As New GH_LexerCombo(lxr1, lxr2)

        Dim IDK As New datatree(Of brep))

        GH_Lexer.PerformLexicalReplace(lxr1, lxr2, bT, IDK)

 

I get a WAY TOO LONG error that is as follows:

 

Error: Type parameter 'T' for 'Public Shared Sub PerformLexicalReplace(Of T As Grasshopper.Kernel.Types.IGH_Goo)(source As Grasshopper.Kernel.Data.GH_Lexer, target As Grasshopper.Kernel.Data.GH_Lexer, structure_in As Grasshopper.Kernel.Data.IGH_Structure, structure_out As Grasshopper.Kernel.Data.GH_Structure(Of T))' cannot be inferred. (line 215)

Error: Type argument inference failed for type parameter 'T' of 'Public Shared Sub PerformLexicalReplace(Of T As Grasshopper.Kernel.Types.IGH_Goo)(source As Grasshopper.Kernel.Data.GH_Lexer, target As Grasshopper.Kernel.Data.GH_Lexer, structure_in As Grasshopper.Kernel.Data.IGH_Structure, structure_out As Grasshopper.Kernel.Data.GH_Structure(Of T))'. Type argument could not be inferred from the argument passed to parameter 'structure_out'. (line 215)

 

ANY help would be greatly appreciated.

 

Views: 1237

Replies to This Discussion

Hi Andy,

 

DataTree is only for use within VB and C# script components, Grasshopper itself uses IGH_DataStructure and GH_DataStructure(Of T As IGH_Goo) (both located in the Grasshopper.Kernel.Data namespace).

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

How do I define that in order to plug into the last slot of the lexical replace?

 

Is it:

 

Dim IDK As New GH_DataStructure(Of Brep As IGH_Goo) ?

No, the (Of T As XXXX) puts restrictions on what T can be. Since Brep does not implement IGH_Goo, it cannot be used inside a GH_Structure.

 

You'll need to use a type that implements this interface. You should probably use GH_Brep.

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Does this mean that I cannot use a DataTree(of brep) in the third slot either? How would I convert that into something usable?

 

This GH_XXXX stuff is quite new to me...

 

 Note: bT is a DataTree(of Brep)


        Dim lxr1 As New GH_lexer("{A;B}")

        Dim lxr2 As New GH_Lexer("{A}")

        Dim lxr3 As New GH_Lexer("{B}")

        Dim IDK As New GH_Structure(Of GH_Brep)

        GH_Lexer.PerformLexicalReplace(lxr1, lxr2, bT, IDK)

 

This returns the error:

Unable to cast object of type 'Grasshopper.DataTree`1[Rhino.Geometry.Brep]' to type 'Grasshopper.Kernel.Data.IGH_Structure''. (line: 215)

 

That's true, you cannot use DataTree at all. You'll need to take your DataTree(Of Brep) and turn it into a GH_Structure(Of GH_Brep).

 

I assume you just want to be able to use a PathMapper like operation inside a VB component? This is probably quite a common problem, I'll have a look at the Lexer code, see if I can make it work on DataTrees as well (it's been a while since I've worked on this stuff).

 

I've attached a file that shows how to convert from a DataTree(Of Point3d) to a GH_Structure(Of GH_Point) and vice versa, it's pretty nasty code.

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Attachments:

I added an overload to PerformLexicalReplace that takes two DataTree(Of T)

 

Will be available in the next release, then the code will look like this:

Private Sub RunScript(ByVal pts As DataTree(Of Point3d), ByRef A As Object)   

  Dim pts_out As New DataTree(Of Point3d)
  Dim source As New GH_Lexer("{A;B}(i)")
  Dim target As New GH_Lexer("{i}(B)")

  GH_Lexer.PerformLexicalReplace(source, target, pts, pts_out)
  A = pts_out
End Sub

 

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Excellent. I got the code working using your function. 

 

Even more excellent that I can use data trees in the near future. Thanks a million.

Hi David,

I know I've touched on this topic before, but I have a few scripted components, most of which deal with DataTrees of various types of data (planes, points, integers). Is it still the case that when developing GHA's dataTree cannot be used? If so, is the conversion method above the best way to go about getting from dataTree to GH_Structure? Or is there a cleaner way to rewrite the code containing the dataTrees? Like just replacing all instances of dataTree(of type) with GH_Structure(of type which implements IGH_Goo)? If so, can I just declare all inputs which should be datatree access as GH_Structures?

If the conversion is in fact necessary, if I want to input a dataTree of some type and also output a dataTree of the same type, do I need to convert from dataTree to GH_Structure and then back again for the output?

I hope this question makes sense. 

Thanks for all the help,

-Brian Harms

Hey David,
I've been working on converting several clusters I've made into a legit plugin (which is what you've been helping me with ever so kindly). Ive been slowly but surely assimilating a few hundred components into fewer and fewer custom scripted components, and when I'm done i plan to make the jump to GHA files. Considering your comment above about datatrees, I was wondering if there are other noteable differences to be aware of when making this switch.
Thanks
-Brian

Hi Brian,

DataTrees and IGH_Structures have been completely parallel types. This was probably a mistake, but DataTrees came later and I basically just copied the source for GH_Structure and tore out all advanced methods. Ideally GH_Structure should derive from DataTree and only add the IGH_Goo specific stuff, but I didn't see that way back then. I'm trying to decide whether to make this (probably breaking) change in 0.9 or not. So far I've come down on the 'probably not' side.

GH_Structure is the more mature and powerful type, but it only operates on IGH_Goo derived types, whereas DataTree will swallow anything. Beyond this fundamental difference, they are quite alike.

--

David Rutten

david@mcneel.com

Poprad, Slovakia

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service