Grasshopper

algorithmic modeling for Rhino

Hi, im pretty new to scripting in general, but have been trying to learn from looking at example scripts.
I came across this line of script within a function:
 Dim pt0 As On3dPoint = crv2.Item(1)
where crv2 is an OnPolyline
I would like to assign a point based on the end point of a line and thought that this would be a good method, however, whenever I try to incorporate it into a script of my own, it makes the script stop working.  I was wondering if there are any additional imports or other steps that I might be missing?

Here is the relevant section of code:

 Private Sub RunScript(ByVal pt As On3dPoint, ByVal j As Object, ByVal crv As Object, ByRef A As Object, ByRef B As Object, ByRef C As Object) 

    Dim pattern As New List(Of OnLine)
    Dim pt2 As On3dPoint
    Dim ln As OnLine
    
    pt2 = New On3dPoint(pt)
    pt2.x = (pt2.x + 5)
    ln = New OnLine(pt, pt2)
    pattern.Add(ln)


    Dim pt3 As On3dPoint
    Dim pt4 As On3dPoint
    Dim ln2 As OnLine

    ln2 = New OnLine(ln)
    pt3 = ln.Item(0) 'target point
    pt4 = ln2.Item(1) 'selection pt
    ln2.Translate(pt4 - pt3)
    ln2.Rotate(j, New On3dVector(0, 0, 1), pt3)
    pattern.Add(ln2)
it works except for these two lines
   pt3 = ln.Item(0) 'target point
    pt4 = ln2.Item(1) 'selection pt
I also tried:
 pt3 = New OnLine(ln.Item(0)) 'target point
Thanks!

Views: 274

Replies to This Discussion

Hi nreamy,

this code is still using the old SDK. Are you using Grasshopper 0.7 or 0.8? If yes, then I can show you how to use the new SDK. If no, you'll probably switch eventually, so why not start today :)

--
David Rutten
david@mcneel.com
Seattle, WA
I am using grasshopper 0.7, but yes, if you could show me how to access the newer version that would be great! I have been having trouble accessing the SDK help file also maybe its because i'm trying to access an older version?
Hi nreamy,

a Polyline has an indefinite number of corner points. A Line only has two points. You cannot access a line in the same way as you'd access a polyline, using an indexer.

I believe what you are trying to do can be accomplished as follows:

Private Sub RunScript(ByVal pt As Point3d, ByVal y As Double, ByRef A As Object)
   Dim pattern As New List(Of Line)

   Dim pt2 As Point3d = pt
   pt2.X += 5

   Dim ln As New Line(pt, pt2)
   pattern.Add(ln)

   Dim pt3 As Point3d = ln.From
   Dim pt4 As Point3d = ln.To
   Dim ln2 As Line = ln

   ln2.Transform(Transform.Translation(ln.Direction))
   ln2.Transform(transform.Rotation(y, Vector3d.ZAxis, pt3))

   pattern.Add(ln2)

   A = pattern
End Sub


If you do want to access a line using indexers, you can of course create a polyline from your line segments:

Dim pline As New Polyline(New Point3d(){ln.From, ln.To})

or

Dim pline As New Polyline()
pline.Add(ln.From)
pline.Add(ln.To)


--
David Rutten
david@mcneel.com
Seattle, WA
Thanks David, that worked well.
Here is the script that I wrote so far. I was wondering if there is a way to reference the vertices of a Brep similar to the command line.from. right now I am making points based on the end points of a reference line and then rotating the points as I rotate the objects. As a result I think the script is getting a little unnecessarily long.

Private Sub RunScript(ByVal obj As OnBrep, ByVal ln1_5 As OnLine, ByVal ln6_10 As OnLine, ByVal ln2_3 As OnLine, ByVal ln3_4 As OnLine, ByVal ln7_9 As OnLine, ByVal ln7_8 As OnLine, ByVal axis1 As On3dVector, ByVal axis5 As Object, ByVal axis2 As On3dVector, ByVal axis3 As Object, ByVal axis4 As Object, ByVal j As Object, ByVal k As Object, ByVal N As Object, ByRef A As Object, ByRef B As Object, ByRef C As Object)
Dim pt1 As On3dPoint
Dim pt6 As On3dPoint
Dim pt5 As On3dPoint
Dim pt10 As On3dPoint

Dim pattern As New List(Of OnBrep)
Dim pattern1 As New List(Of OnBrep)
Dim obj2 As OnBrep
Dim obj3 As OnBrep

Dim axxis1 As On3dVector
Dim ref2axis As On3dVector
Dim refaxis2 As On3dVector

Dim refpt6 As On3dPoint
Dim refpt10 As On3dPoint
Dim refpt5 As On3dPoint
Dim refpt1 As On3dPoint


'Dim points As New List(Of On3dPoints)


pt1 = New On3dPoint(ln1_5.from)
pt6 = New On3dPoint(ln6_10.from)
pt5 = New On3dPoint(ln1_5.To)
pt10 = New On3dPoint(ln6_10.To)


pattern.Add(obj)
For i As Integer = 1 To N
axxis1 = New On3dVector(pt5 - pt1)
obj2 = New OnBrep(obj)

'rotate object
obj2.Rotate(j, axxis1, pt1)

'rotate points
refpt6 = New On3dPoint(pt6)
refpt10 = New On3dPoint(pt10)

refpt6.Rotate(j, axxis1, pt1)
refpt10.Rotate(j, axxis1, pt1)
'remake axes
refaxis2 = New On3dVector(refpt6 - refpt10)
'add brep to pattern1

pattern1.Add(New OnBrep(obj2))

refpt1 = New On3dPoint(pt1)
refpt5 = New On3dPoint(pt5)

refpt1.Rotate(k, refaxis2, refpt6)
refpt5.Rotate(k, refaxis2, refpt6)

obj3 = New OnBrep(obj2)
obj3.Rotate(k, refaxis2, refpt6)

pattern1.Add(New OnBrep(obj3))

'remake axes again
ref2axis = New On3dVector(refpt10 - refpt6)
axxis1 = ref2axis
pt6 = refpt6
pt10 = refpt10
pt1 = refpt1
pt5 = refpt5

obj = obj3

Next

A = pattern1
B = pattern

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