Here’s the NURBS JSON loader so far, it could use some polish on the loading part, which is commented out…
#!/usr/bin/env python
#Import NURBS curves exported from Rhino into ad hoc JSON format
import json
import modo
import lx
import lxu
json_str = '{"curves": [{"closed": false, "knots": [0.0, 0.0, 0.0, 19.270446242706978, 38.540892485413949, 57.81133872812093, 57.81133872812093, 57.81133872812093], "id": "28f0ad8a-8e03-4061-9c33-ef251963b16f", "cvs": [[-11.0, -6.0, 0.0, 1.0], [-19.0, 3.0, 0.0, 1.0], [-13.0, 10.0, 0.0, 1.0], [1.0, 7.0, 0.0, 1.0], [16.0, 3.0, 0.0, 1.0], [19.0, 9.0, 0.0, 1.0]], "dim": 3, "rational": false, "knot_count": 8, "periodic": false, "cv_count": 6, "planar": true, "degree": 3}, {"closed": false, "knots": [0.0, 6.324555320336759, 14.926880587379387, 22.137983138307366, 28.462538458644126, 37.896519590700727, 44.9675874025662, 60.100333352987761], "id": "8048255a-18eb-43af-97bb-2d257edf311f", "cvs": [[-2.0, 0.0, 0.0, 1.0], [-4.0, -6.0, 0.0, 1.0], [3.0, -1.0, 0.0, 1.0], [7.0, -7.0, 0.0, 1.0], [9.0, -1.0, 0.0, 1.0], [17.0, -6.0, 0.0, 1.0], [18.0, 1.0, 0.0, 1.0], [3.0, 3.0, 0.0, 1.0]], "dim": 3, "rational": false, "knot_count": 8, "periodic": false, "cv_count": 8, "planar": true, "degree": 1}], "curve_count": 2, "rhino": 5, "version": 1.0, "date": "15/03/2017"}'
data = json.loads(json_str)
#data = json.load(open('/Users/arnie/Documents/sampleNURBSCurves.json', 'r'))
curves = data['curves']
print 'Number of curves: ',len(curves)
scene = modo.Scene()
mesh = scene.addMesh("Mesh")
vmap_BSPL = lxu.lxID4('BSPL')
maps = mesh.geometry.vmaps.getMapsByType(vmap_BSPL)
wmap = maps[0]
storage = lx.object.storage()
storage.setType('f')
storage.setSize(1)
geo = mesh.geometry
with mesh.geometry as geo:
for crv in curves:
v=[]
for cv in crv['cvs']:
nv = geo.vertices.new((cv[0],cv[1],cv[2]))
v.append(nv)
pa = lx.object.Point(nv._accessor)
pa.Select(nv._id)
storage.set([cv[3],])
pa.SetMapValue(wmap._id,storage)
if crv['closed']:
v.append(v[0])
print len(v)
poly = geo.polygons.new(v,False,lx.symbol.iPTYP_BSPL)
poly.setTag (lx.symbol.i_POLYTAG_PART,crv['id'])