Nurbs surfaces in Fusion using the API

Nurbs surfaces in Fusion using the API

jean-marc_langlois
Contributor Contributor
1,975 Views
5 Replies
Message 1 of 6

Nurbs surfaces in Fusion using the API

jean-marc_langlois
Contributor
Contributor

Hi,

I'm very new to Fusion 360, and I am currently looking into the API to see whether or not we can have some sort of integration between our own 3d modeling software and Fusion, mostly for reverse engineering purposes.

I've been looking around in the API, samples, etc. for a way to add a Nurbs surface in the active design, without any success so far. I've found a way to do just that for a nurbs curve (using the "addByNurbsCurve" method in sketchFixedSplines or sketchFittedSplines classes, but couldn't find a similar "addByNurbsSurface"  method.

I also stumbled across the transient NurbsSurface class, but once an instance is created, what can we do with it ?

 

Thanks in advance for any comments.

 

0 Likes
Accepted solutions (1)
1,976 Views
5 Replies
Replies (5)
Message 2 of 6

kandennti
Mentor
Mentor

Hi @jean-marc_langlois .

 

The NurbsSurface.create method is used in this sample.

https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-ca29fec6-6d94-49bb-b4cd-de77c782011a 

 

Since it is difficult for me to understand, I would consider using a Feature such as Sweep, Loft, Patch, etc.

https://help.autodesk.com/view/fusion360/ENU/?guid=SampleList 

1.png

0 Likes
Message 3 of 6

jean-marc_langlois
Contributor
Contributor

Thanks for the reply.

It got me in the right direction, but there still is a lot I don't really understand...

For testing purposes, I imported a STP file that contains a single Nurbs surface (see attached image), and I ended up with this:

1) A body in the rootComponent.bRepBodies collection
2) The body has a single lump / shell
3) The shell / lump has a single face, whose geometry is an adsk.core.NurbsSurface instance
4) The face's single loop has 4 edges, whose geometries are all adsk.core.NurbsCurve3D instances

All of this is as I expected, although I suspect it will a little bit painful to reproduce this programmatically.

What I would really like to get my hands on is a complete example of how to achieve the same result programmatically, given all the required Nurbs surface info (control points, U and V control point count, U and V degress, etc.).

In the suggested example ( https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-ca29fec6-6d94-49bb-b4cd-de77c782011a ), we're almost there, but the temporary NurbsSurface / resulting body is added to the customGraphicsGroups, which is not what I want ultimately.

How can that body be added to the rootComponent bRepBodies collection ? I tried to use the bRepBodies.add method but that didn't work, and quite frankly I don't really understand what is missing for this to be working.

Thanks for any advice.

 

0 Likes
Message 4 of 6

jean-marc_langlois
Contributor
Contributor

I just noticed I replied to myself, so here I go again.. 🙂

 

Thanks for the reply.

I got me in the right direction, but there still is a lot I don't really understand.

For testing purposes, I imported a STP file that contains a single Nurbs surface (see attached image), and I ended up with this:

1) A body in the rootComponent.bRepBodies collection
2) Te body has a single lump / shell
3) The shell / lump has a single face, whose geometry is an adsk.core.NurbsSurface instance
4) The face's single loop has 4 edges, whose geometries are all adsk.core.NurbsCurve3D instances

All of this is as I expected, although I suspect it will a little bit painful to reproduce this programmtically.

But what I would like to find is a complete example of how to achieve the same result programmatically, given all the required Nrbs surface info (control points, U and V control point count, U and V degress, etc.).

In the suggested example ( https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-ca29fec6-6d94-49bb-b4cd-de77c782011a ), we're almost there, but the temporary NurbsSurface / resulting body is added to the customGraphicsGroups, which is not what I want ultimately.

How can that body be added to the rootComponent bRepBodies collection ? I tried to use th bRepBodies.add method but that didn't work, and quite frankly I don't really understand what is missing for this to be working.

Thansk for any advice.

 

0 Likes
Message 5 of 6

kandennti
Mentor
Mentor
Accepted solution

@jean-marc_langlois .

 

Use BaseFeature for temporary brep bodies solids and surfaces and sketch for wire brep bodies.

https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-GUID-73BE9780-D085-42BB-85BD-92375C2DC8E3 

 

If you change the following near the end of the sample, you will get the result you want.

・・・
        # # Show the temporary brep bodies
        # group = rootComp.customGraphicsGroups.add()
        # group.addBRepBody(body)
        
        # for edge in wireBrepBody.edges:
        #     group.addCurve(edge.geometry)

        # temporary brep bodies to solid or surface
        baseFeat: adsk.fusion.BaseFeature = None
        if design.designType == adsk.fusion.DesignTypes.ParametricDesignType:
            baseFeat = rootComp.features.baseFeatures.add()

        bodies: adsk.fusion.BRepBodies = rootComp.bRepBodies

        if baseFeat:
            # Parametric Design
            baseFeat.startEdit()
            try:
                bodies.add(body, baseFeat)
            except:
                pass
            finally:
                baseFeat.finishEdit()
        else:
            # Direct Design
            bodies.add(body)

        # wire brep bodies to sketch curves
        skt: adsk.fusion.Sketch = rootComp.sketches.add(
            rootComp.xYConstructionPlane
        )
        sktCrvs: adsk.fusion.SketchCurves = skt.sketchCurves
        for edge in wireBrepBody.edges:
            geo = edge.geometry
            if hasattr(geo, 'asNurbsCurve'):
                nurbs = geo.asNurbsCurve
            else:
                nurbs = geo

            sktCrvs.sketchFixedSplines.addByNurbsCurve(nurbs)

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
Message 6 of 6

jean-marc_langlois
Contributor
Contributor

Many thanks @kandennti