Ejemplo n.º 1
0
    def notify(self, args):
        design = adsk.fusion.Design.cast(_app.activeProduct)
        if not design:
            raise Exception("No active Fusion design")
        root = design.rootComponent

        args = adsk.core.CommandCreatedEventArgs.cast(args)
        cmd = args.command

        prog = _ui.createProgressDialog()
        prog.isCancelButtonShown = True

        try:
            ok = mk_export_dialog(cmd, root, prog)
        except:
            _ui.messageBox("Error:\n%s" % (traceback.format_exc(), ), "Error")
            ok = False

        if not ok:
            # causes a crash:
            # cmd.doExecute(True)
            adsk.terminate()
            return

        exe = ExecuteHandler(root)
        cmd.execute.add(exe)
        handlers.append(exe)

        cancel = CancelHandler()
        cmd.destroy.add(cancel)
        handlers.append(cancel)
Ejemplo n.º 2
0
 def notify(self):
     try:
         # when the command is done, terminate the script
         # this will release all globals which will remove all event handlers
         print("Terminating script")
         adsk.terminate()
     except:
         if ui:
             ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
Ejemplo n.º 3
0
    def notify(self, args):

        global _script_to_run
        print("in transaction.SampleCommandExecuteHandler")

        # Code to react to the event.
        _script_to_run()

        # Force the termination of the command.
        Adsk.terminate()
Ejemplo n.º 4
0
    def notify(self, args):
        #eventArgs = Core.CommandEventArgs.cast(args)

        # Code to react to the event.
        #app = adsk.core.Application.get()
        #des = adsk.fusion.Design.cast(app.activeProduct)

        ui = None
        try:
            app = Core.Application.get()
            ui = app.userInterface
            design = Fusion.Design.cast(app.activeProduct)

            if not design:
                raise internalScriptError('No active Fusion design')

            design.designType = Fusion.DesignTypes.ParametricDesignType

            # create a new occurence of a new component at origin
            newComp = design.rootComponent.occurrences.addNewComponent(
                Core.Matrix3D.create()).component

            #sketches = newComp.sketches
            # Create a new sketch on the xy plane.
            sketch = newComp.sketches.add(newComp.xYConstructionPlane, None)

            # Center point
            cp = Core.Point3D.create(0, 0, 0)

            # S2M Standard Parameters
            pitch = 0.2
            edgeRad = 0.019
            filletRad = 0.01
            invRad = 0.1325
            invOffsetX = 0.130 / 2
            invOffsetY = 0.0172

            pitchOffset = 0.0254
            baseOffset = 0.076

            # Pulley properties
            n = 20
            t = 0.6

            pd2 = (n * pitch / math.pi) / 2
            od2 = pd2 - pitchOffset
            bd2 = od2 - baseOffset

            newComp.name = "S2M v0 {}n".format(n)
            #
            # OD circle and pulley body
            sketch.sketchCurves.sketchCircles.addByCenterRadius(cp, od2)
            extrudes = newComp.features.extrudeFeatures
            extInput = extrudes.createInput(
                sketch.profiles.item(0),
                Fusion.FeatureOperations.NewBodyFeatureOperation)
            distance = Core.ValueInput.createByReal(t)
            extInput.setDistanceExtent(False, distance)
            od_cyl = extrudes.add(extInput)

            # BD and PD circles
            sketch.sketchCurves.sketchCircles.addByCenterRadius(cp, bd2)
            p_circ = sketch.sketchCurves.sketchCircles.addByCenterRadius(
                cp, pd2)
            p_circ.isConstruction = True

            # "Involutes"
            invOffset = Core.Point3D.create(-invOffsetX, invOffsetY + od2, 0)
            sketch.sketchCurves.sketchCircles.addByCenterRadius(
                invOffset, invRad)
            invOffset = Core.Point3D.create(invOffsetX, invOffsetY + od2, 0)
            sketch.sketchCurves.sketchCircles.addByCenterRadius(
                invOffset, invRad)

            # Get the profile of the involute circles cut
            prof = None
            for pro in sketch.profiles:
                p_c_y = pro.areaProperties().centroid.y
                p_c_x = pro.areaProperties().centroid.x
                if (p_c_y > bd2) and (p_c_y < od2) and (math.fabs(p_c_x) <
                                                        0.0001):
                    prof = pro

            # Create an extrusion input
            extInput = extrudes.createInput(
                prof, Fusion.FeatureOperations.NewBodyFeatureOperation)
            distance = Core.ValueInput.createByReal(t)
            extInput.setDistanceExtent(False, distance)

            # Create the extrusion.
            toothCutter = extrudes.add(extInput)

            # Add base fillets to cutter
            fillets = newComp.features.filletFeatures
            collection = Core.ObjectCollection.create()

            # Get the straight edges closest to center
            for face in toothCutter.sideFaces:
                for edge in face.edges:
                    if (edge.geometry.curveType ==
                            Core.Curve3DTypes.Line3DCurveType):
                        if (edge.pointOnEdge.y < (od2 + bd2) / 2):
                            collection.add(edge)

            filletInput = fillets.createInput()
            filletInput.addConstantRadiusEdgeSet(
                collection, Core.ValueInput.createByReal(filletRad), True)
            filletInput.isG2 = False
            filletInput.isRollingBallCorner = False
            fillets.add(filletInput)

            # Circular pattern for each teeth
            collection.clear()
            collection.add(toothCutter.bodies.item(0))

            # Create the input for circular pattern
            circularFeats = newComp.features.circularPatternFeatures
            circularFeatInput = circularFeats.createInput(
                collection, newComp.zConstructionAxis)
            circularFeatInput.quantity = Core.ValueInput.createByReal(n)
            circularFeatInput.totalAngle = Core.ValueInput.createByString(
                '360 deg')
            circularFeatInput.isSymmetric = False

            # Create the circular pattern
            teeth = circularFeats.add(circularFeatInput)

            # Cut the base cylinder with the teeth
            collection.clear()
            collection.add(toothCutter.bodies.item(0))

            for th in teeth.bodies:
                collection.add(th)

            comb = newComp.features.combineFeatures
            combInput = comb.createInput(od_cyl.bodies.item(0), collection)
            combInput.operation = Fusion.FeatureOperations.CutFeatureOperation

            # Combine
            pulley = comb.add(combInput)

            # Add edge fillets to pulley
            collection.clear()

            # Get the straight edges fartest from center
            for face in pulley.faces:
                for edge in face.edges:
                    if (edge.geometry.curveType ==
                            Core.Curve3DTypes.Line3DCurveType):
                        if (len2D(edge.pointOnEdge) > ((od2 + bd2) / 2)):
                            collection.add(edge)

            filletInput.addConstantRadiusEdgeSet(
                collection, Core.ValueInput.createByReal(edgeRad), True)
            fillets.add(filletInput)

        except internalScriptError as ise:
            if ui:
                ui.messageBox(ise, "Internal Script Error")
            else:
                print("Internal Script Error" + ise)
        except:
            if ui:
                ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
            else:
                print('Failed:\n{}'.format(traceback.format_exc()))

        # Force the termination of the command.
        Adsk.terminate()
