Is there a way to execute the command to match two curves (e.g., their curvature) fully from python? My use case is I have a python script that generates two splines that are connected at one end, and I want to match the curvature (the script does this multiple times).
I can’t find anything in rhinoscriptsyntax. I poked around a bit in RhinoScript and didn’t see anything either. Maybe it’s possible via some form of rs.Command("_Match …"), but I’m not sure how to programatically specify the curves.
The only other idea I had was to modify the curves to be a bit shorter and not quite touch and then invoke rs.AddBlendCurve(), but that seems klunky.
Scripting the Match command won’t be possible, as the command works based on where you pick on the input curves. And there is no way to script this kind of picking.
It does appear that the code behind Match is exposed on the SDK. I’ll add a wish list item to get his wrapped in RhinoCommon and Python.
Hi Dale, doesn’t AddBlendCurve have a similar issue about picking the curve ends? You just use rs.CurveDomain() to specify which end of both curves you want the operation to apply to. Or am I missing something?
Josh
I presume you can get all the point data from the curves and then modify their positions.
In other words program your own “match”.
Here is a dummy script that closes a curve if it has more than 3 control points.
import rhinoscriptsyntax as rs
obj = rs.GetObject("Select curve", rs.filter.curve)
if obj:
rs.EnableObjectGrips( obj, enable=True )
points = rs.ObjectGripLocations(obj)
if len(points)>3:
points[len(points)-1]=points[0]
rs.ObjectGripLocations(obj,points)
rs.EnableObjectGrips( obj, enable=False )
You have to rewrite it to work on two curves, find the “mean point”, move the end points to that location, and the “mean direction” for the match and then move the points next to the ends to that mean direction.
Hi Holo,
Do you know how to modify the control points to get the curvature of the end of one curve to match the other one? My NURBS knowledge isn’t super strong.
Hi Dale,
There are a couple of other functions that seem to be missing from python that I’d like to use in my project. How hard would it be to code something using the SDK to make those functions available in python? I’m a software engineer so am open to a bit of hacking…
Josh
To answer your question about picking, the answer is not. AddBlendCurve requries that you pass in parameters on the two curves that will be used as the blend curve end points
If you are using C++, you can use RhinoSdkBlend::CurveBlend. However, this may not produce the same results as Rhino’s Match command.
/*
Description
Makes a curve blend between 2 curves at the parameters specified
with the directions and continuities specified
Parameters:
[in] pC0 - First curve to blend from
[in] t0 - Parameter on first curve for blend endpoint
[in] bRev0 - if bRev0 is false, the blend will go in the natural direction of the curve
if bRev0 is true, the blend will go in the opposite direction to the curve
[in] continuity0 - continuity for the blend at the start
0: position
1: tangency
2: curvature
[in] pC1 - Second curve to blend from
[in] t1 - Parameter on second curve for blend endpoint
[in] bRev1 - if bRev1 is false, the blend will go in the natural direction of the curve
if bRev1 is true, the blend will go in the opposite direction to the curve
[in] continuity1 - continuity for the blend at the end
0: position
1: tangency
2: curvature
Returns:
The blend as an ON_Curve if successful
NULL if not
*/
Hi @dale, trying to match one curve end to another but cannot find a method to do this in RhinoCommon or python with the same logic as the match command. Has this been added ?