Пример #1
0
def three_points_plane_command():
    """ This command use the selected object(s) to try to build a
    ThreePointsPlane feature object.
    """
    m_sel, m_act_doc = getSel(WF.verbose())

    points_from = ["Points", "Curves", "Objects"]
    try:
        number_of_vertexes, vertex_list = m_sel.get_pointsWithNames(
            get_from=points_from)

        if number_of_vertexes < 3:
            raise Exception(M_EXCEPTION_MSG)

        try:
            m_main_dir = "WorkPlanes_P"
            m_sub_dir = "Set000"
            m_group = createFolders(str(m_main_dir))

            # Create a sub group if needed
            if number_of_vertexes > 6:
                m_group = createSubGroup(m_act_doc, m_main_dir, m_sub_dir)

            # Case of only 3 points
            if number_of_vertexes == 3:
                buildFromThreePoints(M_MACRO, m_group, vertex_list,
                                     M_PLANE_EXT)
            else:
                raise Exception(M_EXCEPTION_MSG)

        except Exception as err:
            printError_msg(err.args[0], title=M_MACRO)

    except Exception as err:
        printError_msgWithTimer(err.args[0], title=M_MACRO)

    App.ActiveDocument.commitTransaction()
    App.activeDocument().recompute()
Пример #2
0
def along_line_point_command():
    """ This command use the selected object(s) to try to build a
    AlongLinePoint feature object.
    """
    m_sel, m_act_doc = getSel(WF.verbose())

    edges_from = ["Segments", "Curves"]
    points_from = ["Points"]
    try:
        if m_sel.numberOfEntities == 1:
            number_of_edges, edge_list = m_sel.get_segmentsWithNames(
                get_from=edges_from)
        else:
            number_of_edges, edge_list = m_sel.get_segmentsWithNames(
                get_from=edges_from)

        number_of_vertexes, vertex_list = m_sel.get_pointsWithNames(
            get_from=points_from)

        if number_of_edges == 0:
            raise Exception(M_EXCEPTION_MSG)
        else:
            if number_of_edges == 1 and number_of_vertexes == 0:
                raise Exception(M_EXCEPTION_MSG)

        m_main_dir = "WorkPoints_P"
        m_sub_dir = "Set000"
        m_group = createFolders(str(m_main_dir))

        m_distance = getDistanceLinePoint()

        # Selection of : One Edge and One or several Point(s)
        if number_of_edges == 1 and number_of_vertexes > 0:
            try:
                # Create a sub group if needed
                if number_of_vertexes > 1:
                    m_group = createSubGroup(m_act_doc, m_main_dir, m_sub_dir)

                edge = edge_list[0]
                for j in range(number_of_vertexes):
                    point = vertex_list[j]
                    buildFromEdgeAndPoint(M_MACRO,
                                          m_group,
                                          edge, point, m_distance)

            except Exception as err:
                printError_msg(err.args[0], title=M_MACRO)

        # Selection of : One Edge and One or several Edge(s)
        elif number_of_edges > 1 and number_of_vertexes == 0:
            try:
                # Create a sub group if needed
                if number_of_edges > 2:
                    m_group = createSubGroup(m_act_doc, m_main_dir, m_sub_dir)

                edge = edge_list[0]
                for other_edge in edge_list[1:]:
                    buildFromEdges(M_MACRO,
                                   m_group,
                                   edge, other_edge, m_distance)

            except Exception as err:
                printError_msg(err.args[0], title=M_MACRO)

        # Selection of : several Edges and Points with
        # same number of Edges and Points
        elif number_of_edges > 1 and number_of_vertexes == number_of_edges:
            try:
                # Create a sub group if needed
                m_group = createSubGroup(m_act_doc, m_main_dir, m_sub_dir)

                for edge, point in zip(edge_list, vertex_list):
                    buildFromEdgeAndPoint(M_MACRO,
                                          m_group,
                                          edge, point, m_distance)

            except Exception as err:
                printError_msg(err.args[0], title=M_MACRO)

        else:
            printError_msg("Bad selection !", title=M_MACRO)

    except Exception as err:
        printError_msgWithTimer(err.args[0], title=M_MACRO)

    App.ActiveDocument.commitTransaction()
    App.activeDocument().recompute()
