Grasshopper

algorithmic modeling for Rhino

Hi,

I am trying to create a VB .NET button that will allow me to input an object, and recursively translate the object a number of times in the x-axis. I would think this would be easy, but I keep getting errors while writing the code with normal syntax. 

 

------------------BEGIN-------------------

Private Sub RunScript(ByVal ITER As Object, ByVal OBJ As Object, ByRef A As Object)


   Dim endobj As New list(Of Object)
   Dim k As Int32

   For k = 0 To ITER


      Dim newOBJ As New Object
      newOBJ = OBJ
      newOBJ.Transform(transform.Translation(k, 0, 0))
      endobj.add(newOBJ)

   Next


   A = endobj

------------------END-------------------

Thanks in advance

Views: 614

Replies to This Discussion

Object is a framework class, you typically don't use it unless you have absolutely no idea of what you might get. ITER should be of type Integer, OBJ should probably be of type GeometryBase.

The following code is weird:

Dim newOBJ As New Object

newOBJ = OBJ

There's no point in declaring a new instance of a class if you immediately afterwards assign it a different instance. Because you do not actually make a copy of your OBJ, you keep on transforming the same one over and over.

This is how I'd write it:

Private Sub RunScript(ByVal geometry As GeometryBase, ByVal iterations As Integer, ByRef A As Object)
  Dim result As New List(Of GeometryBase)

  For k As Int32 = 0 To iterations
    Dim duplicate As GeometryBase = geometry.Duplicate()
    duplicate.Transform(Transform.Translation(k, 0, 0))
    result.Add(duplicate)
  Next

  A = result
End Sub

--

David Rutten

david@mcneel.com

Poprad, Slovakia

David,

Thank You.

I have created code before that instantiates the new [initial] object within the code, and then when I iterate through the transformation of those objects it automatically creates the duplicate. Which is why I wrote the code that way. 

Devin

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