algorithmic modeling for Rhino
Hi Guys,
I am trying to incrementally rotate a line using the codes below in c# and Vb.net. The components show no error but they only overlap lines...Any idea what is going wrong? The python attempt just gave the strange message "i" unexpected token "i".
Many thanks,
on C#:
Arthur
private void RunScript(Curve ln, int x, double angle, ref object A)
{List<Curve> lines = new List<Curve>();
Int16 i = default(Int16);for(i = 0; i <= x; i++){
ln.Rotate(angle * i, Vector3d.ZAxis, ln.PointAtEnd);
lines.Insert(i, ln);
}A = lines;
on VB.net:
Private Sub RunScript(ByVal ln As Curve, ByVal x As Integer, ByVal angle As Double, ByRef A As Object)
Dim lns As New List(Of Curve)()
Dim i As Int16For i = 0 To x
ln.Transform(transform.Rotation(angle * i, vector3d.ZAxis, ln.PointAtEnd))
lns.Insert(i, ln)
NextA = lns
in python I get the strange error : unexpected token "i"
For i in xrange(0,x):
rs.RotateObject(angle * i, vector3d.ZAxis, ln.PointAtEnd)
rs.AddLine(lns)
A = lns
Tags:
Hi Arthur,
could you upload what you have so far?
Thanks,
- Giulio
_______________
giulio@mcneel.com
Hi Giulio,
Thanks for your reply!
Please see attached files.
arthur
Hi Arthur,
there were some minor syntax mistakes but one big issue: you should remember to copy objects if you do not want your changes to be not propagated from one tranformation to the next one.
(I've added a rhinoscriptsyntax and a RhinoCommon version of the Python script. Rhinoscriptsyntax works in degrees).
Thanks,
- Giulio
________________
giulio@mcneel.com
Thanks for sharing! I'm studying C# and Python these days and is a really usefull thing.
I've been trying a similar thing, but transforming points in a list and it doesn't seem to work:
profile_points(2).Transform(transform.Rotation(angle, vector3d.ZAxis, New point3d(0, 0, 0)))
This doesn't seem to actually rotate the point, although it doesn't throw an error.
I should add that the list of points was created within the script, not brought in through the input parameters.
Point3D is a structure, not a class. When you get a point from a list, you get a copy of that point. Then you transform the copy and ultimately you forget about the copy. You'll need to put the new point back into the list:
Dim point As Point3d = profile_points(2)
point.Transform(Transform.Rotation(...))
profile_points(2) = point
--
David Rutten
david@mcneel.com
Thanks David! I've just been reading about the differences between classes and structures and would like to clarify if the following is correct: As point3d is a structure, when you say "point = profile_point" an exact, independant copy is created. However, with classes such as the 'Curve' class, a reference to profile_curve will be copied if you say "curve = profile_curve". Does that mean if you modify 'curve', you will also modify 'profile_curve'?
That is correct. If you want to get a curve from somewhere, modify the curve whilst making sure you don't modify the original, you have to duplicate the curve first.
came across same problem. thanks for sharing~~~~~
I'm quite new to Python (and programming in general), but could your problem not be solved by assigning the variable i a value before trying to call it?
i = 0
for i in range(0,x):
rs.RotateObject(....
please forgive me if that is waaaaaayy low level... :D
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by