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: 

addExistingComponent weirdness

2 REPLIES 2
Reply
Message 1 of 3
innermatrix
267 Views, 2 Replies

addExistingComponent weirdness

I have some code that should create three rectangular solids (A, B, and C) , at (0, 0), (2, 1), and (2, -1), respectively. That's not what happens. The problem appears to be caused by the fact that B and C are copies of A that aren't at the same level of component hierarchy as A; if I create them as siblings the problem goes away. 

 

Here's the code:

from traceback import format_exc
from adsk.core import Application, DialogResults, Matrix3D, Matrix2D, Vector3D, Point3D, Point2D, ValueInput, ObjectCollection
from adsk.fusion import Design, FeatureOperations

def run(context):
    ui = None
    try:
        app = Application.get()
        ui = app.userInterface
        design = Design.cast(app.activeProduct)

        if not design:
            ui.messageBox('No active Fusion design', 'No Design')
            return

        # Create component #1
        modelBoard = design.activeComponent.occurrences.addNewComponent(Matrix3D.create()).component
        modelBoard.name = "Board"

        # Create component #2
        packageComponent = design.activeComponent.occurrences.addNewComponent(Matrix3D.create()).component

        # Create a sketch in component #2
        outline = packageComponent.sketches.add(packageComponent.xYConstructionPlane)

        lines = outline.sketchCurves.sketchLines
        for line in [(-2, -1, 2, -1), (2, -1, 2, 1), (2, 1, -2, 1), (-2, 1, -2, -1)]:
            (x1, y1, x2, y2) = line
            start = Point3D.create(float(x1), float(y1), 0)
            end = Point3D.create(float(x2), float(y2), 0)

            lines.addByTwoPoints(start, end)

        # Extrude sketch in component #2
        extrudes = packageComponent.features.extrudeFeatures
        extrudeParams = extrudes.createInput(outline.profiles.item(0), FeatureOperations.NewBodyFeatureOperation)
        extrudeParams.setDistanceExtent(False, ValueInput.createByReal(.25))
        extrudeParams.isSolid = True
        extrudes.add(extrudeParams)

        # Copy component #2 into component #1 twice
        for x, y in [(2, 1), (-2, 1)]:
            transform = Matrix3D.create()
            transform.translation = Vector3D.create(x, y, 0)

            packageOccurrence = modelBoard.occurrences.addExistingComponent(packageComponent, transform)

    except:
        if ui:
            print(format_exc())
            ui.messageBox('Failed:\n{}'.format(format_exc(4)))

Here's what happens: 

 

Weirdness!

 

Help / suggestions?

2 REPLIES 2
Message 2 of 3
ekinsb
in reply to: innermatrix

This appears to be a bug in the API.  I'm logging it so we can investigate some more and fix it.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 3 of 3
innermatrix
in reply to: ekinsb

Thanks!

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