Ejemplo n.º 5
0
 def notify(self, args):
     adsk.terminate()
Ejemplo n.º 6
0
    def _notify(self, args):
        design = adsk.fusion.Design.cast(_app.activeProduct)
        if not design:
            raise Exception("No active Fusion design")
        root = design.rootComponent

        args = adsk.core.CommandEventArgs.cast(args)
        inputs = args.command.commandInputs
        table = inputs.itemById(_TABLE_ID)  # type: core.TableCommandInput

        if any(
                table.getInputAtPosition(row, COL.INCLUDE).value
                for row in range(1, table.rowCount)):
            d = _ui.createFileDialog()
            d.isMultiSelectEnabled = False
            d.title = "Select output directory"
            d.filter = "Drawing Exchange Format (*.dxf)"
            d.filterIndex = 0
            rs = d.showSave()
            if rs == adsk.core.DialogResults.DialogOK:
                filename = d.filename
            else:
                return

            # yeah f**k "not overwriting built-ins" when they're stupid...
            dir = filename.rsplit(os.path.sep, 1)[0]

        else:
            dir = None

        _bodies = self.root.bRepBodies
        bodies = {}
        for i in range(_bodies.count):
            body = _bodies.item(i)
            bodies[body.name] = body

        keep = set()
        prog = _ui.createProgressDialog()
        prog.show("Generating DXF files...", "%v/%m (%p%) complete", 0,
                  table.rowCount - 1, 0)

        for row in range(1, table.rowCount):
            face_id = table.getInputAtPosition(row, COL.FACE_ID).value
            body_name, temp_id = split_face_id(face_id)
            keep.add((body_name, temp_id))
            body = bodies[body_name]
            faces = body.findByTempId(temp_id)
            assert len(faces) == 1, "face tempId collision"
            face = faces[0]
            filename = table.getInputAtPosition(row, COL.FILENAME).value
            # export first, to inhibit permanent export flag on failure
            if table.getInputAtPosition(row, COL.INCLUDE).value:
                path = dir + os.path.sep \
                       + filename + table.getInputAtPosition(row, COL.EXT).value
                sketch = root.sketches.add(face)
                sketch.saveAsDXF(path)
                sketch.deleteMe()

            face.attributes.add(_ATTR_GROUP, 'filename', filename)
            body.attributes.add(_ATTR_GROUP, 'export', "yes")

            prog.progressValue = row

        for face in _scan_cache:
            if (face.body.name, face.tempId) not in keep:
                a = face.attributes.itemByName(_ATTR_GROUP, 'filename')
                if a:
                    a.deleteMe()

            body = face.body
            if not any(
                    body.faces.item(j).attributes.itemByName(
                        _ATTR_GROUP, 'filename')
                    for j in range(body.faces.count)):
                a = body.attributes.itemByName(_ATTR_GROUP, 'export')
                if a:
                    a.deleteMe()

        prog.hide()
        adsk.terminate()