Community
Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Nurbs surfaces in Fusion using the API

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
jean-marc_langlois
750 Views, 5 Replies

Nurbs surfaces in Fusion using the API

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.

 

5 REPLIES 5
Message 2 of 6

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

Message 3 of 6

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.

 

Message 4 of 6

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.

 

Message 5 of 6

@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

Many thanks @kandennti 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report