Пример #3
0
def center_line_point_command():
    """ This command use the selected object(s) to try to build a
    CenterLinePoint feature object.
    """
    m_sel, m_act_doc = getSel(WF.verbose())

    edges_from = ["Segments", "Curves", "Planes", "Shells", "Objects"]
    points_from = ["Points"]
    try:
        number_of_edges, edge_list = m_sel.get_segmentsWithNames(
            get_from=edges_from)
        # number_of_edges, edge_list = m_sel.get_segmentsWithIndex(getfrom=edges_from)

        if number_of_edges == 0:
            # Try to get Edges from points
            number_of_vertexes, vertex_list = m_sel.get_pointsWithNames(
                get_from=points_from)

        if number_of_edges == 0 and number_of_vertexes < 2:
            raise Exception(M_EXCEPTION_MSG)

        try:
            if WF.verbose():
                print_msg("Location = " + str(M_LOCATION))

            m_main_dir = "WorkPoints_P"
            m_sub_dir = "Set000"
            m_group = createFolders(str(m_main_dir))

            # From Edges
            if number_of_edges != 0:
                # Create a sub group if needed
                if number_of_edges > 1 or M_LOCATION != "Single":
                    m_group = createSubGroup(m_act_doc, m_main_dir, m_sub_dir)

                for i in range(number_of_edges):
                    m_edge = edge_list[i]

                    # Check if first point and last point of edge is not the
                    # same
                    vector_a = m_edge[0].Shape.Edges[0].Vertexes[0].Point
                    vector_b = m_edge[0].Shape.Edges[0].Vertexes[-1].Point
                    if isEqualVectors(vector_a, vector_b):
                        continue

                    if M_LOCATION == "Single":
                        buildFromEdge(M_MACRO,
                                      m_group,
                                      m_edge, M_NUMBERLINEPART, M_INDEXPART)
                    else:
                        for m_i_part in range(M_NUMBERLINEPART + 1):
                            buildFromEdge(M_MACRO,
                                          m_group,
                                          m_edge, M_NUMBERLINEPART, m_i_part)

            # From Vertexes
            else:
                if number_of_vertexes > 2:
                    m_group = createSubGroup(m_act_doc, m_main_dir, m_sub_dir)

                # Even number of vertexes
                if number_of_vertexes % 2 == 0:
                    if WF.verbose():
                        print_msg("Even number of points")

                    if number_of_vertexes == 2:
                        vertex1 = vertex_list[0]
                        vertex2 = vertex_list[1]

    #                     point1 = vertex1[0].Shape.Vertexes[0].Point
    #                     point2 = vertex2[0].Shape.Vertexes[0].Point
    #                     if isEqualVectors(point1, point2):
    #                         return

                        if M_LOCATION == "Single":
                            buildFromPoints(M_MACRO,
                                            m_group,
                                            (vertex1, vertex2),
                                            M_NUMBERLINEPART, M_INDEXPART)
                        else:
                            for m_i_part in range(M_NUMBERLINEPART + 1):
                                buildFromPoints(M_MACRO,
                                                m_group,
                                                (vertex1, vertex2),
                                                M_NUMBERLINEPART, m_i_part)
                    else:
                        for i in range(0, number_of_vertexes - 2, 2):
                            vertex1 = vertex_list[i]
                            vertex2 = vertex_list[i + 1]

    #                         point1 = vertex1[0].Shape.Vertexes[0].Point
    #                         point2 = vertex2[0].Shape.Vertexes[0].Point
    #                         if isEqualVectors(point1, point2):
    #                             continue

                            if M_LOCATION == "Single":
                                buildFromPoints(M_MACRO,
                                                m_group,
                                                (vertex1, vertex2),
                                                M_NUMBERLINEPART, M_INDEXPART)
                            else:
                                for m_i_part in range(M_NUMBERLINEPART + 1):
                                    buildFromPoints(M_MACRO,
                                                    m_group,
                                                    (vertex1, vertex2),
                                                    M_NUMBERLINEPART, m_i_part)
                # Odd number of vertexes
                else:
                    if WF.verbose():
                        print_msg("Odd number of points")
                    for i in range(number_of_vertexes - 1):
                        vertex1 = vertex_list[i]
                        vertex2 = vertex_list[i + 1]

                        if M_LOCATION == "Single":
                            buildFromPoints(M_MACRO,
                                            m_group,
                                            (vertex1, vertex2),
                                            M_NUMBERLINEPART, M_INDEXPART)
                        else:
                            for m_i_part in range(M_NUMBERLINEPART + 1):
                                buildFromPoints(M_MACRO,
                                                m_group,
                                                (vertex1, vertex2),
                                                M_NUMBERLINEPART, m_i_part)

        except Exception as err:
            printError_msg(err.args[0], title=M_MACRO)

    except Exception as err:
        printError_msgWithTimer(err.args[0], title=M_MACRO)

    App.ActiveDocument.commitTransaction()
    App.activeDocument().recompute()
Пример #4
0
def n_points_line_command():
    """ This command use the selected object(s) to try to build a
    NPointsLine feature object.
    """
    m_sel, m_act_doc = getSel(WF.verbose())

    points_from = ["Points", "Curves", "Objects"]
    try:
        number_of_vertexes, vertex_list = m_sel.get_pointsWithNames(
            get_from=points_from)

        if number_of_vertexes < 2:
            raise Exception(M_EXCEPTION_MSG)

        try:
            m_main_dir = "WorkAxis_P"
            m_sub_dir = "Set000"
            m_group = createFolders(str(m_main_dir))

            # Create a sub group if needed
            if M_SVD_FLAG:
                m_group = createSubGroup(m_act_doc, m_main_dir, m_sub_dir)

            points = []
            # Case of only 2 points
            if number_of_vertexes == 2:
                if WF.verbose():
                    print_msg("Process only 2 points")
                vertex1 = vertex_list[0]
                vertex2 = vertex_list[1]
                points.append(vertex1)
                points.append(vertex2)

                if WF.verbose():
                    print_msg("vertex1 = " + str(vertex1))
                    print_msg("vertex2 = " + str(vertex2))

                App.ActiveDocument.openTransaction(M_MACRO)
                selfobj, m_inst = makeNPointsLineFeature(m_group)
                m_inst.addSubobjects(selfobj, points)
                selfobj.VectorIndex = '1'
                selfobj.Proxy.execute(selfobj)

                if M_SVD_FLAG:
                    App.ActiveDocument.openTransaction(M_MACRO)
                    selfobj, m_inst = makeNPointsLineFeature(m_group)
                    m_inst.addSubobjects(selfobj, points)
                    selfobj.VectorIndex = '2'
                    selfobj.Proxy.execute(selfobj)

                    App.ActiveDocument.openTransaction(M_MACRO)
                    selfobj, m_inst = makeNPointsLineFeature(m_group)
                    m_inst.addSubobjects(selfobj, points)
                    selfobj.VectorIndex = '3'
                    selfobj.Proxy.execute(selfobj)
            # Case of more than 2 points
            else:
                if WF.verbose():
                    print_msg("Process more than 2 points")
                for i in range(number_of_vertexes):
                    vertex = vertex_list[i]
                    points.append(vertex)
                    if WF.verbose():
                        print_msg("vertex = " + str(vertex))

                App.ActiveDocument.openTransaction(M_MACRO)
                selfobj, m_inst = makeNPointsLineFeature(m_group)
                m_inst.addSubobjects(selfobj, points)
                selfobj.VectorIndex = '1'
                selfobj.Proxy.execute(selfobj)

                if M_SVD_FLAG:
                    App.ActiveDocument.openTransaction(M_MACRO)
                    selfobj, m_inst = makeNPointsLineFeature(m_group)
                    m_inst.addSubobjects(selfobj, points)
                    selfobj.VectorIndex = '2'
                    selfobj.Proxy.execute(selfobj)

                    App.ActiveDocument.openTransaction(M_MACRO)
                    selfobj, m_inst = makeNPointsLineFeature(m_group)
                    m_inst.addSubobjects(selfobj, points)
                    selfobj.VectorIndex = '3'
                    selfobj.Proxy.execute(selfobj)

        except Exception as err:
            printError_msg(err.args[0], title=M_MACRO)

    except Exception as err:
        printError_msgWithTimer(err.args[0], title=M_MACRO)

    App.ActiveDocument.commitTransaction()
    App.activeDocument().recompute()
Пример #5
0
def two_points_line_command():
    """ This command use the selected object(s) to try to build a
    TwoPointsLine feature object.
    """
    m_sel, m_act_doc = getSel(WF.verbose())

    points_from = ["Points", "Curves", "Objects"]
    try:
        number_of_vertexes, vertex_list = m_sel.get_pointsWithNames(
            get_from=points_from)

        if number_of_vertexes < 2:
            raise Exception(M_EXCEPTION_MSG)

        try:
            m_main_dir = "WorkAxis_P"
            m_sub_dir = "Set000"
            m_group = createFolders(str(m_main_dir))

            # Create a sub group if needed
            if number_of_vertexes > 2:
                m_group = createSubGroup(m_act_doc, m_main_dir, m_sub_dir)

            # Case of only 2 points
            if number_of_vertexes == 2:
                if WF.verbose():
                    print_msg("Process only 2 points")
                vertex1 = vertex_list[0]
                vertex2 = vertex_list[1]

                buildFromPoints(M_MACRO, m_group, vertex1, vertex2, M_LINE_EXT)

            # Case of more than 2 points
            else:
                if M_BYPAIR:
                    if WF.verbose():
                        print_msg("Process points by pair")
                    # even
                    if (number_of_vertexes % 2 == 0):
                        if WF.verbose():
                            print_msg("Even number of points")
                        for i in range(0, number_of_vertexes - 1, 2):
                            vertex1 = vertex_list[i]
                            vertex2 = vertex_list[i + 1]

                            buildFromPoints(M_MACRO, m_group, vertex1, vertex2,
                                            M_LINE_EXT)
                    # odd
                    else:
                        if WF.verbose():
                            print_msg("Odd number of points")
                        for i in range(0, number_of_vertexes - 2, 2):
                            vertex1 = vertex_list[i]
                            vertex2 = vertex_list[i + 1]

                            buildFromPoints(M_MACRO, m_group, vertex1, vertex2,
                                            M_LINE_EXT)

                        if WF.closePolyline():
                            vertex1 = vertex_list[-1]
                            vertex2 = vertex_list[0]

                            buildFromPoints(M_MACRO, m_group, vertex1, vertex2,
                                            M_LINE_EXT)
                else:
                    if WF.verbose():
                        print_msg("Process points as list")
                    for i in range(number_of_vertexes - 1):
                        vertex1 = vertex_list[i]
                        vertex2 = vertex_list[i + 1]

                        buildFromPoints(M_MACRO, m_group, vertex1, vertex2,
                                        M_LINE_EXT)

                    if WF.closePolyline():
                        vertex1 = vertex_list[-1]
                        vertex2 = vertex_list[0]

                        buildFromPoints(M_MACRO, m_group, vertex1, vertex2,
                                        M_LINE_EXT)

        except Exception as err:
            printError_msg(err.args[0], title=M_MACRO)

    except Exception as err:
        printError_msgWithTimer(err.args[0], title=M_MACRO)

    App.ActiveDocument.commitTransaction()
    App.activeDocument().recompute()