Built-in circular pattern - Fusion crashes during exporting component to STL or copying an pasting

Built-in circular pattern - Fusion crashes during exporting component to STL or copying an pasting

marcinszydlowski.1984
Enthusiast Enthusiast
690 Views
2 Replies
Message 1 of 3

Built-in circular pattern - Fusion crashes during exporting component to STL or copying an pasting

marcinszydlowski.1984
Enthusiast
Enthusiast

Hello,

 

during attempt of exporting to STL or copying and pasting a component which contains bodies created by built-in circular pattern feature there's a Fusion crash:

 

STL Crash.png

 

I checked three approaches for comparison results and it shows that when bodies are created manually or merged into the single body problem doesn't exist. Here's the script:

 

 

import math
import adsk.core, adsk.fusion

def testOfBuiltInCircularPattern(rootComp: adsk.fusion.Component):
    # Create a new component
    circularOccurrence = rootComp.occurrences.addNewComponent(adsk.core.Matrix3D.create())
    circularComponent = circularOccurrence.component
    circularComponent.name = "cannot export to STL or copy/past"

    # Create a base feature corresponding to it
    circBaseFeat = adsk.fusion.BaseFeature.cast(circularComponent.features.baseFeatures.add())
    circBaseFeat.name = "circular pattern feature"
    circBaseFeat.startEdit()

    # Create a sample body
    bottomCntr = adsk.core.Point3D.create(5, 0, 0)
    topCntr = adsk.core.Point3D.create(5, 0, 2)
    tempCyl = adsk.fusion.TemporaryBRepManager.get().createCylinderOrCone(bottomCntr, 0.5, topCntr, 0.5)
    cyl = circularComponent.bRepBodies.add(tempCyl, circBaseFeat)

    # Circular pattern
    circFeatures = circularComponent.features.circularPatternFeatures
    objects = adsk.core.ObjectCollection.create()
    objects.add(cyl)
    circPattInput = circularComponent.features.circularPatternFeatures.createInput(objects, circularComponent.zConstructionAxis)
    circPattInput.targetBaseFeature = circBaseFeat
    circPattInput.quantity = adsk.core.ValueInput.createByReal(5)
    circPattern = circFeatures.add(circPattInput)

    circBaseFeat.finishEdit()

def testOfBuiltInCircularPatternMerged(rootComp: adsk.fusion.Component):
    # Create a new component
    circularOccurrence = rootComp.occurrences.addNewComponent(adsk.core.Matrix3D.create())
    circularComponent = circularOccurrence.component
    circularComponent.name = "ok (merged)"

    # Create a base feature corresponding to it
    circBaseFeat = adsk.fusion.BaseFeature.cast(circularComponent.features.baseFeatures.add())
    circBaseFeat.name = "circular pattern feature"
    circBaseFeat.startEdit()

    # Create a sample body
    bottomCntr = adsk.core.Point3D.create(5, 0, 0)
    topCntr = adsk.core.Point3D.create(5, 0, 2)
    tempCyl = adsk.fusion.TemporaryBRepManager.get().createCylinderOrCone(bottomCntr, 0.5, topCntr, 0.5)
    cyl = circularComponent.bRepBodies.add(tempCyl, circBaseFeat)

    # Circular pattern
    circFeatures = circularComponent.features.circularPatternFeatures
    objects = adsk.core.ObjectCollection.create()
    objects.add(cyl)
    circPattInput = circularComponent.features.circularPatternFeatures.createInput(objects, circularComponent.zConstructionAxis)
    circPattInput.targetBaseFeature = circBaseFeat
    circPattInput.quantity = adsk.core.ValueInput.createByReal(5)
    circPattern = circFeatures.add(circPattInput)

    # Create a plate at the back
    plateBottomCtr = adsk.core.Point3D.create(0, 0, -0.5)
    tempPlate = adsk.fusion.TemporaryBRepManager.get().createCylinderOrCone(plateBottomCtr, 6, circularComponent.originConstructionPoint.geometry, 6)
    plate = circularComponent.bRepBodies.add(tempPlate, circBaseFeat)
    plate.name = "plate"

    # Merge all cylinders with plate
    combines = circularComponent.features.combineFeatures
    objects = adsk.core.ObjectCollection.create()

    for icb in circPattern.bodies:
        objects.add(icb)

    combineInput = combines.createInput(plate, objects)
    combineInput.isNewComponent = False
    combineInput.operation = adsk.fusion.FeatureOperations.JoinFeatureOperation
    combineInput.isKeepToolBodies = False
    combineInput.targetBaseFeature = circBaseFeat
    combineResult = combines.add(combineInput)

    circBaseFeat.finishEdit()

