Hello,
I am using Rhino 8 (script editor using python 3) and Rhino common to create sth, now I encounter a problem…As the Rhino common API shows, ‘CurveIntersections’ has properties of ‘Count’ and ‘Item’, while only ‘Count’ property works in my code but ‘Item’ didn’t work. Can anybody help? I uploaded my gh file here.
Thanks a lot.
Xusheng
python_basics14_curve_input.gh (9.3 KB)
you’ll need to have a for loop with i < count
and access the item (an intersection even) through its iterator itxn[i]
Hi Adel, thanks for your quick answer. I tried as you suggested, it seems not working, maybe it’s my misunderstanding. Would you mind, if possible, to show me your answer on my uploaded gh.file?
Looking forward to your further info.
Xusheng
sure, here’s how you should use the code
import rhinoscriptsyntax as rs
import Rhino.Geometry as rg
a = []
b = []
for curve1 in curves:
for curve2 in curves:
if( curve1 != curve2):
itxn = rg.Intersect.Intersection.CurveCurve(curve1, curve2, 0.0001, 0.0001)
#count=getattr(itxn,'Count')
#print(count)
#this is how you should ge the number of itersection
count = itxn.Count
#this is a standard loop in pythin
for i in range(count):
#gets the intersection event
ix = itxn[i]
a.append(ix)
#gets the intersection point - there's more to this
#check https://developer.rhino3d.com/api/rhinocommon/rhino.geometry.intersect.intersectionevent
b.append(ix.PointA)
@Xusheng_Li note: there’s a problem with your outer loop logic, that’s why it returns extra points
use this pattern or similar
for i in range(listLength - 1):
for j in range(i+1, listLength):
#intersect curve[ i ] with curve[ j ]
updating the code above
# this takes intersection of all curves and build geometry around the intersection
# input type: curves - Curve (List Access)
import rhinoscriptsyntax as rs
import Rhino.Geometry as rg
a = []
b = []
curveCount = len(curves)
for k in range(curveCount - 1):
for m in range(k+1, curveCount):
curve1 = curves[k]
curve2 = curves[m]
if( curve1 != curve2): #this is redundant now...
itxn = rg.Intersect.Intersection.CurveCurve(curve1, curve2, 0.0001, 0.0001)
#count=getattr(itxn,'Count')
#print(count)
#this is how you should ge the number of itersection
count = itxn.Count
#this is a standard loop in pythin
for i in range(count):
#gets the intersection event
ix = itxn[i]
a.append(ix)
#gets the intersection point - there's more to this
#check https://developer.rhino3d.com/api/rhinocommon/rhino.geometry.intersect.intersectionevent
b.append(ix.PointA)
@adel.albloushi Thanks very much for your great answer. There is another question as a beginner. As I am using python for Rhino programming. But it seems the Rhino common(rhino geometry) is written in C#, (such as the code in my case,syntax *‘public [IntersectionEvent ] this[int index]’), so I didn’t use the code rightly. Should I also learn C# to use rhino.common? and then translate C# discription into python code if I am using python for Rhino programming? sorry for my stupid question as a beginner, but hopefully you can give me a little guidance.
I have a similar issue with BrepLoopList class - it doesn’t seem to have attribute “Item” anymore. Is there anywhere an update API documentation for RhinoCommon in Rhino 8?