Grasshopper

algorithmic modeling for Rhino

I am trying to transform and rotate a series of OnCurves in order to create an Array. My outputted list returns one valid curve but then a list of invalid curves. I thought this may have to do with the OnNurbsCurve.transform function. In the Rhino SDK it says that this function returns a boolean. "Public Function Transform(ByRef xform As IOnXform) As bool" How do I get this method to return a new transformed OnNurbsCurve? Or is the error have something to do with the protected Ionxform class? I have attached the Function which is causing the problem. The full script is also attached below. FYI The objective is to mirror the helix segment and arc and then array the 4 curves in order to create the framework for parametric spiral staircase. . . .

Function move_rotate(ByVal dblZ_amount As Double, ByVal dblRotationAngle As Double, ByVal_ ObjectToMove As OnNurbsCurve, ByVal pntCenter As On3dpoint)As  OnNurbsCurve
  
 'declares function specific variables
   
Dim ObjectToMoveCopy As New OnNurbsCurve()
  
 'duplicates the inputted object
   
ObjectToMoveCopy = ObjectToMove.duplicate
   
'prepares the Xform objects to rotate the object dblRotationAngle degrees and moves it
'dblZ_amount amount in the z direction
   
Dim move_xform As New OnXform
    move_xform.Translation(0, 0, dblZ_amount)
    Dim vertZ_axis As New On3dVector(0, 0, 1)
    Dim rotate_xform As New OnXform
    rotate_xform.Rotation(dblRotationAngle, vertZ_axis, pntCENTER)
  
 'performs the transformations on the object
  
 ObjectToMove.Transform(move_xform)
    ObjectToMove.Transform(rotate_xform)
  
 'returns the new objects

    ObjectToMovecopy = objectToMove
    Return ObjectToMoveCopy

  End Function



Full Script:

Private Sub RunScript(ByVal InputObjectToMove1 As List(Of OnCurve), ByVal InputObjectToMove2 As OnCurve, ByVal z_amount As Double, ByVal pntCENTER As Object, ByVal dblReps As Integer, ByRef OutputList1 As Object, ByRef OutputList2 As Object)

    'decalres the variables
    Dim i As Integer
    Dim ObjectToMoveCopy As New OnNurbsCurve
  
 'converts the OnCurve list from Grasshopper to OnNurbs Object
 
  Dim objectToMove1 As New OnNurbsCurve()
    InputObjectToMove1(0).getnurbform(objectToMove1)
  
 'converts the OnArc list from Grasshopper to OnArc Object
  
 Dim objectToMove2 As New OnNurbsCurve()
    InputObjectToMove2.getnurbform(objectToMove2)

    'creates two lists and adds the original objects to that list

    Dim list1 As New list(Of OnNurbsCurve)
    Dim list2 As New list(Of OnNurbsCurve)
    list1.add(objectToMove1)
    list2.add(objecttomove2)

    'Rotate and move the first two object 1x z_amount
    'dblRotationAngle = 3.141593 is 180 degrees in radians

    Call move_rotate(z_amount, 3.141593, list1(0), pntCenter)
    list1.add(ObjectToMoveCopy)
    Call move_rotate(z_amount, 3.141593, list2(0), pntCenter)
    list2.add(ObjectToMoveCopy)

    'array the rotated object dblReps amount of times
    For i = 1 To dblReps
      Call move_rotate(z_amount * 2, 0, list1(i), pntCenter)
      list1.add(ObjectToMoveCopy)
    Next
    For i = 1 To dblReps
      Call move_rotate(z_amount * 2, 0, list2(i), pntCenter)
      list2.add(ObjectToMoveCopy)
    Next

    'array the original object dblReps amount of times
'inset move-rotate function for non rotated objects
    'set the lists to the grasshopper output variables

    OutputList1 = list1
    OutputList2 = list2



Views: 974

Replies to This Discussion

Sorry, after posting this I realized the function seems to be working, rather I think I am doing something wrong in trying to add to the list, maybe in this section:

'array the rotated object dblReps amount of times
For i = 1 To dblReps
Call move_rotate(z_amount * 2, 0, list1(i), pntCenter)
list1.add(ObjectToMoveCopy)
Next
For i = 1 To dblReps
Call move_rotate(z_amount * 2, 0, list2(i), pntCenter)
list2.add(ObjectToMoveCopy)
Next
Hi ben,

I don't know if you already solved the problem but i took a quick stab at the code. Here's an alternative way to just structure the code, hope it can help

Dim list1 As New list(Of OnCurve)
Dim list2 As New list(Of OnCurve)

For Each crv As oncurve In inputObjectToMove1
move_rotate(z_amount, 3.141593, crv, pntCenter)
list1.add(crv)
Next

For Each crv As oncurve In inputObjectToMove2
move_rotate(z_amount, 3.141593, crv, pntCenter)
list2.add(crv)
Next

Dim outList1 As New List(Of OnCurve)
Dim outList2 As New List(Of OnCurve)

For Each crv As oncurve In list1
For i As Integer = 0 To dbReps
move_rotate(z_amount, 3.141593, crv, pntCenter)
outList1.Add(crv)
Next
Next

For Each crv As oncurve In list2
For i As Integer = 0 To dbReps
move_rotate(z_amount, 3.141593, crv, pntCenter)
outList2.Add(crv)
Next
Next

OutputList1 = outlist1
OutputList2 = outlist2



I also changed your function into a sub (which is ok because you are passing the curves in byVal) and just used oncurve instead of onnurbscurve:

Sub move_rotate(ByVal dblZ_amount As Double, ByVal dblRotationAngle As Double, ByVal _
ObjectToMove As OnCurve, ByVal pntCenter As On3dpoint)'As OnNurbsCurve


Dim move_xform As New OnXform
move_xform.Translation(0, 0, dblZ_amount)
Dim vertZ_axis As New On3dVector(0, 0, 1)
Dim rotate_xform As New OnXform
rotate_xform.Rotation(dblRotationAngle, vertZ_axis, pntCENTER)
ObjectToMove.Transform(move_xform)
ObjectToMove.Transform(rotate_xform)

End Sub
Thanks Jason for your help! I was actually able to do the exact same thing with a couple of grasshopper components. I'm still learning what I can do with Grasshopper and when I need to go to VbScript. I will have a look at this code though, because I need to learn what I was doing wrong so I can whip out little vbscripts in the future. . . Once I get the hang of it it shouldn't be too hard, but right now it takes me a day to do the simplest thing.

I will get in contact with you soon and send you those ghx files to look at, hopefully before you leave.


BEst,

Ben

RSS

About

Translate

Search

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service