def testOfManualCircularPattern(rootComp: adsk.fusion.Component):
    # Create a new component
    circularOccurrence = rootComp.occurrences.addNewComponent(adsk.core.Matrix3D.create())
    circularComponent = circularOccurrence.component
    circularComponent.name = "ok (pattern manually)"

    # Create a base feature corresponding to it
    circBaseFeat = adsk.fusion.BaseFeature.cast(circularComponent.features.baseFeatures.add())
    circBaseFeat.name = "circular pattern feature"
    circBaseFeat.startEdit()

    # Circular pattern by creating bodies manually in loop
    qty = 5
    for ic in range(qty):
        angle = 2 * math.pi / qty * ic
        matrix = adsk.core.Matrix3D.create()
        matrix.setToRotation(angle, circularComponent.zConstructionAxis.geometry.direction, circularComponent.originConstructionPoint.geometry)
        bottomCntr = adsk.core.Point3D.create(5, 0, 0)
        bottomCntr.transformBy(matrix)
        topCntr = adsk.core.Point3D.create(5, 0, 2)
        topCntr.transformBy(matrix)
        tempCyl = adsk.fusion.TemporaryBRepManager.get().createCylinderOrCone(bottomCntr, 0.5, topCntr, 0.5)
        cyl = circularComponent.bRepBodies.add(tempCyl, circBaseFeat)

    circBaseFeat.finishEdit()

def run(context):
    app = adsk.core.Application.get()
    product = app.activeProduct
    design = adsk.fusion.Design.cast(product)
    rootComp = design.rootComponent

    # Example 1 - error (only built-in pattern) - component created in this way causes hangs and crashes during export to STL or pasting to the existing or new document
    testOfBuiltInCircularPattern(rootComp)

    # Example 2 - no errors with component (built-in pattern but later merged with another body)
    testOfBuiltInCircularPatternMerged(rootComp)

    # Example 3 - no errors with component (pattern manually by creating many bodies)
    testOfManualCircularPattern(rootComp)

 

 

Is there a better solution than creating bodies manually?

0 Likes
Accepted solutions (1)
691 Views
2 Replies
Replies (2)
Message 2 of 3

kandennti
Mentor
Mentor
Accepted solution

Hi @marcinszydlowski.1984 .

 

I tried it, and it reproduced the condition.

I don't know why the error occurs in the export.

 

After creating the cylinders, I quit editing BaseFeature once, and then went back to edit it again to make the patterns, and the error was avoided.

def testOfBuiltInCircularPattern(rootComp: adsk.fusion.Component):
    try:
        # Create a new component
・・・
        # Create a sample body
        bottomCntr = adsk.core.Point3D.create(5, 0, 0)
        topCntr = adsk.core.Point3D.create(5, 0, 2)
        tempCyl = adsk.fusion.TemporaryBRepManager.get().createCylinderOrCone(bottomCntr, 0.5, topCntr, 0.5)
        cyl = circularComponent.bRepBodies.add(tempCyl, circBaseFeat)

        # Finish editing once.
        circBaseFeat.finishEdit()

        # Restart editing.
        circBaseFeat.startEdit()

        # Circular pattern
        circFeatures = circularComponent.features.circularPatternFeatures
・・・
0 Likes
Message 3 of 3

marcinszydlowski.1984
Enthusiast
Enthusiast

Thank you very much @kandennti for the quick answer, it did the trick. I thought that closing transaction by baseFeat.finishEdit() ensures that operations inside the block are finished but it seems not every time. Good to know.