Example #1
0
def run(context):
    global ui
    try:

        app = Application.get()
        des = Design.cast(app.activeProduct)
        ui = app.userInterface

        log('--------------------------------')
        log(dt.datetime.now(), __file__)
        log()

        root = Component.cast(des.rootComponent)

        # locate the spars sketch & wing body
        sketch = item_by_name(root.sketches, settings.SPARS_SKETCH)
        wing_body = item_by_name(root.bRepBodies, settings.WING_BODY)

        # create new component
        component_occurrence = root.occurrences.addNewComponent(
            Matrix3D.create())
        component = Component.cast(component_occurrence.component)
        component.name = settings.SPARS_COMPONENT_NAME

        # now create the spars, one for each line on the sketch.
        lines = sketch.sketchCurves.sketchLines
        log('num lines:', lines.count)
        for i, line in enumerate(lines):
            spar = create_spar_from_line(component, component_occurrence,
                                         wing_body, sketch, line,
                                         settings.SPAR_THICKNESS_CM)
            spar.name = "spar_{}".format(i + 1)
            log('Created spar', spar.name)

        ui.messageBox('done')

    except Exception as ex:
        msg = 'Failed:\n{}'.format(traceback.format_exc())
        log(msg)
        if ui:
            ui.messageBox(str(ex))
Example #2
0
from adsk.core import Application
app = Application.get()
ui = app.userInterface


def axis_dir(vector):
    # ui.messageBox('Axis Vector: {} {} {}'.format(vector.x, vector.y, vector.z))
    if vector.z:
        return 'z'
    if vector.y:
        return 'y'
    return 'x'
Example #3
0
def run(context):
    global ui
    try:
        log('--------------------------------')
        log(dt.datetime.now(), __file__)
        log()
        app = Application.get()
        des = Design.cast(app.activeProduct)
        ui = app.userInterface
        root = Component.cast(des.rootComponent)

        # locate the root and tip sketches
        rootSketch = root.sketches.itemByName(ROOT_SKETCH)
        if rootSketch is None:
            raise ValueError('Root sketch "{}" not found'.format(ROOT_SKETCH))

        tipSketch = root.sketches.itemByName(TIP_SKETCH)
        if tipSketch is None:
            raise ValueError('Tip sketch "{}" not found'.format(TIP_SKETCH))

        # locate the wing body
        wingBody = root.bRepBodies.itemByName(WING_BODY)
        if wingBody is None:
            raise ValueError('Wing body "{}" not found'.format(WING_BODY))

        # create new component = 'ribs'
        ribsOcc = root.occurrences.addNewComponent(Matrix3D.create())
        ribs = Component.cast(ribsOcc.component)
        ribs.name = 'ribs'

        def create_rib(dist_from_root, thickness):
            rootPlane = rootSketch.referencePlane
            tipPlane = tipSketch.referencePlane

            # Create 2 construction planes:
            #   1) offset from root sketch plane
            #   2) offset from the first
            planes = ribs.constructionPlanes

            plane1Input = planes.createInput()
            plane1Input.setByOffset(rootPlane,
                                    ValueInput.createByString(dist_from_root))
            plane1 = planes.add(plane1Input)

            plane2Input = planes.createInput()
            plane2Input.setByOffset(plane1,
                                    ValueInput.createByString(thickness))
            plane2 = planes.add(plane2Input)

            # Create rib as using boundary fill, between the 2 construction planes, and the wing body
            boundaryFills = ribs.features.boundaryFillFeatures
            tools = ObjectCollection.create()
            tools.add(wingBody)
            tools.add(plane1)
            tools.add(plane2)

            boundaryFillInput = boundaryFills.createInput(
                tools, FeatureOperations.NewBodyFeatureOperation)
            try:

                # Boundary fill will be created in sub component
                boundaryFillInput.creationOccurrence = ribsOcc

                # Specify which cell is kept
                assert boundaryFillInput.bRepCells.count == 3, "expected 3 cells"

                # volumes = [cell.cellBody.volume for cell in boundaryFillInput.bRepCells]
                # log('Volumes: {}'.format(volumes))

                cell = cell_in_the_middle(boundaryFillInput.bRepCells)
                cell.isSelected = True

                # Create the boundary fill, based on the input data object
                boundaryFills.add(boundaryFillInput)
            except:
                # rollback the boundary fill transaction
                boundaryFillInput.cancel()
                raise
            # end of create_rib
            # ----------------------------------

        # now create the ribs
        for rs in RIB_STATIONS:
            create_rib('{} mm'.format(rs), RIB_THICKNESS)

    except:
        msg = 'Failed:\n{}'.format(traceback.format_exc())
        log(msg)
        if ui:
            ui.messageBox(msg)