AddLoftSrf not working

Hey guys, I’m basically trying to loft some curves and just cannot figure out why my lofts wont come out clean. I got my lofts, but they are like twisted or something, almost as if its skipping the mid curve. The curve in the middle is usually smaller than the first two curves which is why I used length to identify it.

import rhinoscriptsyntax as rs
from Rhino.Geometry import *
import System.Drawing.Color as color
import Rhino
import time
import math
import sys
sys.path.append("C:\\BMIRhinoTools\\Source")
import MO
import System.Drawing.Bitmap as BM
import utility as rhutil

def preloft(curves):
    plane = rs.WorldZXPlane()
    bbox2 = rs.BoundingBox(curves)
    cur_cen = (bbox2[0]+bbox2[6])*0.5
    a  = rs.AddPoint(cur_cen)
    b = rs.VectorCreate([0,0,20],[0,0,0])
    c = rs.VectorCreate([20,0,0],[0,0,0])
    d = rs.VectorCreate([-20,0,0],[0,0,0])
    point1 = rs.CopyObject(a,b)
    point2 = rs.CopyObject(a,c)
    point3 = rs.CopyObject(a,d)
    boundary = rs.AddCircle3Pt(point1,point2,point3)
    return (boundary)


inputc = rs.ObjectsByLayer("NewNostrils",rs.filter.curve)

bound = preloft(inputc)
surface = rs.AddPlanarSrf(bound)
rs.DeleteObject(bound)

right_nostril =[]
left_nostril =[]

for i in inputc:
    bbox = rs.BoundingBox(i)
    cent = (bbox[0]+bbox[6])*0.5
    if cent.X>0:
        left_nostril.append(i)
    else:
        right_nostril.append(i)


#gettherightcurves
lower_right_curve = rs.PointClosestObject([0,0,-10],right_nostril)[0]
lower_left_curve = rs.PointClosestObject([0,0,-10],left_nostril)[0]
top_right_curve = rs.PointClosestObject([0,0,20],right_nostril)[0]
top_left_curve = rs.PointClosestObject([0,0,20],left_nostril)[0]

#getthecurvelenght
lowleft_len = rs.CurveLength(lower_left_curve)
topleft_len = rs.CurveLength(top_left_curve)
lowright_len = rs.CurveLength(lower_right_curve)
topright_len = rs.CurveLength(top_right_curve)

#getthemiddlecurves
mid_left_curve =[]
mid_right_curve =[]

for cur_a in left_nostril:
    if rs.CurveLength(cur_a) < lowleft_len and rs.CurveLength(cur_a) < topleft_len:
        mid_left_curve.append(cur_a)

for cur_b in right_nostril:
    if rs.CurveLength(cur_b) < lowright_len and rs.CurveLength(cur_b) < topright_len:
        mid_right_curve.append(cur_b)

#Startlofting
for cur in inputc:
    int = rs.CurveSurfaceIntersection(cur,surface)
    param = int[0][6]
    rs.CurveSeam(cur,param)
    if(not rs.CurveDirectionsMatch(cur,inputc[0])):
        rs.ReverseCurve(cur)

#LoftCurves
rs.DeleteObject(surface)
rightLoft = rs.AddLoftSrf((top_right_curve,mid_right_curve[0],lower_right_curve),None,None,1,1,155)[0]
lefttLoft = rs.AddLoftSrf((top_left_curve,mid_left_curve[0],lower_left_curve),None,None,1,1,155)[0]

Hi Zoey,

Can you paste your code surrounded by backticks so it shows up properly? Could this be because the middle curve is oriented the other way around?

```python
… code here …
```

1 Like

Yep, likely the case…

1 Like

hey sorry bout that, i wasnt familiar with what format to post in. How did you know the mid curve is the other way around and others aren’t? I thought this bit would help ensure they are all in the right direction? Thanks btw :slight_smile:

for cur in inputc:
int = rs.CurveSurfaceIntersection(cur,surface)
param = int[0][6]
rs.CurveSeam(cur,param)
if(not rs.CurveDirectionsMatch(cur,inputc[0])):
rs.ReverseCurve(cur)

I have had this problem enough times over the years for the solution to stick in my memory!
:smiley:

1 Like

Lol :smiley: nice.

Do you have any suggestions on how I can turn it around? Like in my older comment I put in some code, I thought this would ensure they are all in the right direction. But they obviously aren’t :cry: what should I change/or add in my script you reckon? Thanks :slight_smile:

Yes I would have tried CurveDirectionsMatch too. Is there a simpler logic for your geometry ? Eg selecting the lowest x, closest to a given point or surface, … ?

1 Like

I think CurveDirectionsMatch only works reliably with closed curves…