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: 

Using a TemporaryBRepManager.copy in a combine operation fails

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
florian.pommereningDGUYA
336 Views, 5 Replies

Using a TemporaryBRepManager.copy in a combine operation fails

In a script want to use a temporary BRepBody for cutting. This works fine if the temporary body was created with something like createCylinderOrCone but fails when the body is created with the copy function of TemporaryBRepManager. For some reason the base feature adding the temporary object to the document contains no bodies in case of using the copy, Although the copied body shows up in the document afterwards.

 

The following script shows the problem. If I comment in line 37, the script breaks.

 

import adsk.core, adsk.fusion, adsk.cam, traceback
import math
 
def createCylinder(x, y, r, h):
    app = adsk.core.Application.get()
    des = adsk.fusion.Design.cast(app.activeProduct)
    root = des.rootComponent
    sk = root.sketches.add(root.xYConstructionPlane)
    circs = sk.sketchCurves.sketchCircles
    circs.addByCenterRadius(adsk.core.Point3D.create(x,y,0), r)
    prof = sk.profiles.item(0)
    ext = root.features.extrudeFeatures.addSimple(
        prof, adsk.core.ValueInput.createByReal(h), 
        adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
    return ext.bodies.item(0)


def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface
        des = adsk.fusion.Design.cast(app.activeProduct)
        root = des.rootComponent

        c1 = createCylinder(0, 0, 2, 5)
        c2 = createCylinder(1, 1, 2, 3)
        c2.isLightBulbOn = False

        tempBRep = adsk.fusion.TemporaryBRepManager.get()

        # Works
        tempToolBody = tempBRep.createCylinderOrCone(
            adsk.core.Point3D.create(1, 1, 0), 2,
            adsk.core.Point3D.create(1, 1, 3), 2)
        # Fails with "RuntimeError: 3 : Bad index parameter" in the line below that uses baseFeat.bodies.item(0)
#        tempToolBody = tempBRep.copy(c2)

        baseFeat = root.features.baseFeatures.add()
        baseFeat.startEdit()
        toolBody = root.bRepBodies.add(tempToolBody, baseFeat)
        baseFeat.finishEdit()
        
        toolBodies = adsk.core.ObjectCollection.create()
        toolBodies.add(baseFeat.bodies.item(0))
        combineInput = root.features.combineFeatures.createInput(c1, toolBodies)
        combineInput.operation = adsk.fusion.FeatureOperations.CutFeatureOperation
        root.features.combineFeatures.add(combineInput)
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

 

5 REPLIES 5
Message 2 of 6

Hi @florian.pommereningDGUYA .

 

I also tried.

No error occurred in direct mode.

In parametric mode, no error occurred if tempBRep.booleanOperation.

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface
        des = adsk.fusion.Design.cast(app.activeProduct)
        root = des.rootComponent

        c1 = createCylinder(0, 0, 2, 5)
        c2 = createCylinder(1, 1, 2, 3)
        # c2.isLightBulbOn = False

        tempBRep = adsk.fusion.TemporaryBRepManager.get()

        # Works
        tempToolBody = tempBRep.createCylinderOrCone(
            adsk.core.Point3D.create(1, 1, 0), 2,
            adsk.core.Point3D.create(1, 1, 3), 2)
        # Fails with "RuntimeError: 3 : Bad index parameter" in the line below that uses baseFeat.bodies.item(0)
        tempToolBody = tempBRep.copy(c2)

        baseFeat = root.features.baseFeatures.add()
        baseFeat.startEdit()

        clone_c1 = tempBRep.copy(c1)
        cutOpe = adsk.fusion.BooleanTypes.DifferenceBooleanType
        tempBRep.booleanOperation(clone_c1, tempToolBody, cutOpe)
        root.bRepBodies.add(clone_c1, baseFeat)
        
        baseFeat.finishEdit()
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

 

I feel that BRepBody created by tempBRep.copy can only be used in direct mode or while editing the base future.

 

Message 3 of 6

I looked at this and can reproduce the problem.  There's a problem if the temporary B-Rep body is a copy of a parametric body then the base feature isn't correctly returning the body that's created in it.  This is a bug.  It should behave the same for a copied body or a newly created body.

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

Thanks. I worked around the problem in a similar way, keeping the copied body temporary until the end of the operation. This works for me but in general is only side-stepping the issue.

Message 5 of 6

Thanks for the confirmation. Is there an issue tracker where I should report this as a bug?

Message 6 of 6
kandennti
in reply to: BrianEkins

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