Wacky wires

Wacky wires

GRSnyder
Collaborator Collaborator
622 Views
4 Replies
Message 1 of 5

Wacky wires

GRSnyder
Collaborator
Collaborator

I'm working on a CustomFeature add-in. I prototyped it with UI-level construction tools (sketches, sweeps, etc.), but now I'm trying to push the actual geometry creation down to the TemporaryBRepManager level. The CustomFeature parts are actually working great - it's the TBRM that's confusing me.

 

If I understand correctly, B-rep wires are essentially edges that are not bound to faces and have no face-level geometry. They should render normally in the UI, much like sketch geometry, should they not?

 

Here's a test script that gives problems for me:

 

 

import adsk.core as core
import adsk.fusion as fusion
import traceback

def run(context):
    try:
        app = core.Application.get()
        ui  = app.userInterface
        tbm = fusion.TemporaryBRepManager.get()
        pt1 = core.Point3D.create(0, 1, 0)
        pt2 = core.Point3D.create(0, 0, 0)
        pt3 = core.Point3D.create(1, 0, 0)
        nurb = core.NurbsCurve3D.createNonRational([pt1, pt2, pt3], 2, [0, 0, 0, 1, 1, 1], False)
        wireBody, _ = tbm.createWireFromCurves([nurb])
        comp = app.activeProduct.activeComponent
        base = comp.features.baseFeatures.add()
        base.startEdit()
        comp.bRepBodies.add(wireBody, base)
        base.finishEdit()

    except Exception as e:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

 

 

It creates a very simple NurbsCurve3D, converts it to a wire body, and inserts the body into a BaseFeature.
 
It runs fine, but the curve seen in the UI is a straight line from all angles, no curvature at all. I can understand that there might be a mismatch between the TBRM coordinate system and the coordinate system of a specific component, but there's no perspective from which the wire looks like a curve.
 
The curve is a new-to-the-UI degree two NURBS, but in the actual plugin the degrees are 3 and 5 and show the same effect. Also, they worked fine when placed into a Sketch rather than a wire body.
 
Attached is an .f3d file that shows a blank document after running this script. I added a sketch on the XY plane and projected in the wire (which is also on the XY plane). Surprisingly, the wire projects correctly, showing the expected curvature:
 
Screenshot 2023-02-13 at 7.02.03 PM.png

 

I usually try to keep questions specific, but I think my query in this case is "Whaaa?"

0 Likes
Accepted solutions (1)
623 Views
4 Replies
Replies (4)
Message 2 of 5

kandennti
Mentor
Mentor
Accepted solution

Hi @GRSnyder .

 

I don't know why, but BRepWire does not appear correctly on the screen.
If you want to see the correct geometry, the only way is to draw the geometry in a sketch.

 

However, the correct data is retained. The export function of the add-in published here is able to export BRepWire with Iges and Step. The information is retained correctly when checked with other CAD programs.

https://github.com/kantoku-code/Fusion360_Curve3D_Doorway 

Message 3 of 5

GRSnyder
Collaborator
Collaborator

@kandennti wrote: I don't know why, but BRepWire does not appear correctly on the screen.

If you want to see the correct geometry, the only way is to draw the geometry in a sketch.

How strange! This is exactly the information that I needed. Thanks!

Message 4 of 5

BrianEkins
Mentor
Mentor

I ran into this same issue while I was testing some custom feature functionality. What's happening is that the API is exposing more functionality than Fusion was designed to handle. Fusion doesn't use this functionality, so it was never expected to happen. It's even an edge case when using the API to create this type of geometry. I still consider it a bug, but it's probably a low priority because it's certainly not a typical workflow.

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

kandennti
Mentor
Mentor

@GRSnyder .

 

I think the only way is to check it like this.

 

・・・
        base.startEdit()
        comp.bRepBodies.add(wireBody, base)
        base.finishEdit()

        dump_wires(wireBody)

    except Exception as e:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))


def dump_wires(wireBody: fusion.BRepBody) -> None:

    geos = []
    for wire in wireBody.wires:
        for edge in wire.edges:
            geos.append(edge.geometry)

    if len(geos) < 1:
        return

    app: core.Application = core.Application.get()
    des: fusion.Design = app.activeProduct
    root: fusion.Component = des.rootComponent

    skt: fusion.Sketch = root.sketches.add(root.xYConstructionPlane)
    skt.name = 'dump_wires'

    sktFixeds: fusion.SketchFixedSplines = skt.sketchCurves.sketchFixedSplines
    for geo in geos:
        if hasattr(geo, 'asNurbsCurve'):
            geo = geo.asNurbsCurve

        sktFixeds.addByNurbsCurve(geo)