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: 

Consistent boundaryFillInput.bRepCells.item

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
Anonymous
297 Views, 2 Replies

Consistent boundaryFillInput.bRepCells.item

I'm hitting an issue where the bRepCells.item on a BoundaryFill aren't consistently the same array index. The 2 Bodies used are a rectangular box and then a doing an Intersect with a cylinder to produce a rounded top. The intersect produces 3 items, but there doesn't appear to be a way to guarantee that the item index is the right one. It also appears dependent on the order of the adsk.core.ObjectCollection.create.add operations. Is there a way to consistently get the correct item?

 

code snippet:

    circles = sketch.sketchCurves.sketchCircles
    circle1 = circles.addByCenterRadius(adsk.core.Point3D.create(center, 0, 0), radius)

    prof = sketch.profiles.item(0)
    distance = adsk.core.ValueInput.createByReal(length)
    extrude1 = extrudes.addSimple(prof, distance, adsk.fusion.FeatureOperations.NewBodyFeatureOperation)

    # BoundaryFill intersect to radius the board
    tools = adsk.core.ObjectCollection.create()
    tools.add(rootComp.bRepBodies.item(0))
    tools.add(rootComp.bRepBodies.item(1))

    # Create input
    boundaryFillInput = boundaryFills.createInput(tools, adsk.fusion.FeatureOperations.IntersectFeatureOperation)

    # Specify which cell is kept
    print(boundaryFillInput.bRepCells.item(1).this)
    cell = boundaryFillInput.bRepCells.item(1)
    cell.isSelected = True

    # Create the boundary fill
    boundaryFills.add(boundaryFillInput)

Thanks,

Jesse

2 REPLIES 2
Message 2 of 3
Anonymous
in reply to: Anonymous

I kludged around it by selecting the cellBody that's within 10% volume of the original board body.

 

 

    board_body = rootComp.bRepBodies.itemByName(board_body_name)
    board_vol = board_body.volume
    print("BOARD_BODY: ", board_body.volume)

    # Specify which cell is kept
    for x in range(0, boundaryFillInput.bRepCells.count):
        cell = boundaryFillInput.bRepCells.item(x)
        cell_vol = cell.cellBody.volume
        orig_percent = (cell_vol / board_vol) * 100
        print("Cell{0}: {1}\t{2} %".format(x, cell_vol, orig_percent))
        if 90 <= orig_percent <= 100:
            cell.isSelected = True
            break

 

Message 3 of 3
ekinsb
in reply to: Anonymous

I think something like you've done is the correct answer and not just a workaround.  The order of the results shouldn't be relied upon.  You might find something consistent by controlling the order of the inputs but there's no guarantee that it would remain the same in future versions of Fusion 360.

 

The solution is to look for something in the results that will identify the body you want.  It could be the volume like you've done but it could also be volumes that have certain shapes, a certain number of faces, or are located in a specific area of the model.  It would differ with each specific case.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog

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