def execute_2018(self, selfobj): if WF.verbose(): m_msg = "Recompute Python CenterLinePoint feature (old manner)\n" App.Console.PrintMessage(m_msg) if 'Edge' not in selfobj.PropertiesList: return if 'IndexPart' not in selfobj.PropertiesList: return if 'NumberLinePart' not in selfobj.PropertiesList: return n = eval(selfobj.Edge[1][0].lstrip('Edge')) if WF.verbose(): print_msg("n = " + str(n)) try: Vector_point = alongLinePoint(selfobj.Edge[0].Shape.Edges[n - 1], selfobj.IndexPart, selfobj.NumberLinePart) point = Part.Point(Vector_point) selfobj.Shape = point.toShape() propertiesPoint(selfobj.Label) selfobj.X = float(Vector_point.x) selfobj.Y = float(Vector_point.y) selfobj.Z = float(Vector_point.z) except Exception as err: printError_msg(err.args[0], title=m_macro)
def execute_2018(self, selfobj): """ Doing a old recomputation. """ if M_DEBUG: print("Recompute Python CenterLinePoint feature (old manner)\n") if 'Edge' not in selfobj.PropertiesList: return if 'IndexPart' not in selfobj.PropertiesList: return if 'NumberLinePart' not in selfobj.PropertiesList: return # n = eval(selfobj.Edge[1][0].lstrip('Edge')) m_int = re.sub('[^0-9]', '', selfobj.Edge[1][0]) n = int(m_int) if WF.verbose(): print_msg("n = " + str(n)) try: vector_point = alongLinePoint(selfobj.Edge[0].Shape.Edges[n - 1], selfobj.IndexPart, selfobj.NumberLinePart) point = Part.Point(vector_point) selfobj.Shape = point.toShape() propertiesPoint(selfobj.Label) selfobj.X = float(vector_point.x) selfobj.Y = float(vector_point.y) selfobj.Z = float(vector_point.z) except Exception as err: printError_msg(err.args[0], title=M_MACRO)
def buildFromTwoPoints(vertex1, vertex2, index, object1, group): if WF.verbose(): App.Console.PrintMessage("running aLP.buildFromTwoPoints !") try: if M_DEBUG: print_msg("\nvertex1 = " + str(vertex1)) print_msg("vertex2 = " + str(vertex2)) vector_a = vertex1 vector_b = vertex2 m_distance = vector_b.sub(vector_a).Length / 2 m_distance = index * (vector_b.sub(vector_a).Length / 1) if M_DEBUG: print_msg("vector_a = " + str(vector_a)) print_msg("vector_b = " + str(vector_b)) print_msg("m_distance = " + str(m_distance)) vector_c = vector_a.add( vector_b.sub(vector_a).normalize().multiply(m_distance)) if M_DEBUG: print_msg("vector_c = " + str(vector_c)) L1 = Part.LineSegment(vector_b, vector_c) edge = Part.Edge(L1) # App.ActiveDocument.openTransaction("Macro AlongLinePoint") # selfobj = makeAlongLinePointFeature(group) # selfobj.AlongEdge = edge [object1, "Vertex1"] # selfobj.Point = vector_c # selfobj.Edge = None # selfobj.Distance = m_distance # selfobj.Proxy.execute(selfobj) except Exception as err: printError_msg(err.args[0], title="Macro AlongLinePoint")
def run(): m_sel, m_actDoc = getSel(WF.verbose()) try: Number_of_Edges, Edge_List = m_sel.get_segmentsNames( getfrom=["Segments","Curves"]) if WF.verbose() != 0: print_msg("Number_of_Edges = " + str(Number_of_Edges)) print_msg("Edge_List = " + str(Edge_List)) Number_of_Planes, Plane_List = m_sel.get_planesNames( getfrom=["Planes","Objects"]) if WF.verbose() != 0: print_msg("Number_of_Planes = " + str(Number_of_Planes)) print_msg("Plane_List = " + str(Plane_List)) if Number_of_Edges == 0 or Number_of_Planes == 0 : raise Exception(m_exception_msg) try: m_main_dir = "WorkPoints_P" m_sub_dir = "Set" m_group = createFolders(str(m_main_dir)) # Create a sub group if needed if Number_of_Edges > 1 or Number_of_Planes > 1: try: m_ob = App.ActiveDocument.getObject(str(m_main_dir)).newObject("App::DocumentObjectGroup", str(m_sub_dir)) m_group = m_actDoc.getObject( str(m_ob.Label) ) except: printError_msg("Could not Create '"+ str(m_sub_dir) +"' Objects Group!") if WF.verbose() != 0: print_msg("Group = " + str(m_group.Label)) for i in range( Number_of_Edges ): edge = Edge_List[i] if WF.verbose() != 0: print_msg("edge = " + str(edge)) for j in range( Number_of_Planes ): plane = Plane_List[j] if WF.verbose() != 0: print_msg("plane = " + str(plane)) App.ActiveDocument.openTransaction("Macro LineFacePoint") selfobj = makeLineFacePointFeature(m_group) selfobj.Edge = edge selfobj.Face = plane selfobj.Proxy.execute(selfobj) finally: App.ActiveDocument.commitTransaction() except Exception as err: printError_msg(err.message, title="Macro LineFacePoint")
def execute(self, selfobj): """ Doing a recomputation. """ if m_debug: print("running ExtremaLinePoint.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 WF.verbose(): m_msg = "Recompute Python ExtremaLinePoint feature\n" App.Console.PrintMessage(m_msg) m_PropertiesList = [ 'Edge', 'At', ] for m_Property in m_PropertiesList: if m_Property not in selfobj.PropertiesList: return try: Vector_point = None n = eval(selfobj.Edge[1][0].lstrip('Edge')) if m_debug: print_msg(str(selfobj.Edge)) print_msg("n = " + str(n)) print_msg(str(selfobj.Edge[0].Shape.Edges)) if len(selfobj.Edge[0].Shape.Edges) == 0: return if selfobj.At == "Begin": Vector_point = selfobj.Edge[0].Shape.Edges[n - 1].Vertexes[0].Point else: Vector_point = selfobj.Edge[0].Shape.Edges[ n - 1].Vertexes[-1].Point 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 Exception as err: printError_msg(err.args[0], title=m_macro)
def execute(self, selfobj): """ Doing a recomputation. """ if m_debug: print("running NPointsPoint.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 WF.verbose(): m_msg = "Recompute Python NPointsPoint feature\n" App.Console.PrintMessage(m_msg) if m_debug: print("selfobj.PropertiesList = " + str(selfobj.PropertiesList)) m_PropertiesList = [ 'Points', ] for m_Property in m_PropertiesList: if m_Property not in selfobj.PropertiesList: return try: Vector_point = None if m_debug: print("selfobj.Points = " + str(selfobj.Points)) if selfobj.Points is not None: m_points = [] for p in linkSubList_convertToOldStyle(selfobj.Points): n = eval(p[1].lstrip('Vertex')) if m_debug: print("p " + str(p)) print_msg("n = " + str(n)) m_points.append(p[0].Shape.Vertexes[n - 1].Point) Vector_point = meanVectorsPoint(m_points) 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 Exception as err: printError_msg(err.args[0], title=m_macro)
def execute(self, selfobj): """ Doing a recomputation. """ m_properties_list = [ 'Edge', 'At', ] for m_property in m_properties_list: if m_property not in selfobj.PropertiesList: return if M_DEBUG: print("running ExtremaLinePoint.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: vector_point = None m_n = re.sub('[^0-9]', '', selfobj.Edge[1][0]) m_n = int(m_n) if M_DEBUG: print_msg(str(selfobj.Edge)) print_msg("m_n = " + str(m_n)) if not selfobj.Edge[0].Shape.Edges: return if selfobj.At == "Begin": vector_point = selfobj.Edge[0].Shape.Edges[m_n - 1].Vertexes[0].Point else: vector_point = selfobj.Edge[0].Shape.Edges[ m_n - 1].Vertexes[-1].Point 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. """ if M_DEBUG: print("running CenterFacePoint.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 WF.verbose(): m_msg = "Recompute Python CenterFacePoint feature\n" App.Console.PrintMessage(m_msg) m_properties_list = [ 'Face', ] for m_property in m_properties_list: if m_property not in selfobj.PropertiesList: return try: Vector_point = None if selfobj.Face is not None: n = eval(selfobj.Face[1][0].lstrip('Face')) if M_DEBUG: print_msg(str(selfobj.Face)) print_msg("n = " + str(n)) m_face = selfobj.Face[0].Shape.Faces[n - 1] if M_DEBUG: print_msg("m_face = " + str(m_face)) Vector_point = m_face.CenterOfMass 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 Exception as err: printError_msg(err.args[0], title=M_MACRO)
def createSubGroup(main_dir, sub_dir, error_msg): try: m_ob_dir = App.ActiveDocument.getObject(main_dir) m_ob = m_ob_dir.newObject("App::DocumentObjectGroup", str(sub_dir)) m_group = m_actDoc.getObject(str(m_ob.Label)) except Exception as err: printError_msg(err.message, title=m_macro) printError_msg(error_msg) return m_group
def execute(self, selfobj): """ Doing a recomputation. """ m_properties_list = ['Points', ] for m_property in m_properties_list: if m_property not in selfobj.PropertiesList: return if M_DEBUG: print("running NPointsPoint.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: vector_point = None if selfobj.Points is not None: m_points = [] for p in linkSubList_convertToOldStyle(selfobj.Points): # n = eval(p[1].lstrip('Vertex')) m_n = re.sub('[^0-9]', '', p[1]) m_n = int(m_n) if M_DEBUG: print("p " + str(p)) print_msg("m_n = " + str(m_n)) m_points.append(p[0].Shape.Vertexes[m_n - 1].Point) vector_point = meanVectorsPoint(m_points) 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 propertiesPlane(Plane_User_Name, color=(1.00, 0.67, 0.00), s_color=(0.00, 0.33, 1.00)): """ Define the properties of a Work feature Plane. PointColor LineColor ShapeColor Transparency """ try: if isinstance(color, tuple): Gui.ActiveDocument.getObject(Plane_User_Name).PointColor = color except Exception as err: printError_msg(err.message, title="propertiesPlane") print_msg("Not able to set PointColor !") try: if isinstance(color, tuple): Gui.ActiveDocument.getObject(Plane_User_Name).LineColor = color except Exception as err: printError_msg(err.message, title="propertiesPlane") print_msg("Not able to set LineColor !") try: if isinstance(s_color, tuple): Gui.ActiveDocument.getObject(Plane_User_Name).ShapeColor = s_color except Exception as err: printError_msg(err.message, title="propertiesPlane") print_msg("Not able to set ShapeColor !") try: Gui.ActiveDocument.getObject(Plane_User_Name).Transparency = 75 except Exception as err: printError_msg(err.message, title="propertiesPlane") print_msg("Not able to set Transparency !") return
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 run(): m_sel, _ = getSel(WF.verbose()) try: number_of_edges, edge_list = m_sel.get_segmentsNames( getfrom=["Segments", "Curves", "Planes", "Objects"]) number_of_vertexes, vertex_list = m_sel.get_pointsNames( getfrom=["Points", "Curves", "Objects"]) if WF.verbose() != 0: print_msg("number_of_edges = " + str(number_of_edges)) print_msg("edge_list = " + str(edge_list)) print_msg("number_of_vertexes = " + str(number_of_vertexes)) print_msg("vertex_list = " + str(vertex_list)) 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 = "Set" m_group = createFolders(str(m_main_dir)) # Create a sub group if needed # To develop if WF.verbose() != 0: print_msg("Group = " + str(m_group.Label)) edge = edge_list[0] vertex = vertex_list[0] App.ActiveDocument.openTransaction( "Macro PerpendicularLinePointPlane") selfobj = makePerpendicularLinePointPlaneFeature(m_group) selfobj.Edge = edge selfobj.Point = vertex selfobj.Extension = m_extension selfobj.Proxy.execute(selfobj) finally: App.ActiveDocument.commitTransaction() except Exception as err: printError_msg(err.args[0], title="Macro PerpendicularLinePointPlane")
def createSubGroup(actDoc, main_dir, sub_dir): """ Create a sub directory group into main directory if needed """ m_error_msg = "Could not Create '" m_error_msg += str(sub_dir) + "' Objects Group!" try: m_ob_dir = App.ActiveDocument.getObject(str(main_dir)) m_ob = m_ob_dir.newObject("App::DocumentObjectGroup", str(sub_dir)) m_group = actDoc.getObject(str(m_ob.Label)) except Exception as err: printError_msg(err.args[0], title="createSubGroup") printError_msg(m_error_msg) if WF.verbose(): print_msg("Group = " + str(m_group.Label)) return m_group
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 makeCenterCirclePointFeature(group): """ Makes a CenterCirclePoint parametric feature object. into the given Group Returns the new object. """ m_name = "CenterCirclePoint_P" m_part = "Part::FeaturePython" try: m_obj = App.ActiveDocument.addObject(str(m_part), str(m_name)) if group != None: addObjectToGrp(m_obj, group, info=1) CenterCirclePoint(m_obj) ViewProviderCenterCirclePoint(m_obj.ViewObject) except: printError_msg("Not able to add an object to Model!") return None return m_obj
def makePerpendicularLinePointPlaneFeature(group): """ Makes a PerpendicularLinePointPlane parametric feature object. into the given Group Returns the new object. """ m_name = "PerpendicularLinePointPlane_P" m_part = "Part::FeaturePython" try: m_obj = App.ActiveDocument.addObject(str(m_part), str(m_name)) if group != None: addObjectToGrp(m_obj, group, info=1) PerpendicularLinePointPlane(m_obj) ViewProviderPerpendicularLinePointPlane(m_obj.ViewObject) except: printError_msg("Not able to add an object to Model!") return None return m_obj
def buildFromOnePointAndOneObject(vertex1, object1, group): try: if WF.verbose(): print_msg("vertex1 = " + str(vertex1)) print_msg("object1 = " + str(object1)) App.ActiveDocument.openTransaction("Macro TwoPointsLine") selfobj = makeTwoPointsLineFeature(group) selfobj.Point1 = vertex1 selfobj.Point2 = [object1, "Vertex1"] selfobj.Extension = 0.0 selfobj.Proxy.execute(selfobj) try: Gui.ActiveDocument.getObject(selfobj.Label).DrawStyle = "Dotted" except Exception as err: printError_msg(err.args[0], title="Macro TwoPointsLine") print_msg("Not able to set DrawStyle !") except Exception as err: printError_msg(err.args[0], title="Macro TwoPointsLine")
def propertiesLine(Line_User_Name, color=(1.00, 0.67, 0.00)): """ Define the properties of a Work feature Line. PointColor LineColor LineWidth PointSize Transparency """ try: if isinstance(color, tuple): Gui.ActiveDocument.getObject(Line_User_Name).PointColor = color except Exception as err: printError_msg(err.message, title="propertiesLine") print_msg("Not able to set PointColor !") print_msg("Color : " + str(color) + " !") try: if isinstance(color, tuple): Gui.ActiveDocument.getObject(Line_User_Name).LineColor = color except Exception as err: printError_msg(err.message, title="propertiesLine") print_msg("Not able to set LineColor !") print_msg("Color : " + str(color) + " !") try: Gui.ActiveDocument.getObject( Line_User_Name).LineWidth = WF.lineThickness() except Exception as err: printError_msg(err.message, title="propertiesLine") print_msg("Not able to set LineWidth !") try: Gui.ActiveDocument.getObject( Line_User_Name).PointSize = WF.linePointSize() except Exception as err: printError_msg(err.message, title="propertiesLine") print_msg("Not able to set PointSize !") try: Gui.ActiveDocument.getObject(Line_User_Name).Transparency = 0 except Exception as err: printError_msg(err.message, title="propertiesLine") print_msg("Not able to set Transparency !") return
def makeThreePointsPlaneFeature(group): """ Makes a ThreePointsPlane parametric feature object. into the given Group Returns the new object. """ m_name = "ThreePointsPlane_P" m_part = "Part::FeaturePython" try: m_obj = App.ActiveDocument.addObject(str(m_part), str(m_name)) if group is not None: addObjectToGrp(m_obj, group, info=1) ThreePointsPlane(m_obj) ViewProviderThreePointsPlane(m_obj.ViewObject) except Exception as err: printError_msg("Not able to add an object to Model!") printError_msg(err.args[0], title=m_macro) return None return m_obj
def run(): m_sel, m_act_doc = getSel(WF.verbose()) try: Number_of_Curves, Curve_List = m_sel.get_curvesNames( getfrom=["Points","Segments","Curves","Planes","Objects"]) if WF.verbose() != 0: print_msg("Number_of_Curves = " + str(Number_of_Curves)) print_msg("Curve_List = " + str(Curve_List)) if Number_of_Curves == 0: raise Exception(M_EXCEPTION_MSG) try: m_main_dir = "WorkPoints_P" m_sub_dir = "Set" m_group = createFolders(str(m_main_dir)) # Create a sub group if needed if Number_of_Curves > 1 : 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: printError_msg("Could not Create '"+ str(m_sub_dir) +"' Objects Group!") if WF.verbose() != 0: print_msg("Group = " + str(m_group.Label)) for i in range( Number_of_Curves ): edge = Curve_List[i] App.ActiveDocument.openTransaction("Macro CenterCirclePoint") selfobj = makeCenterCirclePointFeature(m_group) selfobj.Edge = edge selfobj.Proxy.execute(selfobj) finally: App.ActiveDocument.commitTransaction() except Exception as err: printError_msg(err.args[0], title="Macro CenterCirclePoint")
def propertiesPoint(Point_User_Name, color=(1.00, 0.67, 0.00)): """ Define the properties of a Work feature Point. PointColor PointSize Transparency """ try: if isinstance(color, tuple): Gui.ActiveDocument.getObject(Point_User_Name).PointColor = color except Exception as err: printError_msg(err.args[0], title="propertiesPoint") print_msg("Not able to set PointColor !") print_msg("Color : " + str(color) + " !") try: Gui.ActiveDocument.getObject( Point_User_Name).PointSize = WF.pointSize() except Exception as err: printError_msg(err.args[0], title="propertiesPoint") print_msg("Not able to set PointSize !") try: Gui.ActiveDocument.getObject(Point_User_Name).Transparency = 0 except Exception as err: printError_msg(err.args[0], title="propertiesPoint") print_msg("Not able to set Transparency !") return
def makeAlongLinePointFeature(group): """ Makes a AlongLinePoint parametric feature object. into the given Group Returns the new object. """ m_name = "AlongLinePoint_P" m_part = "Part::FeaturePython" if group is None: return None try: m_obj = App.ActiveDocument.addObject(str(m_part), str(m_name)) if group is not None: addObjectToGrp(m_obj, group, info=1) AlongLinePoint(m_obj) ViewProviderAlongLinePoint(m_obj.ViewObject) except Exception as err: printError_msg("Not able to add an object to Model!") printError_msg(err.args[0], title=M_MACRO) return None return m_obj
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 makeTwoPointsLineFeatureFromList(selectionset, group): """ Makes a TwoPointsLine parametric feature object from a selection set. into the given Group Returns the new object. """ m_name = "TwoPointsLine_P" m_part = "Part::FeaturePython" if not isinstance(selectionset, list): selectionset = [selectionset] try: m_obj = App.ActiveDocument.addObject(str(m_part), str(m_name)) if group is not None: addObjectToGrp(m_obj, group, info=1) TwoPointsLine(m_obj) ViewProviderTwoPointsLine(m_obj.ViewObject) m_obj.Proxy.addSubobjects(m_obj, selectionset) except Exception as err: printError_msg("Not able to add an object to Model!") printError_msg(err.args[0], title=m_macro) return None return m_obj
def run(): m_sel, m_act_doc = getSel(WF.verbose()) try: Number_of_Planes, Plane_List = m_sel.get_planesNames( getfrom=["Planes", "Objects"]) if WF.verbose(): print_msg("Number_of_Planes = " + str(Number_of_Planes)) print_msg("Plane_List = " + str(Plane_List)) if Number_of_Planes == 0: raise Exception(M_EXCEPTION_MSG) try: m_main_dir = "WorkPoints_P" m_sub_dir = "Set001" m_group = createFolders(str(m_main_dir)) m_error_msg = "Could not Create '" m_error_msg += str(m_sub_dir) + "' Objects Group!" # Create a sub group if needed if Number_of_Planes > 1: 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_Planes): plane = Plane_List[i] App.ActiveDocument.openTransaction(M_MACRO) selfobj = makeCenterFacePointFeature(m_group) selfobj.Face = plane selfobj.Proxy.execute(selfobj) except Exception as err: printError_msg(err.args[0], title=M_MACRO) App.ActiveDocument.commitTransaction() except Exception as err: printError_msg(err.args[0], title=M_MACRO)
def createFolders(folder=None): """ Create WorkFeatures Parametric folders if needed. """ m_main_dir = "WorkFeatures" if not (App.ActiveDocument.getObject(m_main_dir)): try: App.ActiveDocument.addObject("App::DocumentObjectGroup", m_main_dir) except Exception as err: printError_msg(err.args[0], title="createFolders") m_msg = "Could not Create '" + str(m_main_dir) + "' Objects Group!" printError_msg(m_msg) m_list_dirs = [ 'Origin_P', 'WorkPoints_P', 'WorkAxis_P', 'WorkPlanes_P', 'WorkCircles_P', 'WorkArcs_P', 'WorkBoxes_P', 'WorkWires_P', 'WorkImages_P', 'WorkObjects_P', 'Rot_Trans_P' ] m_group = None for m_dir in m_list_dirs: if folder == m_dir: m_group = App.ActiveDocument.getObject(m_main_dir).getObject( str(m_dir)) if not (m_group): try: m_group = App.ActiveDocument.getObject( m_main_dir).newObject("App::DocumentObjectGroup", str(m_dir)) except Exception as err: printError_msg(err.args[0], title="createFolders") m_msg = "Could not Create '" + str(m_dir) m_msg += "' Objects Group!" printError_msg(m_msg) if WF.verbose(): print_msg("Group = " + str(m_group.Label) + " created!") return m_group
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 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)