+ Reply to Thread
Results 1 to 6 of 6

Thread: bug in rs.PlaneCurveIntersection

  1. #1

    bug in rs.PlaneCurveIntersection

    Hi Steve,

    the rs.PlaneCurveIntersection() does not work.
    I tried this script from the help

    Python Code:
      import rhinoscriptsyntax as rs
       
       
       
      curve = rs.GetObject("Select curve", rs.filter.curve)
       
      if curve:
       
          plane = rs.WorldXYPlane()
       
          intersections = rs.PlaneCurveIntersection(plane, curve)
       
          if intersections:
       
              for intersection in intersections:
       
                  rs.AddPoint(intersection[1])

    but it constantly throws an error.
    See image attached.

    Could you please have a look a it!

    Thanks!
    Attached Images

  2. #2
    Super Moderator Mitch's Avatar
    Join Date
    May 2010
    Location
    Switzerland
    Posts
    313
    Yes, there is a bug in this function. It will fail if no intersection is found.

    Python Code:
      def PlaneCurveIntersection(plane, curve, tolerance=None):
          "Intersect an infinite plane and a curve object"
          plane = rhutil.coerceplane(plane, True)
          curve = rhutil.coercecurve(curve, True)
          if tolerance is None: tolerance = scriptcontext.doc.ModelAbsoluteTolerance
          intersections = Rhino.Geometry.Intersect.Intersection.CurvePlane(curve, plane, tolerance)
          #<-- the rc=[] line below should actually be here
          if intersections:
              rc = []  # rc is defined only if there are intersections
              for intersection in intersections:
                  a = 1
                  if intersection.IsOverlap: a = 2
                  b = intersection.PointA
                  c = intersection.PointA2
                  d = intersection.PointB
                  e = intersection.PointB2
                  f = intersection.ParameterA
                  g = intersection.ParameterB
                  h = intersection.OverlapA[0]
                  i = intersection.OverlapA[1]
                  j = intersection.OverlapB[0]
                  k = intersection.OverlapB[1]
                  rc.append( (a,b,c,d,e,f,g,h,i,j,k) )
          return rc  # will fail if intersections is None
       

    --Mitch
    Last edited by Mitch; 06-28-2012 at 07:51 PM.

  3. #3
    Hi Mitch,

    thanks for your reply and your help!
    I also found that error and moved the rc = [] two lines up.
    But for me that didn't help ?

  4. #4
    Super Moderator Mitch's Avatar
    Join Date
    May 2010
    Location
    Switzerland
    Posts
    313
    It should work. Make sure you got the indent right and most importantly - make sure all of the Rhino instances are closed BEFORE making the modifications to plane.py...

    It works here.

    --Mitch

  5. #5
    Hi Mitch,

    ok got it.
    I was trying to modify the plane.py directly via the script editor.
    That didn't work.
    Now it's fne....

    Thanks again!

  6. #6
    Senior Member Steve Baer's Avatar
    Join Date
    Apr 2010
    Location
    Seattle
    Posts
    1,472
    Blog Entries
    19
    My fix for this is almost the same as Mitch's except I indented return rc so it is only returned if there are intersections. This way if no intersections were found, then None is returned (based on another thread where Mitch asked for this type of functionality.) If a function ends and doesn't explicitly return something, then None is returned.

    https://github.com/mcneel/rhinopytho...t/plane.py#L77

    -Steve

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts