Created
May 10, 2014 13:00
-
-
Save JMG-SP/c70f1e4e462bc9d13cab to your computer and use it in GitHub Desktop.
WorkFeatures Macro V1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # -*- coding: utf-8 -*- | |
| # FreeCAD Work Features | |
| # (c) 2014 Javier Martínez García | |
| #*************************************************************************** | |
| #* (c) Javier Martínez García 2014 * | |
| #* * | |
| #* This program is free software; you can redistribute it and/or modify * | |
| #* it under the terms of the GNU Lesser General Public License (LGPL) * | |
| #* as published by the Free Software Foundation; either version 2 of * | |
| #* the License, or (at your option) any later version. * | |
| #* for detail see the LICENCE text file. * | |
| #* * | |
| #* This macro is distributed in the hope that it will be useful, * | |
| #* but WITHOUT ANY WARRANTY; without even the implied warranty of * | |
| #* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | |
| #* GNU Lesser General Public License for more details. * | |
| #* * | |
| #* You should have received a copy of the GNU Library General Public * | |
| #* License along with FreeCAD; if not, write to the Free Software * | |
| #* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * | |
| #* USA * | |
| #* * | |
| #***************************************************************************/ | |
| """ | |
| Implemented functions: | |
| -OriginObjects | |
| -WorkPoint: | |
| -MiddPoint | |
| -Center | |
| -FaceCenter | |
| -WorkAxis: | |
| -TwoPoints | |
| -CylinderAxis | |
| -WorkPlane: | |
| -AxisandPoint | |
| -ThreePoints | |
| -PlaneandPoint | |
| """ | |
| import Part | |
| from FreeCAD import Console | |
| from FreeCAD import Base | |
| from FreeCAD import Gui | |
| def OriginObjects(): | |
| try: | |
| # FOLDER CREATOR | |
| if not(App.ActiveDocument.getObject("WorkFeatures")): | |
| App.ActiveDocument.addObject("App::DocumentObjectGroup","WorkFeatures") | |
| if not(App.ActiveDocument.getObject("Origin")): | |
| App.ActiveDocument.getObject("WorkFeatures").newObject("App::DocumentObjectGroup", "Origin") | |
| if not(App.ActiveDocument.getObject("WorkPoints")): | |
| App.ActiveDocument.getObject("WorkFeatures").newObject("App::DocumentObjectGroup", "WorkPoints") | |
| if not(App.ActiveDocument.getObject("WorkAxis")): | |
| App.ActiveDocument.getObject("WorkFeatures").newObject("App::DocumentObjectGroup", "WorkAxis") | |
| if not(App.ActiveDocument.getObject("WorkPlanes")): | |
| App.ActiveDocument.getObject("WorkFeatures").newObject("App::DocumentObjectGroup", "WorkPlanes") | |
| if not(App.ActiveDocument.getObject("Origin_Point")): | |
| Line_Color = (1.00,0.33,0.00) | |
| Shape_Color = (0.00,1.00,0.50) | |
| Transparency = 75 | |
| # Origin | |
| Origin = Base.Vector(0, 0, 0) | |
| Origin_Vertex = Part.Vertex(Origin) | |
| Origin = App.ActiveDocument.addObject("Part::Feature","Origin_Point") | |
| App.ActiveDocument.getObject("Origin").addObject(Origin) | |
| Origin.Shape = Origin_Vertex | |
| Origin_User_Name = Origin.Label | |
| FreeCADGui.ActiveDocument.getObject(Origin_User_Name).PointColor = (0.33, 0.00, 1.00) | |
| FreeCADGui.ActiveDocument.getObject(Origin_User_Name).PointSize = 4.00 | |
| Gui.ActiveDocument.getObject("Origin_Point").Visibility=False | |
| #Work-AxisX | |
| AX_Length = 300 | |
| PX_A = Base.Vector(AX_Length, 0, 0) | |
| PX_B = Base.Vector(-AX_Length, 0, 0) | |
| Axis_X = Part.makeLine(PX_A, PX_B) | |
| Axis = App.ActiveDocument.addObject("Part::Feature","X_Axis") | |
| Axis.Shape = Axis_X | |
| App.ActiveDocument.getObject("Origin").addObject(Axis) | |
| Axis_User_Name = Axis.Label | |
| FreeCADGui.ActiveDocument.getObject(Axis_User_Name).LineColor = (1.00,0.00,0.00) | |
| FreeCADGui.ActiveDocument.getObject(Axis_User_Name).PointColor = (1.00,0.00,0.00) | |
| Gui.ActiveDocument.getObject("X_Axis").Visibility=False | |
| #Work-AxisY | |
| AY_Length = 300 | |
| PY_A = Base.Vector(0, AY_Length, 0) | |
| PY_B = Base.Vector(0, -AY_Length, 0) | |
| Axis_Y = Part.makeLine(PY_A, PY_B) | |
| Axis = App.ActiveDocument.addObject("Part::Feature","Y_Axis") | |
| Axis.Shape = Axis_Y | |
| App.ActiveDocument.getObject("Origin").addObject(Axis) | |
| Axis_User_Name = Axis.Label | |
| FreeCADGui.ActiveDocument.getObject(Axis_User_Name).LineColor = (0.00,0.67,0.00) | |
| FreeCADGui.ActiveDocument.getObject(Axis_User_Name).PointColor = (0.00,0.67,0.00) | |
| Gui.ActiveDocument.getObject("Y_Axis").Visibility=False | |
| #Work-AxisZ | |
| AZ_Length = 300 | |
| PZ_A = Base.Vector(0,0 , AZ_Length) | |
| PZ_B = Base.Vector(0, 0, -AZ_Length) | |
| Axis_Z = Part.makeLine(PZ_A, PZ_B) | |
| Axis = App.ActiveDocument.addObject("Part::Feature","Z_Axis") | |
| Axis.Shape = Axis_Z | |
| App.ActiveDocument.getObject("Origin").addObject(Axis) | |
| Axis_User_Name = Axis.Label | |
| FreeCADGui.ActiveDocument.getObject(Axis_User_Name).LineColor = (0.33,0.00,1.00) | |
| FreeCADGui.ActiveDocument.getObject(Axis_User_Name).PointColor = (0.33,0.00,1.00) | |
| Gui.ActiveDocument.getObject("Z_Axis").Visibility=False | |
| # Work-PlaneXY | |
| PXY_A_SIZE = 300 | |
| PXY_A = Base.Vector(PXY_A_SIZE, PXY_A_SIZE, 0) | |
| PXY_B = PXY_A + Base.Vector(-2.0*PXY_A_SIZE, 0, 0) | |
| PXY_C = PXY_A + Base.Vector(-2.0*PXY_A_SIZE, -2.0*PXY_A_SIZE, 0) | |
| PXY_D = PXY_A + Base.Vector(0, -2.0*PXY_A_SIZE, 0) | |
| PlaneXY_list = [PXY_A, PXY_B, PXY_C, PXY_D, PXY_A] | |
| PlaneXY_wire = Part.makePolygon(PlaneXY_list) | |
| PlaneXY_face = Part.Face(PlaneXY_wire) | |
| PlaneXY = App.ActiveDocument.addObject("Part::Feature", "XY_WPlane") | |
| PlaneXY.Shape = PlaneXY_face | |
| App.ActiveDocument.getObject("Origin").addObject(PlaneXY) | |
| PlaneXY_User_Name = PlaneXY.Label | |
| FreeCADGui.ActiveDocument.getObject(PlaneXY_User_Name).PointColor = Line_Color | |
| FreeCADGui.ActiveDocument.getObject(PlaneXY_User_Name).LineColor = Line_Color | |
| FreeCADGui.ActiveDocument.getObject(PlaneXY_User_Name).ShapeColor = Shape_Color | |
| FreeCADGui.ActiveDocument.getObject(PlaneXY_User_Name).Transparency = Transparency | |
| Gui.ActiveDocument.getObject("XY_WPlane").Visibility=False | |
| # Work-PlaneXY | |
| PXZ_A_SIZE = 300 | |
| PXZ_A = Base.Vector(PXZ_A_SIZE, 0, PXZ_A_SIZE) | |
| PXZ_B = PXZ_A + Base.Vector(-2.0*PXZ_A_SIZE, 0, 0) | |
| PXZ_C = PXZ_A + Base.Vector(-2.0*PXZ_A_SIZE, 0, -2.0*PXZ_A_SIZE) | |
| PXZ_D = PXZ_A + Base.Vector(0, 0, -2.0*PXZ_A_SIZE) | |
| PlaneXZ_list = [PXZ_A, PXZ_B, PXZ_C, PXZ_D, PXZ_A] | |
| PlaneXZ_wire = Part.makePolygon(PlaneXZ_list) | |
| PlaneXZ_face = Part.Face(PlaneXZ_wire) | |
| PlaneXZ = App.ActiveDocument.addObject("Part::Feature", "XZ_WPlane") | |
| PlaneXZ.Shape = PlaneXZ_face | |
| App.ActiveDocument.getObject("Origin").addObject(PlaneXZ) | |
| PlaneXZ_User_Name = PlaneXZ.Label | |
| FreeCADGui.ActiveDocument.getObject(PlaneXZ_User_Name).PointColor = Line_Color | |
| FreeCADGui.ActiveDocument.getObject(PlaneXZ_User_Name).LineColor = Line_Color | |
| FreeCADGui.ActiveDocument.getObject(PlaneXZ_User_Name).ShapeColor = Shape_Color | |
| FreeCADGui.ActiveDocument.getObject(PlaneXZ_User_Name).Transparency = Transparency | |
| Gui.ActiveDocument.getObject("XZ_WPlane").Visibility=False | |
| # Work-PlaneZY | |
| PYZ_A_SIZE = 300 | |
| PYZ_A = Base.Vector(0, PYZ_A_SIZE, PYZ_A_SIZE) | |
| PYZ_B = PYZ_A + Base.Vector(0, -2.0*PYZ_A_SIZE, 0) | |
| PYZ_C = PYZ_A + Base.Vector(0, -2.0*PYZ_A_SIZE, -2.0*PYZ_A_SIZE) | |
| PYZ_D = PYZ_A + Base.Vector(0, 0, -2.0*PYZ_A_SIZE) | |
| PlaneYZ_list = [PYZ_A, PYZ_B, PYZ_C, PYZ_D, PYZ_A] | |
| PlaneYZ_wire = Part.makePolygon(PlaneYZ_list) | |
| PlaneYZ_face = Part.Face(PlaneYZ_wire) | |
| PlaneYZ = App.ActiveDocument.addObject("Part::Feature", "YZ_WPlane") | |
| PlaneYZ.Shape = PlaneYZ_face | |
| App.ActiveDocument.getObject("Origin").addObject(PlaneYZ) | |
| PlaneYZ_User_Name = PlaneYZ.Label | |
| FreeCADGui.ActiveDocument.getObject(PlaneYZ_User_Name).PointColor = Line_Color | |
| FreeCADGui.ActiveDocument.getObject(PlaneYZ_User_Name).LineColor = Line_Color | |
| FreeCADGui.ActiveDocument.getObject(PlaneYZ_User_Name).ShapeColor = Shape_Color | |
| FreeCADGui.ActiveDocument.getObject(PlaneYZ_User_Name).Transparency = Transparency | |
| Gui.ActiveDocument.getObject("YZ_WPlane").Visibility=False | |
| except: | |
| Console.PrintError("Could not Create Origin Objects!") | |
| class WorkPoint(): | |
| def SelectedObjects( self2 ): | |
| MouseSel = Gui.Selection.getSelectionEx() | |
| Selected_Points = [] | |
| Selected_Edges = [] | |
| Selected_Planes = [] | |
| for i in range(len(MouseSel)): | |
| Sel_i_Object = MouseSel[i] | |
| SubObjects_Inside = Sel_i_Object.SubObjects | |
| for n in range(len(SubObjects_Inside)): | |
| SubObject = SubObjects_Inside[n] | |
| if SubObject.ShapeType == "Vertex": | |
| Selected_Points.append(SubObject) | |
| if SubObject.ShapeType == "Edge": | |
| Selected_Edges.append(SubObject) | |
| if SubObject.ShapeType == "Face": | |
| Selected_Planes.append(SubObject) | |
| Number_of_Points = len(Selected_Points) | |
| Number_of_Edges = len(Selected_Edges) | |
| Number_of_Planes = len(Selected_Planes) | |
| Selection = (Number_of_Points, Number_of_Edges, Number_of_Planes, | |
| Selected_Points, Selected_Edges, Selected_Planes) | |
| return Selection | |
| def MiddPoint( self2 ): | |
| try: | |
| SelectedObjects = self2.SelectedObjects() | |
| Number_of_Edges = SelectedObjects[1] | |
| if Number_of_Edges < 1: | |
| Console.PrintError("Select One Edge at Least!") | |
| pass | |
| else: | |
| Edge_List = SelectedObjects[4] | |
| for i in range( Number_of_Edges ): | |
| Vector_A=Edge_List[i].valueAt( 0.0 ) | |
| Vector_B=Edge_List[i].valueAt( Edge_List[i].Length ) | |
| Vector_MidPoint = Vector_B+Vector_A | |
| Vector_MidPoint = Vector_MidPoint.multiply(0.5) | |
| MidPoint_Vertex = Part.Vertex(Vector_MidPoint) | |
| name = "Midpoint" | |
| MidPoint = App.ActiveDocument.addObject( "Part::Feature", name ) | |
| MidPoint.Shape = MidPoint_Vertex | |
| App.ActiveDocument.getObject( "WorkPoints" ).addObject(MidPoint) | |
| MidPoint_User_Name = MidPoint.Label | |
| FreeCADGui.ActiveDocument.getObject( MidPoint_User_Name ).PointColor = ( 0.33, 0.00, 1.00 ) | |
| FreeCADGui.ActiveDocument.getObject( MidPoint_User_Name ).PointSize = 3.00 | |
| except: | |
| Console.PrintError( "ERROR: Unable to Create Points" ) | |
| def Center( self2 ): | |
| try: | |
| SelectedObjects = self2.SelectedObjects() | |
| Number_of_Edges = SelectedObjects[1] | |
| if Number_of_Edges < 1: | |
| Console.PrintError( "Select One Edge at Least!" ) | |
| pass | |
| else: | |
| Edge_List = SelectedObjects[4] | |
| for i in range( Number_of_Edges ): | |
| try: | |
| Edge_List[i].Curve.Radius | |
| Center = Edge_List[i].centerOfCurvatureAt( 0.0 ) | |
| Center_Vertex = Part.Vertex( Center ) | |
| Center = App.ActiveDocument.addObject( "Part::Feature","Center" ) | |
| Center.Shape = Center_Vertex | |
| App.ActiveDocument.getObject( "WorkPoints" ).addObject( Center ) | |
| Center_User_Name = Center.Label | |
| FreeCADGui.ActiveDocument.getObject( Center_User_Name ).PointColor = ( 0.33, 0.00, 1.00 ) | |
| FreeCADGui.ActiveDocument.getObject( Center_User_Name ).PointSize = 3.00 | |
| except: | |
| Console.PrintError("Found One or More Non-Circular Edges") | |
| except: | |
| Console.PrintError("ERROR: Unable to Create Points") | |
| def FaceCenter( self2 ): | |
| try: | |
| SelectedObjects = self2.SelectedObjects() | |
| Number_of_Planes = SelectedObjects[2] | |
| if Number_of_Planes < 1: | |
| Console.PrintError( "Select One Fase or Plane at Least!" ) | |
| pass | |
| else: | |
| Plane_List = SelectedObjects[5] | |
| for i in range( Number_of_Planes ): | |
| try: | |
| Selected_Plane = Plane_List[i] | |
| Plane_Center_Point = Selected_Plane.CenterOfMass | |
| Plane_Center_Point = Part.Vertex( Plane_Center_Point ) | |
| Gui_Center = App.ActiveDocument.addObject( "Part::Feature","FaceCenter" ) | |
| Gui_Center.Shape = Plane_Center_Point | |
| App.ActiveDocument.getObject( "WorkPoints" ).addObject( Gui_Center ) | |
| Plane_Center_User_Name = Gui_Center.Label | |
| FreeCADGui.ActiveDocument.getObject( Plane_Center_User_Name ).PointColor = ( 0.33, 0.00, 1.00 ) | |
| FreeCADGui.ActiveDocument.getObject( Plane_Center_User_Name ).PointSize = 3.00 | |
| except: | |
| Console.PrintError("Non Planar Surface") | |
| except: | |
| Console.PrintError("ERROR: Unable to Create Points") | |
| class WorkAxis(): | |
| def SelectedObjects( self3 ): | |
| MouseSel = Gui.Selection.getSelectionEx() | |
| Selected_Points = [] | |
| Selected_Edges = [] | |
| Selected_Planes = [] | |
| for i in range(len(MouseSel)): | |
| Sel_i_Object = MouseSel[i] | |
| SubObjects_Inside = Sel_i_Object.SubObjects | |
| for n in range(len(SubObjects_Inside)): | |
| SubObject = SubObjects_Inside[n] | |
| if SubObject.ShapeType == "Vertex": | |
| Selected_Points.append(SubObject) | |
| if SubObject.ShapeType == "Edge": | |
| Selected_Edges.append(SubObject) | |
| if SubObject.ShapeType == "Face": | |
| Selected_Planes.append(SubObject) | |
| Number_of_Points = len(Selected_Points) | |
| Number_of_Edges = len(Selected_Edges) | |
| Number_of_Planes = len(Selected_Planes) | |
| Selection = (Number_of_Points, Number_of_Edges, Number_of_Planes, | |
| Selected_Points, Selected_Edges, Selected_Planes) | |
| return Selection | |
| def TwoPoints( self3 ): | |
| try: | |
| SelectedObjects = self3.SelectedObjects() | |
| Number_of_Points= SelectedObjects[0] | |
| if Number_of_Points != 2: | |
| Console.PrintError("Select Two Points Only!") | |
| pass | |
| else: | |
| Point_List = SelectedObjects[3] | |
| Axis_A = Point_List[0].Point | |
| Axis_B = Point_List[1].Point | |
| Axis_dir = Axis_B - Axis_A | |
| Axis_E1 = Axis_B + Axis_dir.multiply(0.1) | |
| Axis_E2 = Axis_A - Axis_dir.multiply(0.9) | |
| Axis_feature = Part.makeLine(Axis_E1, Axis_E2) | |
| if not(App.ActiveDocument.getObject("WorkAxis")): | |
| App.ActiveDocument.addObject("App::DocumentObjectGroup","WorkAxis") | |
| name = "Axis" | |
| Axis = App.ActiveDocument.addObject("Part::Feature",name) | |
| Axis.Shape = Axis_feature | |
| App.ActiveDocument.getObject("WorkAxis").addObject(Axis) | |
| Axis_User_Name = Axis.Label | |
| FreeCADGui.ActiveDocument.getObject(Axis_User_Name).LineColor = (1.00,0.67,0.00) | |
| FreeCADGui.ActiveDocument.getObject(Axis_User_Name).PointColor = (1.00,0.67,0.00) | |
| except: | |
| Console.PrintError("Error: Unable to Create Axis") | |
| def CylinderAxis( self3 ): | |
| try: | |
| Selected_Objects = self3.SelectedObjects() | |
| Number_of_Faces= Selected_Objects[2] | |
| if Number_of_Faces != 1: | |
| Console.PrintError("Select One Cylindrical Face Only") | |
| pass | |
| else: | |
| Face_list = Selected_Objects[5] | |
| Face = Face_list[0] | |
| Face_Wire = Face.OuterWire | |
| Face_Edges = Face_Wire.Edges | |
| try: | |
| for i in range(len(Face_Edges)): | |
| Current_Edge = Face_Edges[i] | |
| Edge_Info = Current_Edge.Curve | |
| Edge_Type_Name = str(Edge_Info) | |
| Edge_Circle = Edge_Type_Name[0:6] | |
| Edge_Line = Edge_Type_Name[1:5] | |
| if Edge_Circle == "Circle": | |
| Circle_Axis = Current_Edge.Curve.Axis | |
| Circle_Axis = Circle_Axis.normalize() | |
| Circle_Center = Current_Edge.Curve.Center | |
| Circle_Radius = Current_Edge.Curve.Radius | |
| if Edge_Line == "Line": | |
| Line_Start = Current_Edge.Curve.StartPoint | |
| Line_End = Current_Edge.Curve.EndPoint | |
| Edge_Length = ( Line_End - Line_Start ).Length | |
| except: | |
| Console.PrintError("Non Valid Cylinder") | |
| Axis_E1 = Circle_Center + Circle_Axis.multiply( Circle_Radius*0.5 ) | |
| Circle_Axis = Circle_Axis.normalize() | |
| Axis_E2 = Circle_Center - Circle_Axis.multiply( Edge_Length ) | |
| Circle_Axis = Circle_Axis.normalize() | |
| Axis_E2 = Axis_E2 - Circle_Axis.multiply( Circle_Radius*0.5 ) | |
| Axis_feature = Part.makeLine(Axis_E1, Axis_E2) | |
| Axis = App.ActiveDocument.addObject( "Part::Feature", "WorkAxis" ) | |
| Axis.Shape = Axis_feature | |
| App.ActiveDocument.getObject("WorkAxis").addObject(Axis) | |
| Axis_User_Name = Axis.Label | |
| FreeCADGui.ActiveDocument.getObject(Axis_User_Name).LineColor = (1.00,0.67,0.00) | |
| FreeCADGui.ActiveDocument.getObject(Axis_User_Name).PointColor = (1.00,0.67,0.00) | |
| except: | |
| Console.PrintError("Error: Unable to Create Axis") | |
| class WorkPlane(): | |
| def SelectedObjects( self4 ): | |
| MouseSel = Gui.Selection.getSelectionEx() | |
| Selected_Points = [] | |
| Selected_Edges = [] | |
| Selected_Planes = [] | |
| for i in range(len(MouseSel)): | |
| Sel_i_Object = MouseSel[i] | |
| SubObjects_Inside = Sel_i_Object.SubObjects | |
| for n in range(len(SubObjects_Inside)): | |
| SubObject = SubObjects_Inside[n] | |
| if SubObject.ShapeType == "Vertex": | |
| Selected_Points.append(SubObject) | |
| if SubObject.ShapeType == "Edge": | |
| Selected_Edges.append(SubObject) | |
| if SubObject.ShapeType == "Face": | |
| Selected_Planes.append(SubObject) | |
| Number_of_Points = len(Selected_Points) | |
| Number_of_Edges = len(Selected_Edges) | |
| Number_of_Planes = len(Selected_Planes) | |
| Selection = (Number_of_Points, Number_of_Edges, Number_of_Planes, | |
| Selected_Points, Selected_Edges, Selected_Planes) | |
| return Selection | |
| def AxisandPoint( self4 ): | |
| try: | |
| SelectedObjects = self4.SelectedObjects() | |
| Number_of_Points = SelectedObjects[0] | |
| Number_of_Edges = SelectedObjects[1] | |
| if Number_of_Points != 1 and Number_of_Edges != 1: | |
| Console.PrintError( "Select One Edge and One Point Only" ) | |
| pass | |
| else: | |
| Points_List = SelectedObjects[3] | |
| Edge_List = SelectedObjects[4] | |
| Point_C = Points_List[0].Point | |
| Point_A = Edge_List[0].valueAt(0.0) | |
| Point_B = Edge_List[0].valueAt(Edge_List[0].Length) | |
| Edge_Vector = Point_B - Point_A | |
| Edge_Length = Edge_List[0].Length | |
| AC_Vector = Point_C - Point_A | |
| Plane_Point = Point_C | |
| Plane_Normal = Edge_Vector.cross( AC_Vector ) | |
| Plane_face = Part.makePlane( Edge_Length*1.4, Edge_Length*1.4, Plane_Point, Plane_Normal ) | |
| Plane_Center = Plane_face.CenterOfMass | |
| Plane_Translate = Edge_List[0].valueAt(Edge_Length*0.5) - Plane_Center | |
| Plane_face.translate( Plane_Translate ) | |
| Plane = App.ActiveDocument.addObject( "Part::Feature", "WorkPlane" ) | |
| Plane.Shape = Plane_face | |
| App.ActiveDocument.getObject( "WorkPlanes" ).addObject( Plane ) | |
| Plane_User_Name = Plane.Label | |
| FreeCADGui.ActiveDocument.getObject( Plane_User_Name ).PointColor = (1.00,0.67,0.00) | |
| FreeCADGui.ActiveDocument.getObject( Plane_User_Name ).LineColor = (1.00,0.67,0.00) | |
| FreeCADGui.ActiveDocument.getObject( Plane_User_Name ).ShapeColor = (0.00,0.33,1.00) | |
| FreeCADGui.ActiveDocument.getObject( Plane_User_Name ).Transparency = 75 | |
| except: | |
| Console.PrintError( "Error: Unable to Create Axis" ) | |
| def ThreePoints( self4 ): | |
| try: | |
| SelectedObjects = self4.SelectedObjects() | |
| Number_of_Points = SelectedObjects[0] | |
| if Number_of_Points != 3 : | |
| Console.PrintError( "Select Three Points Only" ) | |
| pass | |
| else: | |
| Points_List = SelectedObjects[3] | |
| Point_A = Points_List[0].Point | |
| Point_B = Points_List[1].Point | |
| Point_C = Points_List[2].Point | |
| Edge_Vector = Point_B - Point_A | |
| Edge_Length = Edge_Vector.Length | |
| AC_Vector = Point_C - Point_A | |
| Plane_Point = Point_C | |
| Plane_Normal = Edge_Vector.cross( AC_Vector ) | |
| Plane_face = Part.makePlane( Edge_Length*1.4, Edge_Length*1.4, Plane_Point, Plane_Normal ) | |
| Plane_Center = Plane_face.CenterOfMass | |
| Plane_Translate = Point_A + Edge_Vector.multiply(0.5) - Plane_Center | |
| Plane_face.translate( Plane_Translate ) | |
| Plane = App.ActiveDocument.addObject( "Part::Feature", "WorkPlane" ) | |
| Plane.Shape = Plane_face | |
| App.ActiveDocument.getObject( "WorkPlanes" ).addObject( Plane ) | |
| Plane_User_Name = Plane.Label | |
| FreeCADGui.ActiveDocument.getObject( Plane_User_Name ).PointColor = (1.00,0.67,0.00) | |
| FreeCADGui.ActiveDocument.getObject( Plane_User_Name ).LineColor = (1.00,0.67,0.00) | |
| FreeCADGui.ActiveDocument.getObject( Plane_User_Name ).ShapeColor = (0.00,0.33,1.00) | |
| FreeCADGui.ActiveDocument.getObject( Plane_User_Name ).Transparency = 75 | |
| except: | |
| Console.PrintError( "Error: Unable to Create Axis" ) | |
| def PlaneandPoint( self4 ): | |
| try: | |
| SelectedObjects = self4.SelectedObjects() | |
| Number_of_Points = SelectedObjects[0] | |
| Number_of_Planes = SelectedObjects[2] | |
| if Number_of_Points != 1 and Number_of_Planes != 1: | |
| Console.PrintError( "Select One Plane and One Point Only" ) | |
| pass | |
| else: | |
| Points_List = SelectedObjects[3] | |
| Plane_List = SelectedObjects[5] | |
| Point_C = Points_List[0].Point | |
| Reference_Plane = Plane_List[0] | |
| Edge_Length = Reference_Plane.Length / 4.0 | |
| Plane_Normal = Reference_Plane.normalAt(0,0) | |
| Plane_Point = Point_C | |
| Plane_face = Part.makePlane( Edge_Length, Edge_Length, Plane_Point, Plane_Normal ) | |
| Plane_Center = Plane_face.CenterOfMass | |
| Plane_Translate = Plane_Point - Plane_Center | |
| Plane_face.translate( Plane_Translate ) | |
| Plane = App.ActiveDocument.addObject( "Part::Feature", "WorkPlane" ) | |
| Plane.Shape = Plane_face | |
| App.ActiveDocument.getObject( "WorkPlanes" ).addObject( Plane ) | |
| Plane_User_Name = Plane.Label | |
| FreeCADGui.ActiveDocument.getObject( Plane_User_Name ).PointColor = (1.00,0.67,0.00) | |
| FreeCADGui.ActiveDocument.getObject( Plane_User_Name ).LineColor = (1.00,0.67,0.00) | |
| FreeCADGui.ActiveDocument.getObject( Plane_User_Name ).ShapeColor = (0.00,0.33,1.00) | |
| FreeCADGui.ActiveDocument.getObject( Plane_User_Name ).Transparency = 75 | |
| except: | |
| Console.PrintError( "Error: Unable to Create Axis" ) | |
| OriginObjects() | |
| WorkPoint = WorkPoint() | |
| WorkAxis = WorkAxis() | |
| WorkPlane = WorkPlane() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment