def n_points_point_comand(): m_sel, _ = getSel(WF.verbose()) points_from = ["Points", "Curves", "Planes", "Shells", "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 = "WorkPoints_P" m_sub_dir = "Set001" m_group = createFolders(str(m_main_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) buildFromPoints(M_MACRO, m_group, points) # Case of more than 2 points else: if WF.verbose(): print_msg("Process more than 2 points") for i in range(number_of_vertexes): vertex1 = vertex_list[i] points.append(vertex1) buildFromPoints(M_MACRO, m_group, points) 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()
def line_point_plane_command(): """ This command use the selected object(s) to try to build a LinePointPlane feature object. """ m_sel, m_act_doc = getSel(WF.verbose()) edges_from = ["Segments", "Curves", "Planes", "Objects"] points_from = ["Points", "Curves", "Objects"] try: 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 < 1: raise Exception(M_EXCEPTION_MSG) if number_of_vertexes < 1: raise Exception(M_EXCEPTION_MSG) try: m_main_dir = "WorkPlanes_P" m_sub_dir = "Set001" m_group = createFolders(str(m_main_dir)) # Create a sub group if needed # To develop # Case of only 1 point and 1 Edge if number_of_edges == 1 and number_of_vertexes == 1: edge = edge_list[0] vertex = vertex_list[0] buildFromPointAndLine(M_MACRO, m_group, vertex, edge, 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()
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()
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()
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()
def extrema_line_point_command(): """ This command use the selected object(s) to try to build a ExtremaLinePoint feature object. """ m_sel, m_act_doc = getSel(WF.verbose()) edges_from = ["Segments", "Curves", "Planes", "Shells", "Objects"] try: number_of_edges, edge_list = m_sel.get_segmentsWithNames( get_from=edges_from) if number_of_edges == 0: raise Exception(M_EXCEPTION_MSG) try: m_main_dir = "WorkPoints_P" m_sub_dir = "Set000" m_group = createFolders(str(m_main_dir)) m_error_msg = "Could not Create '" m_error_msg += str(m_sub_dir) + "' Objects Group!" if WF.verbose(): print_msg("Location = " + str(M_LOCATION)) # Create a sub group if needed if number_of_edges > 1 or M_LOCATION == "Both ends": try: m_ob = App.ActiveDocument.getObject( str(m_main_dir)).newObject("App::DocumentObjectGroup", str(m_sub_dir)) m_group = m_act_doc.getObject(str(m_ob.Label)) except Exception as err: printError_msg(err.args[0], title=M_MACRO) printError_msg(m_error_msg) if WF.verbose(): print_msg("Group = " + str(m_group.Label)) for i in range(number_of_edges): edge = edge_list[i] if M_LOCATION in ["Begin", "Both ends"]: App.ActiveDocument.openTransaction(M_MACRO) selfobj1 = makeExtremaLinePointFeature(m_group) selfobj1.Edge = edge selfobj1.At = "Begin" selfobj1.Proxy.execute(selfobj1) if str(selfobj1.Parametric) == 'Interactive': selfobj1.Parametric = 'Dynamic' selfobj1.touch() selfobj1.Parametric = 'Interactive' if str(selfobj1.Parametric) == 'Not': selfobj1.Parametric = 'Dynamic' selfobj1.touch() selfobj1.Parametric = 'Not' if M_LOCATION in ["End", "Both ends"]: App.ActiveDocument.openTransaction(M_MACRO) selfobj2 = makeExtremaLinePointFeature(m_group) selfobj2.Edge = edge selfobj2.At = "End" selfobj2.Proxy.execute(selfobj2) if str(selfobj2.Parametric) == 'Interactive': selfobj2.Parametric = 'Dynamic' selfobj2.touch() selfobj2.Parametric = 'Interactive' if str(selfobj2.Parametric) == 'Not': selfobj2.Parametric = 'Dynamic' selfobj2.touch() selfobj2.Parametric = 'Not' 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()
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()
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()