Complete new to python

hi, today is my first day working with python

I got this message while running a script done by my instructor

Message: Could not find file “”

Traceback (most recent call last):
IOError: [Errno 2] Could not find file “”

Please advise what’s wrong with my script… thank you so much !

If you post the script it might help…

Platform: Mac or PC? How are you launching the script?

–Mitch

Thank you so much Mitch for your help!

Yes, my instructors’ used PC and the script run perfectly when I used the PC at class. At home I download and try to run it in MAC ATOM.

In ATOM, I right click and there is a button for “Save and run in Rhino”

Many thanks for your help again!!


import rhinoscriptsyntax as rs

def mapValue(val, inMin, inMax, outMin, outMax):
outR = outMax - outMin
inR = inMax - inMin
inVal = val - inMin
newVal = (inVal/inR) * outR
return outMin + newVal

def lerp(startPt, endPt, T):
len = rs.VectorSubtract(endPt, startPt)
nVec = rs.VectorScale(len, T)
return rs.VectorAdd(startPt, nVec)

def calcBiLinear(pt, bbMin, bbMax):
bX = mapValue(pt.X,bbMin[0],bbMax[0],0.0,1.0)
bY = mapValue(pt.Y,bbMin[1],bbMax[1],0.0,1.0)
return[bX,bY]

def calcTriLinear(pt, bbMin, bbMax):
bX = mapValue(pt.X,bbMin[0],bbMax[0],0.0,1.0)
bY = mapValue(pt.Y,bbMin[1],bbMax[1],0.0,1.0)
bZ = mapValue(pt.Z,bbMin[2],bbMax[2],0.0,1.0)
return[bX,bY,bZ]

def main():
box = rs.GetBox()

unitCubeMin = box[0]
unitCubeMax = box[6]

units = rs.GetObjects("select polylines", 4)
meshes = rs.GetObjects("select meshes",32)

for unit in units:
    unitPts = []
    unitCoords =[]

    polylinePts = rs.PolylineVertices(unit)

    for pt in polylinePts:
        tc = calcTriLinear(pt,unitCubeMin,unitCubeMax)
        unitCoords.append(tc)
        unitPts.append(pt)

    for mesh in meshes:
        v = rs.MeshVertices(mesh)
        count = 0

        newPts = []
        for i in range(0, len(unitPts)):
            bLC = unitCoords[i]
            lX1 = lerp(v[4],v[5],bLC[0])
            lX2 = lerp(v[3],v[0] ,bLC[0])

            uX1 = lerp(v[6],v[7],bLC[0])
            uX2 = lerp(v[1],v[2],bLC[0])

            y1 = lerp(lX1,lX2,bLC[1])
            y2 = lerp(uX1,uX2,bLC[1])

            pt = lerp(y1,y2,bLC[2])
            rs.AddPoint(pt)
            newPts.append(pt)

        rs.AddPolyline(newPts)

if name == “main”:
main()

Looks OK on quick inspection, can’t test right now, have to go out. From Atom, you will need to save it somewhere as a filename.

You can also save it as a .py file anywhere then browse to it and run with the command _RunPythonScript.

Also, it you remove the if name == "main": line and just leave main() at the end - does it run?

–Mitch

Thank you Mitch! I have deleted the last line but it seems Rhino can’t find Atom to run to begin with… I tried different script with runRhinoScript command, the same error…

I think I need to give up for a few hours and deinstall and reinstall everything and try again…

million thanks for your help!! have a great sunday!

Try running the command StartAtomEditorListener in Rhino so that Rhino is listening for Atom. Otherwise, try running it with RunPythonScript (not runRhinoScript) directly from Rhino without Atom. For that, you need to save the script somewhere (like the desktop) as a .py file, then browse to it once RunPythonScript launches a file browser window.

Thank you Mitch!! It seems to work now :smile:
The RunPythonScript works…
million thanks again for your help… i am sure i will have more questions to you soon…

OK, that’s good, so at least we know your python is working. Now, we still need to figure out why your Atom and Rhino are not communicating…