Add interactive spline

Add interactive spline

AndersSSimonsen
Participant Participant
1,642 Views
8 Replies
Message 1 of 9

Add interactive spline

AndersSSimonsen
Participant
Participant

Hi

I'm trying to define a spline (degree 3) through the API, which is fairly straight forward:

 

#include <Core/CoreAll.h>
#include <Fusion/FusionAll.h>
#include <CAM/CAMAll.h>

using namespace adsk::core;
using namespace adsk::fusion;
using namespace adsk::cam;

Ptr<Application> app;
Ptr<UserInterface> ui;

extern "C" XI_EXPORT bool run(const char* context)
{
	app = Application::get();
	if (!app)
		return false;
	ui = app->userInterface();
	if (!ui)
		return false;

	Ptr<Design> design = app->activeProduct();
	Ptr<Component> rootComp = design->rootComponent();
	Ptr<Sketches> sketches = design->rootComponent()->sketches();
	Ptr<Sketch> sketch = sketches->add(rootComp->xYConstructionPlane());
	Ptr<SketchCurves> sketchCurves = sketch->sketchCurves();

	std::vector<double> knots = { 0,0,0,0, 1,1,1,1 };
	int degree = 3;
	Ptr<Point3D> P0 = Point3D::create(0, 0, 0);
	Ptr<Point3D> P1 = Point3D::create(1, 0, 0);
	Ptr<Point3D> P2 = Point3D::create(1, 1, 0);
	Ptr<Point3D> P3 = Point3D::create(0, 1, 0);
	const std::vector<Ptr<Point3D>> controlPoints = { P0,P1,P2,P3 };

	sketchCurves->sketchFittedSplines()->addByNurbsCurve(NurbsCurve3D::createNonRational(controlPoints, degree, knots, false));
	return true;
}

#ifdef XI_WIN
#include <windows.h>
BOOL APIENTRY DllMain(HMODULE hmodule, DWORD reason, LPVOID reserved)
{
	switch (reason)
	{
	case DLL_PROCESS_ATTACH:
	case DLL_THREAD_ATTACH:
	case DLL_THREAD_DETACH:
	case DLL_PROCESS_DETACH:
		break;
	}
	return TRUE;
}
#endif // XI_WIN

After having executed the script in Fusion 360, the spline looks like this:

Fig 1.PNG

 

However, when I move any of the control points, the Nurbs curve is converted to a "Fit Point Spline", which transforms it to this:

 

Fig 2.PNG

 

So just to underline the change - here are the two overlaid:

Fig 3.PNG

What I want is the expected curve, which I've shown here: (Generated using the "Control Point Spline" command within Fusion): 

Fig 5.PNG

Is there any way to create a spline through the API, which allows me to move the nodes without converting the curve to a "Fit Point Spline"? 

 

Thanks!

Anders

0 Likes
Accepted solutions (1)
1,643 Views
8 Replies
Replies (8)
Message 2 of 9

AndersSSimonsen
Participant
Participant

Me again...

 

Or to phrase the question in another way:

Is there any way to add a "Control Point Spline" through the API? 

 

xxx.png

Regards Anders 

0 Likes
Message 3 of 9

BrianEkins
Mentor
Mentor
Accepted solution

It's not possible. When the API to create a curve using a NURBS definition was added, all Fusion supported was a curve fit through points so it had to be implemented to create one of those. Support for control point splines was added later and the API hasn't been updated to support them.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
0 Likes
Message 4 of 9

AndersSSimonsen
Participant
Participant

Hi Brian

Okay, thanks for the answer!

I guess I can only hope they'll implement this some day. 🙂 

Regards Anders

0 Likes
Message 5 of 9

nikogosovd
Explorer
Explorer

It would be nice to have corresponding API for control point splines, like the following:

 

curve = adsk.core.NurbsCurve3D.createNonRational(controlPoints, degree, knots, isPeriodic)
spline = sketch.sketchCurves.sketchControlPointSplines.addByNurbsCurve(curve)

This will make it possible to create editable control point splines with fine control of weights and knots. This also will allow to create periodic control point splines which is impossible through the UI now.

Message 6 of 9

OceanHydroAU
Collaborator
Collaborator

