Grasshopper

algorithmic modeling for Rhino

Hi all,

I am new to VB and just struggling with some lines of code.

what I want to do is do copy a curve (which I supplied to VB component) and rotate it while keeping the original as it is.

 

 

Attached is screen shot for that. At the output tab A, I want this to be the original and for B, the rotated.

Here is the code. How can I get original curve to A tab? Right not both A and B are assigned with the rotated.

--------------------------------------------------------------------------

  Private Sub RunScript(ByVal x As Curve, ByVal y As Vector3d, ByRef A As Object, ByRef B As Object)

    Dim crv As Curve = x

    Dim ref As curve = x

    crv.Rotate(math.PI / 2, y, x.PointAtStart)

    A = crv     B = ref

  End Sub

-------------------------------------------------------------------------

Any comments would be appreciated. Thanks.

 

 

 

Views: 404

Replies to This Discussion

I found the answer by myself.

I can put .duplicate after x. which is very weird to me, because as far as I understand, "Dim crv as Curve = x" means that I assign a duplicate of x to temporary storage called crv. I mean if that is the case, x should stay intact whatever action do I do to the duplicate called "crv". In the context of the code above, even if "ref" has nothing to do with rotation, at the end of the code it also get rotated.

 

Anyone can explain this to me?

Thanks.

Curve is a class. Therefore when you assign using the equals operator you do not get a copy of the original.

There is no mechanism in .NET for creating a duplicate of a class unless the class itself specifically provides a Duplicate function or a special constructor or something. 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

I see. Really good to know.

If that is the case, I probably have to define instance out of class before I use equall operator. Right?

 

Thanks much!

 

You can say:

Dim crv As Curve = x.DuplicateCurve()

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Awesome. Thanks much!

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