Vbscript curve class

vbscript:
I would like to make a make a copy of a curve (basecurve) and perform transform methods to this copy (newCurve) without changing the original basecurve.
because curve is a class, any changes i make to the newCurve changes the baseCurve which is not what I want.
how can I overcome this?

Are you using Rhinoscript? Most of the transform operations in Rhinoscript produce a transformed copy of the original object, and do not transform the object in place…

–Mitch

hi
no I am using VBscript

@cshea, please post some example code.

_
c.

Here it goes:

basecurve was set into Grasshopper component

Dim translateVec As New rhino.Geometry.Vector3d(1, 0, 0)
Dim dist as double = 2.0
Dim centrepoint as rhino.Geometry.Point3d(0,0,0)
Dim translatedist as double
Dim arrAllCurves As New list(Of Curve)
Dim newCurve as curve
newCurve=basecurve
dim i as integer
for i =0 to 10
translatedist=dist*i
translateVec.Transform(transform.Scale(centrepoint, translatedist))
newCurve.Transform(Transform.Translation(translateVec))
arrAllCurves.add(newCurve)
next

all the newCurves in the array end up being in the same location…

You are making only one new reference to the basecurve using newCurve=basecurve and transforming this newCurve as far as i can see. So the newCurve is the basecurve.

If you want to keep the original basecurve unchanged, use newCurve = basecurve.Duplicate(). If you want to do your transforms, each with a new curve, you would have to put this in your loop.

Does that help ?
_
c.

I’ve been using .DuplicateCurve(); and now that I think about it I don’t actually know the dif between the .Duplicate() and .DuplicatCurve() methods. Results seem same to me?

Hi @Michael_Pryor, i guess they do the same according to the identical help text:

Constructs an exact duplicate of this Curve.

i find Duplicate() is just more generic.
_
c.

1 Like

I think it works for the first time before the loop
how would that work within the loop?
I

@cshea, as far as i understand your code (with making the duplicate so that the basecurve does not change) it transforms the newCurve 10 times and looks like this:

Dim newCurve As curve
newCurve = basecurve.Duplicate()
Dim i As Integer
For i = 0 To 10
      translatedist = dist * i
      translateVec.Transform(transform.Scale(centrepoint, translatedist))
      newCurve.Transform(Transform.Translation(translateVec))
      arrAllCurves.add(newCurve)
Next

What i thought would look like this:

Dim i As Integer
For i = 0 To 10
      translatedist = dist * i
      translateVec.Transform(transform.Scale(centrepoint, translatedist))
      Dim newCurve As curve
      newCurve = basecurve.Duplicate()
      newCurve.Transform(Transform.Translation(translateVec))
      arrAllCurves.add(newCurve)
Next

So it would create a new curve for every cycle in the loop. Or maybe i do not understand why you need the loop at all. You could just do this instead:

translatedist = dist * 10

_
c.

hi
thanks for your response
this is what i am trying to do just as an example :
i would like 10 curves like the basecurve in 10 different locations (incrementally moved in the x direction each time)

Then you might just do what i’ve shown in my second example. You could omit creating or scaling the vector. Just pass the index (i) to the arguments of the transform method for the x value while setting y and z to 0.

Dim i As Integer
For i = 0 To 10
      Dim newCurve As curve
      newCurve = basecurve.Duplicate()
      newCurve.Transform(Transform.Translation(i+1,0,0))
      arrAllCurves.add(newCurve)
Next

Here is an example vbscript for Transform.Translation.
_
c.

i see, if you set a new parameter dim curve in each loop, a completely new newCurve will exist in that loop which will not affect the previous “newCurve” already collected in the arrAllCurves in the previous loop … is this correct??
thanks so much

Yes.