Loading and Saving Data

NURBS-Python provides the following API calls for exporting and importing spline geometry data:

JSON import/export works with all spline geometry and container objects. Please refer to File Formats for more details.

The following code snippet illustrates a B-spline curve generation and its JSON export:

 1from geomdl import BSpline
 2from geomdl import utilities
 3from geomdl import exchange
 4
 5# Create a B-Spline curve instance
 6curve = BSpline.Curve()
 7
 8# Set the degree
 9curve.degree = 3
10
11# Load control points from a text file
12curve.ctrlpts = exchange.import_txt("control_points.txt")
13
14# Auto-generate the knot vector
15curve.knotvector = utilities.generate_knot_vector(curve.degree, len(curve.ctrlpts))
16
17# Export the curve as a JSON file
18exchange.export_json(curve, "curve.json")

The following code snippet illustrates importing from a JSON file and adding the result to a container object:

1from geomdl import multi
2from geomdl import exchange
3
4# Import curve from a JSON file
5curve_list = exchange.import_json("curve.json")
6
7# Add curve list to the container
8curve_container = multi.CurveContainer(curve_list)