Getting error to get controlPoints from SketchControlPointsSpline

Getting error to get controlPoints from SketchControlPointsSpline

jiri.manak
Contributor Contributor
642 Views
8 Replies
Message 1 of 9

Getting error to get controlPoints from SketchControlPointsSpline

jiri.manak
Contributor
Contributor

Hello,

this is connected to issue https://forums.autodesk.com/t5/fusion-360-api-and-scripts/bug-inside-offset-of-a-loop-of-sketchcontr...

but other problem.

I am trying to use SketchControlPointSpline.controlPoints property to edit start and end points but my script fails at this statement. 

Why it doesn't work? Tried  with Capture history on / off,  during sketch editing,  allways the same.

Script is attached. The object in the sketch is a loop made of 8 SketchControlPointSpline segments.

DXF is  attached to the post with the bug description.

 

Regards

Jiri

 

 

Screenshot 2022-09-14 200630.png

 

 

0 Likes
643 Views
8 Replies
Replies (8)
Message 2 of 9

kandennti
Mentor
Mentor

Hi @jiri.manak .

 

I tried it.

The log shows a "SketchFittedSpline" object.

1.png

 

Unfortunately, the "SketchFittedSpline" object does not have a controlPoints property.

https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-GUID-6fc8b90c-e04a-4f4f-ac0d-f511e7237a77 

 

I have not tried it, but the fitPoints property should be able to get the transit points.

 

 

I could not understand why it is possible to cast to SketchControlPointSpline.

0 Likes
Message 3 of 9

jiri.manak
Contributor
Contributor

Hi @kandennti

 thanks for trying.

But what's going on here? 

I get SketchControlPointSpline. I tried again both curves from the original post  loop.dxf, loop2.dxf. 

jirimanak_0-1663391274343.png

Its strange that you get something different.

Fusion 360  version   2.0.14110,   Windows 11

 

 

0 Likes
Message 4 of 9

BrianEkins
Mentor
Mentor

I believe your problem is the result of some unexpected behavior in Fusion. Notice that when you import your DXF file you don't see the control polygon of the curves. You're also not able to interactively move the endpoints of any of the curves. You can move the entire curve but you can't change the shape of the curve. The API is constrained by the same limitation and attempting to move the endpoints will not do anything.

 

There's an obscure command you can use in this case. With the sketch active, you can right-click on one of the curves and run the "Display Control Frame" command from the context menu. Now, the control frame will be displayed and the curve can be edited. The API is currently missing the ability to turn on the control frame. Some support for control point curves was recently added to the API, but this is still missing.

 

I tried to work around the current limitations by executing the equivalent commands but for some reason, it's not working as I would have expected. I think you might have to wait for the ability to turn on the control frame to be added to the API.

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

Jorge_Jaramillo
Collaborator
Collaborator

Hi,

 

As for Fusion360 version 2.0.14106, ControlPoints could be obtained from  SketchContolPointSpline.geometry.getData().

On Python, look for second returned value.

On C++ are returned on the first argument.

 

I hope Fusion360 team could clarify the usage of the controlPoints property.

 

Regards,
Jorge

Message 6 of 9

jiri.manak
Contributor
Contributor

thanks for your further investigation and responses

for now, the best solution, respective workaround is to replace the Nurbs3D curve

as @Jorge_Jaramillo which I accepted in the original post

 

 

0 Likes
Message 7 of 9

BrianEkins
Mentor
Mentor

@Jorge_Jaramillo, What you're seeing is because Python does not support returning passing an argument by reference where if it is modified in the function, the modified value will be returned. Instead, you need to return the information as the return value. The return value doesn't have to be a single value but can be multiple values in a tuple.

 

An example in the Fusion API is the Cylinder.getData function. Below is how it is defined internally. It returns the origin, axis, and radius through output arguments. It also has a bool return value to indicate if the call was successful or not.

 

bool getData(out Point3D origin, out Vector3D axis, out double radius);

 

Since C++ supports by-reference arguments, this function is essentially the same in the public C++ API.

Ptr<Point3D> origin;
Ptr<Vector3D> axis;
double radius;
boolean returnValue = cylinder_var->getData(origin, axis, radius);

 

To work around the Python limitation, the output arguments are combined with the return value and returned as a tuple. It's the same 4 values as returned above but all as the single return.

 

(returnValue, origin, axis, radius) = cylinder_var.getData()

 

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

Jorge_Jaramillo
Collaborator
Collaborator

Hi @BrianEkins ,

I agree with you.  What I wrote in the first three lines in my post is what you explain with details in your post.

 

My complain about "I hope Fusion360 team could clarify the usage of the controlPoints property." is based on the fact that the reference to SketchControlPointSpline.controlPoints always returns an error.

 

Regards,
Jorge

Message 9 of 9

BrianEkins
Mentor
Mentor

The current API doesn't take into account that there is a case when a spline is imported that the control points are not available. You see this in the UI and there's a command to turn them on. This is the case where the API is failing. The API should probably be returning None in this case and provide a way to turn the control points on, so you do have access to them. These control points are the points visible in the UI and editable by the user. Of course, internally the spline geometry has control points and if someone only cares about their position, they can be obtained using the function you already pointed out: SketchContolPointSpline.geometry.getData() 

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