Saturday, April 28, 2012

Lofting Problem In Python

I mentioned this problem during my presentation the other day, and thought I would show a quick fix to get around it if anyone has the same problem in the future.

The issue is that if you want to loft (for example) a polygon and a circle together, python has problems aligning the start points of the curves which can lead to unexpected results(see Fig.1).

import rhinoscriptsyntax as rs
import math
import random

hex = rs.GetObject()
circ = rs.GetObject()
loftL = [hex,circ]
loft = rs.AddLoftSrf(loftL)

So what I did is wrote a function that will align the seams of the curves and then loft them together so that a python loft will match a rhino loft(Fig.2)
import rhinoscriptsyntax as rs
import math
import random

def loft(_crvList):
    crvList = _crvList
    for i in range (0,len(crvList)-1):
    srf = rs.AddLoftSrf(crvList)
    return srf

crvs = rs.GetObjects('select curves',4)

Very easy little function(only 6 lines of code) that will save a lot of headache if you have problems with your lofts.  It can be copied and pasted into any script and just use that instead of the rs.AddLoftSrf  command and it will work no matter how many curves you are trying to loft together

1 comment:

  1. Well done Dennis!
    The other option would be to approximate the upper circle with many segment and connect them with mesh to the lower shape (it happens anyway when you export to print it)