Does anyone know what "sketchFixedSplines" are?  They don't have an .add method (yet?)

 

Could a method perhaps be created which points to the existing internal sketch control point spline implementation that the UI enjoys?

 

endobj=sketch.sketchCurves.sketchFittedSplines.add(endcap) # Works
endobj=sketch.sketchCurves.sketchFixedSplines.add(endcap) # No such method 😞

 

For anyone else reading this - also consider using an ellipse if you can manipulate your needs down into just 3 points.  e.g. I put a nice rounded cap on a complicated ending shape that had been extruded with this:

 

# Put a rounded 3D end-cap on a flat sketch shape (between the under and over points)
enddist=underpt.distanceTo(overpt)
minor=adsk.core.Point3D.create( 0.5*(overpt.x+underpt.x), 0.5*(overpt.y+underpt.y), .5*enddist) 
center=adsk.core.Point3D.create( 0.5*(overpt.x+underpt.x), 0.5*(overpt.y+underpt.y), 0)
major=overpt
ellipse=sketch.sketchCurves.sketchEllipses.add(center, major, minor)
0 Likes
Message 7 of 9

kandennti
Mentor
Mentor

"sketchFixedSpline" was created by executing "sketchConicCurve" or "sketchFittedSpline" with sketch.include or sketch.project.

1.png

0 Likes
Message 8 of 9

AndersSSimonsen
Participant
Participant

I've figured out a solution - well "OceanHydroAU" has 🙂 I found a Python script here https://forums.autodesk.com/t5/fusion-360-api-and-scripts/example-of-how-to-use-sketchcurves-sketchf... , which does what I need.
I change the code and also included a line for breaking the projection link, which is created for some reason(?). The remaining curve is a control point spline:
xxx.PNG

 

Here is the working code, where only a few lines have changed compared to my original entry: 

 

#include <Core/CoreAll.h>
#include <Fusion/FusionAll.h>
#include <CAM/CAMAll.h>

using namespace adsk::core;
using namespace adsk::fusion;
using namespace adsk::cam;

Ptr<Application> app;
Ptr<UserInterface> ui;

extern "C" XI_EXPORT bool run(const char* context)
{
	app = Application::get();
	ui = app->userInterface();

	Ptr<Design> design = app->activeProduct();
	Ptr<Component> rootComp = design->rootComponent();
	Ptr<Sketches> sketches = design->rootComponent()->sketches();
	Ptr<Sketch> sketch = sketches->add(rootComp->xYConstructionPlane());
	Ptr<SketchCurves> sketchCurves = sketch->sketchCurves();

	std::vector<double> knots = { 0,0,0,0, 1,1,1,1 };
	int degree = 3;
	Ptr<Point3D> P0 = Point3D::create(0, 0, 0);
	Ptr<Point3D> P1 = Point3D::create(1, 0, 0);
	Ptr<Point3D> P2 = Point3D::create(1, 1, 0);
	Ptr<Point3D> P3 = Point3D::create(0, 1, 0);
	const std::vector<Ptr<Point3D>> controlPoints = { P0,P1,P2,P3 };

	Ptr<NurbsCurve3D> nurbsCurve = NurbsCurve3D::createNonRational(controlPoints, degree, knots, false);
	Ptr<SketchFixedSpline> Curve = sketchCurves->sketchFixedSplines()->addByNurbsCurve(nurbsCurve);
	Curve->isReference(false);
	return true;
}

#ifdef XI_WIN
#include <windows.h>
BOOL APIENTRY DllMain(HMODULE hmodule, DWORD reason, LPVOID reserved)
{
	switch (reason)
	{
	case DLL_PROCESS_ATTACH:
	case DLL_THREAD_ATTACH:
	case DLL_THREAD_DETACH:
	case DLL_PROCESS_DETACH:
		break;
	}
	return TRUE;
}
#endif // XI_WIN

 

0 Likes
Message 9 of 9

BrianEkins
Mentor
Mentor

The addByNurbsCurve method was on the SketchFixedSplines object was just added this past December so this is a new capability.  It's what was discussed as desirable earlier in this thread.

 

https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-EA5FBD51-ED6F-4D04-83B2-D72A384BC6DA

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com