def execute(self, selfobj): """ Doing a recomputation. """ m_properties_list = ["Distance", 'AlongEdge', 'Edge', 'Point' ] for m_property in m_properties_list: if m_property not in selfobj.PropertiesList: return if M_DEBUG: print("running AlongLinePoint.execute !") # To be compatible with previous version > 2019 if 'Parametric' in selfobj.PropertiesList: # Create the object the first time regardless # the parametric behavior if selfobj.Parametric == 'Not' and self.created: return if selfobj.Parametric == 'Interactive' and self.created: return if selfobj.AlongEdge is None: return if selfobj.Edge is None and selfobj.Point is None: return try: vector_point = None m_distance = selfobj.Distance # m_n1 = eval(selfobj.AlongEdge[1][0].lstrip('Edge')) m_n1 = re.sub('[^0-9]', '', selfobj.AlongEdge[1][0]) m_n1 = int(m_n1) if selfobj.Edge is not None: # m_n2 = eval(selfobj.Edge[1][0].lstrip('Edge')) m_n2 = re.sub('[^0-9]', '', selfobj.Edge[1][0]) m_n2 = int(m_n2) else: if selfobj.Point != selfobj.AlongEdge: # m_n3 = eval(selfobj.Point[1][0].lstrip('Vertex')) m_n3 = re.sub('[^0-9]', '', selfobj.Point[1][0]) else: # m_n3 = eval(selfobj.Point[1][0].lstrip('Edge')) m_n3 = re.sub('[^0-9]', '', selfobj.Point[1][0]) m_n3 = int(m_n3) if M_DEBUG: print_msg("m_n1 = " + str(m_n1)) if selfobj.Edge is not None: print_msg("m_n2 = " + str(m_n2)) else: print_msg("m_n3 = " + str(m_n3)) print_msg("m_distance = " + str(m_distance)) m_alongedge = selfobj.AlongEdge[0].Shape.Edges[m_n1 - 1] if selfobj.Edge is not None: m_edge = selfobj.Edge[0].Shape.Edges[m_n2 - 1] else: m_point = selfobj.Point[0].Shape.Vertexes[m_n3 - 1].Point vector_a = m_alongedge.valueAt(0.0) vector_b = m_alongedge.valueAt(m_alongedge.Length) if isEqualVectors(vector_a, vector_b): return if selfobj.Edge is not None: m_dist = m_alongedge.distToShape(m_edge) vector_c = m_dist[1][0][0] else: vector_c = m_point # Calculate intersection Point vector_t, _, _ = intersectPerpendicularLine(vector_a, vector_b, vector_c,) if M_DEBUG: print_msg("m_alongedge = " + str(m_alongedge)) if selfobj.Edge is not None: print_msg("m_edge = " + str(m_edge)) else: print_msg("m_point = " + str(m_point)) print_msg("vector_a = " + str(vector_a)) print_msg("vector_b = " + str(vector_b)) print_msg("vector_c = " + str(vector_c)) print_msg("vector_t = " + str(vector_t)) vector_translate = (vector_b - vector_a) if m_distance != 0.0: vector_translate = vector_translate.normalize() * m_distance vector_point = vector_t + vector_translate else: vector_point = vector_t if vector_point is not None: point = Part.Point(vector_point) selfobj.Shape = point.toShape() propertiesPoint(selfobj.Label, self.color) selfobj.X = float(vector_point.x) selfobj.Y = float(vector_point.y) selfobj.Z = float(vector_point.z) # To be compatible with previous version 2018 if 'Parametric' in selfobj.PropertiesList: self.created = True except AttributeError as err: print("AttributeError" + str(err)) except Exception as err: printError_msg(err.args[0], title=M_MACRO)
def execute(self, selfobj): """ Doing a recomputation. """ m_properties_list = ['Edge', 'Point', 'Extension'] for m_property in m_properties_list: if m_property not in selfobj.PropertiesList: return if M_DEBUG: print("running LinePointPlane.execute !") # To be compatible with previous version > 2019 if 'Parametric' in selfobj.PropertiesList: # Create the object the first time regardless # the parametric behavior if selfobj.Parametric == 'Not' and self.created: return if selfobj.Parametric == 'Interactive' and self.created: return try: plane = None if selfobj.Edge is not None and selfobj.Point is not None: # n1 = eval(selfobj.Point[1][0].lstrip('Vertex')) # n2 = eval(selfobj.Edge[1][0].lstrip('Edge')) m_n1 = re.sub('[^0-9]', '', selfobj.Point[1][0]) m_n2 = re.sub('[^0-9]', '', selfobj.Edge[1][0]) m_n1 = int(m_n1) m_n2 = int(m_n2) if M_DEBUG: print_msg(str(selfobj.Point)) print_msg(str(selfobj.Edge)) print_msg("n1 = " + str(m_n1)) print_msg("n2 = " + str(m_n2)) points = [] point_a = selfobj.Edge[0].Shape.Edges[m_n2 - 1].Vertexes[0].Point point_b = selfobj.Edge[0].Shape.Edges[m_n2 - 1].Vertexes[-1].Point point_c = selfobj.Point[0].Shape.Vertexes[m_n1 - 1].Point if isEqualVectors(point_a, point_b): m_msg = """Unable to create Plane from 2 equals Points : Points 1 and 2 are equals ! """ printError_msg(m_msg, title=M_MACRO) return if isEqualVectors(point_a, point_c): m_msg = """Unable to create Plane from 2 equals Points : Points 1 an 3 are equals ! """ printError_msg(m_msg, title=M_MACRO) return if isEqualVectors(point_b, point_c): m_msg = """Unable to create Plane from 2 equals Points : Points 2 an 3 are equals ! """ printError_msg(m_msg, title=M_MACRO) return if isColinearVectors(point_a, point_b, point_c): printError_msg(M_EXCEPTION_MSG, title=M_MACRO) return points.append(point_a) points.append(point_b) points.append(point_c) vector_center = meanVectorsPoint(points) vector21 = point_b - point_a vector31 = point_c - point_a plane_point = vector_center plane_normal = vector21.cross(vector31) edge_length = selfobj.Extension plane = Part.makePlane(edge_length, edge_length, plane_point, plane_normal) plane_center = plane.CenterOfMass plane_translate = plane_point - plane_center plane.translate(plane_translate) if plane is not None: selfobj.Shape = plane propertiesPlane(selfobj.Label, self.color) selfobj.Point1_X = float(point_a.x) selfobj.Point1_Y = float(point_a.y) selfobj.Point1_Z = float(point_a.z) selfobj.Point2_X = float(point_b.x) selfobj.Point2_Y = float(point_b.y) selfobj.Point2_Z = float(point_b.z) selfobj.Point3_X = float(point_c.x) selfobj.Point3_Y = float(point_c.y) selfobj.Point3_Z = float(point_c.z) # To be compatible with previous version 2018 if 'Parametric' in selfobj.PropertiesList: self.created = True except AttributeError as err: print("AttributeError" + str(err)) except Exception as err: printError_msg(err.args[0], title=M_MACRO)
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 execute(self, selfobj): """ Doing a recomputation. """ m_properties_list = ['Point1', 'Point2', 'Extension'] for m_property in m_properties_list: if m_property not in selfobj.PropertiesList: return if M_DEBUG: print("running TwoPointsLine.execute !") # To be compatible with previous version > 2019 if 'Parametric' in selfobj.PropertiesList: # Create the object the first time regardless # the parametric behavior if selfobj.Parametric == 'Not' and self.created: return if selfobj.Parametric == 'Interactive' and self.created: return try: line = None if selfobj.Point1 is not None and selfobj.Point2 is not None: # n1 = eval(selfobj.Point1[1][0].lstrip('Vertex')) # n2 = eval(selfobj.Point2[1][0].lstrip('Vertex')) m_n1 = re.sub('[^0-9]', '', selfobj.Point1[1][0]) m_n2 = re.sub('[^0-9]', '', selfobj.Point2[1][0]) m_n1 = int(m_n1) m_n2 = int(m_n2) if M_DEBUG: print_msg(str(selfobj.Point1)) print_msg(str(selfobj.Point2)) print_msg("m_n1 = " + str(m_n1)) print_msg("m_n2 = " + str(m_n2)) point1 = selfobj.Point1[0].Shape.Vertexes[m_n1 - 1].Point point2 = selfobj.Point2[0].Shape.Vertexes[m_n2 - 1].Point if isEqualVectors(point1, point2): m_msg = """Unable to create Line(s) from 2 Points : Given Points are equals ! """ printError_msg(m_msg, title=M_MACRO) axis_dir = point2 - point1 point_e1 = point2 point_e2 = point1 M_LINE_EXT = selfobj.Extension if M_LINE_EXT != 0.0: point_e1 += axis_dir.normalize().multiply(M_LINE_EXT) if M_LINE_EXT >= 0.0: point_e2 -= axis_dir.normalize().multiply(M_LINE_EXT) else: point_e2 += axis_dir.normalize().multiply(M_LINE_EXT) line = Part.makeLine(coordVectorPoint(point_e2), coordVectorPoint(point_e1)) if line is not None: selfobj.Shape = line propertiesLine(selfobj.Label, self.color) selfobj.Point1_X = float(point1.x) selfobj.Point1_Y = float(point1.y) selfobj.Point1_Z = float(point1.z) selfobj.Point2_X = float(point2.x) selfobj.Point2_Y = float(point2.y) selfobj.Point2_Z = float(point2.z) # To be compatible with previous version 2018 if 'Parametric' in selfobj.PropertiesList: self.created = True except AttributeError as err: print("AttributeError" + str(err)) except Exception as err: printError_msg(err.args[0], title=M_MACRO)