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: 

Combine cut script problem

1 REPLY 1
Reply
Message 1 of 2
brad.bylls
209 Views, 1 Reply

Combine cut script problem

I am creating an add-in and am having a problem with this script.

I don't find any examples for this and I am floundering on how to get it done.

What I want is for the user to pick multiple target bodies and multiple tool bodies.

When the user clicks 'Create the Cuts' that is what is supposed to happen (multiple cuts)

When using the Fusion command, you are only allowed 1 target body and for what I am working on that takes too long.

Being fairly new to the API and the documentation, I am floundering.

Can someone please help.

    def on_execute(self, command, inputs, args, input_values):

        x = 0
        y = 0

        target_input = inputs.itemById('target')
        targets = target_input.selectionFilters
        tool_input = inputs.itemById('tool')
        tools = tool_input.selectionFilters
        toolBodies = adsk.core.ObjectCollection.create()

        for target in targets:
            targetBody = adsk.fusion.BRepBodies.add(target_input, target)
            for tool in tools:
                toolBody = adsk.fusion.BRepBodies.add(tool_input, tool)
                toolBodies.add(toolBody)
                y = y + 1

        CombineCutInput = root.features.combineFeatures.createInput(targetBody, toolBodies )
        CombineCutFeats = features.combineFeatures
        CombineCutInput = CombineCutFeats.createInput(targetBody, toolBodies)
        CombineCutInput.operation = adsk.fusion.FeatureOperations.CutFeatureOperation
        CombineCutFeats.add(CombineCutInput)
        x = x + 1
        toolBodies.clear()
        targetBody.clear()

    def on_create(self, command, inputs):
                
        product = _app.activeProduct
        des = adsk.fusion.Design.cast(product)

        # Verify that a Fusion design is active.
        if not des:
            _ui.messageBox('A Fusion design must be active when invoking this command.')
            return()

        command.okButtonText = ("Make the Cuts") # text in "OK" button
        command.isExecutedWhenPreEmpted = False

        app = adsk.core.Application.get()
        ui = app.userInterface
        design = app.activeProduct
        rootComp = design.rootComponent
        sketches = rootComp.sketches
        planes = rootComp.constructionPlanes
        planeInput = planes.createInput()

        # Create the command dialog
        _inputSelectTargets = inputs.addSelectionInput('target', 'Select Target Bodies', 'Select the Bodies\nThat Will Be Cut')
        _inputSelectTargets.addSelectionFilter(adsk.core.SelectionCommandInput.Bodies)
        _inputSelectTargets.setSelectionLimits(0)

        _inputSelectTools = inputs.addSelectionInput('tool', 'Select Tool Bodies', 'Select the Bodies\nThat Will Do The Cutting')
        _inputSelectTools.addSelectionFilter(adsk.core.SelectionCommandInput.Bodies)
        _inputSelectTools.setSelectionLimits(0)

        _inputErrMessage = inputs.addTextBoxCommandInput('errMessage', '', '', 2, True)
        _inputErrMessage.isFullWidth = True

 

Brad Bylls
Tags (2)
1 REPLY 1
Message 2 of 2
brad.bylls
in reply to: brad.bylls

Working it out.

Changed some code.

I verified that target_input =3

I verified that tool_input =2

        target_input = inputs.itemById('target').selectionCount
        tool_input = inputs.itemById('tool').selectionCount
        toolBodies = adsk.core.ObjectCollection.create()

        for x in range (0, target_input):
            target = inputs.itemById('target').selection(x).entity
            toolBodies.clear()
            for y in range (0, tool_input):
                toolBody = inputs.itemById('tool').selection(y).entity
                toolBodies.add(toolBody)

            CombineCutInput = root.features.combineFeatures.createInput(target, toolBodies)
            CombineCutFeats = features.combineFeatures
            CombineCutInput = CombineCutFeats.createInput(target, toolBodies)
            CombineCutInput.operation = adsk.fusion.FeatureOperations.CutFeatureOperation
            CombineCutInput.isKeepToolBodies = True
            CombineCutFeats.add(CombineCutInput)

It runs through the first 'for x in range (0, target_input)' and 'for y in range (0, tool_input) without a problem.

It makes two combine/cuts in the first target. As it should.

But when it gets to 'toolBody = inputs.itemById('tool').selection(y).entity' the second 'x' time, (this is line 41) I get this error message:

bradbylls_0-1627324007259.png

As far as I can tell the index is the same as the first time through.

Any help appreciated.

Brad Bylls

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

Post to forums  

Technology Administrators