algorithmic modeling for Rhino
Hi all,
I am writing a script in python where unfortunately (because of some problems with curvecurveintersection command) I had to use both rhino common (which I am not familiar with) and rhinoscriptsyntax.
I already wrote a function which is giving me as output one or more points as rhino common objects.
For example if I print the output I get:
[<Rhino.Geometry.Point3d object at 0x000000000000055E [-8.68932192728028,-8.18928866036044,1.84595094393439]>]
Now, how do I extrapolate the coordinates of the object or its Guid in order to use it with the rhinoscript syntax?
e.g. rs.PointCoordinates()
My knowledge of rhino common is quite scarce, I apologize for this, hope you can help me.
Thanks a lot in advance
V.
Tags:
Is it in the editor?
Rhino.Geometry.Point3d has other attributes and methods such as Rhino.Geometry.Point3d.X which returns the x coordinate.
in a similar way you can access the other coordinates as well.
I think that rs.PointCoordinates() needs a guid to work on.
Best,
M.
Thanks Mario, but how would the syntax be?
Let's say I have the point 3d stored in the variable called "int"
When I do something like:
print Rhino.Geometry.Point3d.X(int)
I get an error : getset_descriptor is not callable
So how do I tell him to give me the X of that particular point?
(I am working in the python editor)
I think this will clear things out
import Rhino as rc
pt = rc.Geometry.Point3d(1.55,5.40,9.40)
print pt.X,pt.Y,pt.Z
M.
As I was saying, pt is already something:
pt = IntersectCurves(crvy,crvx[0])
print pt
"[<Rhino.Geometry.Point3d object at 0x000000000000055F [-8.68932192728028,-8.18928866036044,1.84595094393439]>]"
pt.X
"Message: 'list' object has no attribute 'X'"
Ok, I solved it
pt[0] is the point I can use with the rhinoscriptsyntax, it is a list with just one element.
Thanks Marios
V.
Ciao Vincenzo,
the reason is that curve-curve intersection might lead to more than one point, so it gives back a list. As you already figured out, lists in Python are like arrays, so you can access their elements with an index in square brackets. Usually, the dot operator in Python lets you access fields and methods of classes: each non-primitive variable type is a class, and those included in Rhino are organized in the RhinoCommon structure. Point3d is a class within Rhino.Geometry, this is why you call it with dots in between the words. X, Y and Z are fields of the Point3d class.
Maybe I'm stating the obvious (in this case ignore my message!) :)
.a.
Thanks Alessio,
yes, my problem at that point was that I didn't understand that even with one single intersection I was getting a list (this with the rhino common program with which I was struggling).
However I feel that the rhinoscriptsyntax command curvecurveintersection gives a really complex output repeating the same intersection for each curve considered, and it seems to me also having some problems with the tolerances. It would be really nice to have a command which would give out directly just the intersection as a list of points just exactly how it happens when you run the "intersect" command in the usual interface of rhino.
However, I tried to make a function, even if it is far from being accurate.
import rhinoscriptsyntax as rs
def intersect (crv1,crv2,tol):
divisions = 1000
pts1 = rs.DivideCurve(crv1,divisions)
outpts = []
for i in range(0,len(pts1)):
par = rs.CurveClosestPoint(crv2,pts1[i])
pt2 = rs.EvaluateCurve(crv2,par)
dist1 = rs.Distance(pts1[i],pt2)
if dist1 < tol:
if len(outpts)>0:
print "it is"
index2 = rs.PointArrayClosestPoint(outpts,pts1[i])
dist2 = rs.Distance(pts1[i],outpts[index2])
print dist2
if dist2 > tol*5:
outpts.append(pts1[i])
else:
outpts.append(pts1[i])
return outpts
crv1 = rs.GetObject("crv1",4)
crv2 = rs.GetObject("crv2",4)
pts = intersect (crv1,crv2,.01)
if pts:
rs.AddPoints(pts)
don't know if someone has better ideas/solutions.
Just to give an overall idea my main goal was to sample (part of) a surface with equal length segments. To do so i put spheres equally spaced in one direction, than get their intersection with the surface (intersect brep = curves) than starting from one sphere and its intersection (curve) in the other direction get the intersection between the two curves (the curve curve intersection) and draw another sphere from there and so on.
I don't know if it is a conceptual problem or a problem of memory but it looks the iteration at a certain point just stop working, and the intersections, no matter what the tolerance, start to fail.
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