Grasshopper

algorithmic modeling for Rhino

Hi All,

 

I have finally taken the big step towards creating a GHA of components and fallen flat on my face, as my shoes seem to be tied together.

 

I created a VB.Script component for what I'm trying to do and that worked fine. Now I've dropped this code into VS and altered the various ins and outs and I get an error when I plug a List into my component.

 

Code from VS:

Protected Overrides Sub RegisterInputParams(ByVal pManager As Grasshopper.Kernel.GH_Component.GH_InputParamManager)       

        pManager.Register_GenericParam("List", "L", "List to find Middle")

End Sub


Protected Overrides Sub RegisterOutputParams(ByVal pManager As Grasshopper.Kernel.GH_Component.GH_OutputParamManager)       

        pManager.Register_GenericParam("Mid", "M", "Value(s) in the Middle")      

        pManager.Register_IntegerParam("Index", "I", "Index of Value(s) in List")

End Sub


Protected Overrides Sub SolveInstance(ByVal DA As Grasshopper.Kernel.IGH_DataAccess)

        Dim L As New List(Of Object)

 

        If (Not DA.GetData(0, L)) Then Return

        If (L.Count = 0) Then Return

 

        Dim Out_M As New List(Of Object)

        Dim Out_I As New List(Of Object)

 

        Out_M.Add(L(Math.Floor(L.Count / 2)))

        Out_I.Add(CInt(Math.Floor(L.Count / 2)))

 

        If L(Math.Floor(L.Count / 2)) <> L(Math.Ceiling(L.Count / 2)) Then

            Out_M.Add(L(Math.Ceiling(L.Count / 2)))

            Out_I.Add(CInt(Math.Ceiling(L.Count / 2))) 

        End If


        DA.SetData(0, Out_M)

        DA.SetData(1, Out_I)

    End Sub

 

Where am I going wrong?

Views: 1700

Replies to This Discussion

Excellent. I have modified it slightly now that I can see the outcome in GH (I think you made the same wood for the trees mistake as me).

 

For odd Length lists:

 

Else

out_v.Add(list(i - 1))
out_i.Add(i - 1)

out_v.Add(val)
out_i.Add(i)

End If 

 

eg List Length = 11, Mid = 4 and 5 (not 5 and 6).

 

Next time we meet I'll buy you a beer. Although I've been thinking about all the virtual beers I've been bought on here and was thinking about setting a link to a paypal account so I can start cashing in on them :))

Dunno why I can't reply to your virtual beers comment, but this is why I was so persistant in replying to your queries...its time the bartender got served ;)

RSS

About

Translate

Search

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service