AddNetworkSrf type problem

I wanted to write a script that will create a surface from the edges of a surface. If there are only 2 edge curves then I need a loft, if between 2 and 4 edge surface command and if more than 4 a network surface command should run. Here is the code:

import rhinoscriptsyntax as rs
import Rhino as rh

print crvs
print type(crvs[1])
#print len(crvs)

#crvs = [rs.coercecurve(crv) for crv in crvs]
#print type(crvs[1])

if len(crvs) <= 2:
    dir_check = rs.CurveDirectionsMatch(crvs[0], crvs[1])
    if dir_check == False:
        crvs[1] = rs.ReverseCurve(crvs[1])
#        crvs[1] = rh.Geometry.Curve.Reverse(crvs[1])
    srf = rs.AddLoftSrf(crvs)
elif 2 < len(crvs) <= 4:
    srf = rs.AddEdgeSrf(crvs)
    srf = rs.AddNetworkSrf(crvs, cont, edge_tol, int_tol, angle_tol)

When I run this code I get this error on rs.ReverseCurve function:

Runtime error (TypeErrorException): Parameter must be a Guid or string representing a Guid

  line 890, in coerceguid, "C:\Users\Erdem\AppData\Roaming\McNeel\Rhinoceros\6.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rhinoscript\"
  line 995, in coercecurve, "C:\Users\Erdem\AppData\Roaming\McNeel\Rhinoceros\6.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rhinoscript\"
  line 490, in AddLoftSrf, "C:\Users\Erdem\AppData\Roaming\McNeel\Rhinoceros\6.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rhinoscript\"
  line 28, in script

I’m pretty sure that the types of the items of crvs list are Guid. So I don’t understand why it asks for a Guid type object when I already pass Guid type objects? :angry:

By the way, rs.AddEdgeSrf function works with this same input but rs.AddLoftSrf and rs.AddNetworkSrf don’t work. What’s the logic?

Weird, your code works just fine for me! Here’s a working Grasshopper definition for you to compare against your own… (5.7 KB)

Thanks for the reply Will.

I tried restarting Rhino and Windows. Both didn’t help! But when I checked your code I saw that you didn’t use the additional inputs into the AddNetworkSrf function.

When I copied what you did, I saw that it works perfectly. Finally I realized that it didn’t work because I didn’t pass anything onto other inputs, thus “None” values went into the function. That should have kept it from working. Still I don’t understand why it didn’t say “you passed in None instead of …” and only said “expected IEnumerable[Curve], got List”.

Here is the working code for reference:

import rhinoscriptsyntax as rs

if not cont:
    cont = 0
if not edge_tol:
    edge_tol = 0
if not int_tol:
    int_tol = 0
if not angle_tol:
    angle_tol = 0

if len(crvs) <= 4:
    srf = rs.AddEdgeSrf(crvs)
    srf = rs.AddNetworkSrf(crvs, cont, edge_tol, int_tol, angle_tol)

AddNetworkSrf() calls Rhino.Geometry.NurbsSurface.CreateNetworkSurface() behind the scenes. Since some of the parameters were empty, I wonder if IronPython got confused and tried to call the wrong overload – the one that takes two collections of curves, instead of one. Anyway, it’s just a hunch. I’m glad you figured it out!

That makes sense.

Thank you for the help.