示例#1
0
def correct_bom():
    try:
        session = Api()
        print("- Author: [email protected]")
        print("- Last update: 2020-05-01")
        session.check_valid_version("Solid Edge ST7", "Solid Edge 2019")
        draft = session.active_document()
        print("Document Number: %s\n" % draft.name)
        assert draft.name.lower().endswith(".dft"), (
            "This macro only works on draft document not %s" % draft.name[-4:]
        )

        if draft.PartsLists.Count == 1:

            print("\nMax number of rows:")
            print(
                "  \t- First Page..................: %s"
                % draft.PartsLists[1].MaximumRowsFirstPage
            )
            print(
                "  \t- Additional Page.............: %s"
                % draft.PartsLists[1].MaximumRowsAdditionalPages
            )

            print("\nMax height:")
            mhfp = draft.PartsLists[1].MaximumHeightFirstPage
            mhap = draft.PartsLists[1].MaximumHeightAdditionalPages
            print("\t- First Page..................: %s" % mhfp)
            print("\t- Additional Page.............: %s" % mhap)
            print("\n")
            print("\t\t****************")

            response = raw_input(
                "Would you like to overwrite the rows with 100-100? [y/Y]es:\n>"
            )
            if response.lower() in ["y", "yes"]:
                pass
            else:
                sys.exit()
            # =========== Overwrite ===============

            draft.PartsLists[1].MaximumRowsFirstPage = 100
            draft.PartsLists[1].MaximumRowsAdditionalPages = 100
            print("Overwrite rows with 100-100: \tdone")

            mhfp, mhap = 0.1778, 0.1778
            draft.PartsLists[1].MaximumHeightFirstPage = mhfp
            draft.PartsLists[1].MaximumHeightAdditionalPages = mhap
            print("Overwrite heights: \tdone")

            print("\n")
            print("\t\t****************")
            print("\n")
            print("Max number of rows:")
            print(
                "\t- First Page..................: %s"
                % draft.PartsLists[1].MaximumRowsFirstPage
            )
            print(
                "\t- Additional Page.............: %s"
                % draft.PartsLists[1].MaximumRowsAdditionalPages
            )
            print("\n")
            print("Max height:")
            print(
                "\t- First Page..................: %s"
                % draft.PartsLists[1].MaximumHeightFirstPage
            )
            print(
                "\t- Additional Page.............: %s"
                % draft.PartsLists[1].MaximumHeightAdditionalPages
            )

        else:
            pass

    except AssertionError as err:
        print(err.args)
    except Exception as ex:
        print(ex.args)
    finally:
        raw_input("\nPress any key to exit...")
        sys.exit()
示例#2
0
def main():
    """Convert holes in plate to metric (by default) or imperial."""
    try:
        session = Api()
        plate = session.active_document()
        print("Part: {:^30s}\n".format(plate.name))

        # Check if part is sheetmetal.
        assert plate.name.endswith(
            ".psm"), "This macro only works on .psm not {:^30s}".format(
                plate.name[-4:])

        # Get a reference to the variables collection.
        holes = HoleCollection(plate)

        # Display the quantites of different types of holes.
        quantites(
            holes.count,
            holes.count_threaded,
            holes.count_imperial_threaded,
            holes.count_metric_threaded,
        )

        # Prototyping table of holes. (helper for drafter)
        ## qty_size = dict(len(holes.all_holes()))  # >>> 'M6x1':3
        ## print_table(qty_size)

        # Prompt user selection
        units = prompt_units_selection()

        if units == "metric":  # if metric
            for hole in holes.threaded():
                o = Hole(hole)
                if o.is_metric():
                    continue
                imperial = o.size
                holedata = Hole.get_equivalence(o, mapping=mappingToMetric)
                o.conversion_to_metric(holedata)
                metric = o.size
                header()
                print(" {:<30s} {:<30s}".format(imperial, metric))
                footer()

        elif units == "imperial":  # if imperial
            for hole in holes.threaded():
                o = Hole(hole)
                if o.is_imperial():
                    continue
                metric = o.size
                holedata = Hole.get_equivalence(
                    o, mapping=mappingToImp)  # correction
                o.conversion_to_metric(holedata)  # correction
                imperial = o.size
                header()
                print(" {:<30s} {:<30s}".format(metric, imperial))
                footer()

        elif units == "debug":
            for hole in holes.threaded():
                o = Hole(hole)
                print(o.__repr__())

        else:
            sys.exit()

        # Display a second time the quantites of different types of holes.
        quantites(
            holes.count,
            holes.count_threaded,
            holes.count_imperial_threaded,
            holes.count_metric_threaded,
            state="(Changed state)",
        )

    except AssertionError as err:
        print(err.args)

    except Exception as ex:
        print(ex.args)

    else:
        pass

    finally:
        raw_input("\nPress any key to exit...")
        sys.exit()