Пример #1
0
 def onDelete(self, arg1=None, arg2=None):
     '''this makes sure that the base operation is added back to the project and visible'''
     FreeCADGui.ActiveDocument.getObject(
         arg1.Object.Base.Name).Visibility = True
     P.addToProject(arg1.Object.Base)
     arg1.Object.Base = None
     return True
Пример #2
0
    def Create():
        obj = FreeCAD.ActiveDocument.addObject("Path::FeaturePython","Machine")
        Machine(obj)
        _ViewProviderMachine(obj.ViewObject)

        PathUtils.addToProject(obj)

        UnitParams = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Units")
        if UnitParams.GetInt('UserSchema') == 0:
            obj.MachineUnits = 'Metric'
            #metric mode
        else:
            obj.MachineUnits = 'Inch'

        obj.ViewObject.ShowFirstRapid = False
        return obj
Пример #3
0
    def Activated(self):
        
        # check that the selection contains exactly what we want
        selection = FreeCADGui.Selection.getSelectionEx()
        if len(selection) != 1:
            FreeCAD.Console.PrintError(translate("Path_Pocket","Please select an edges loop from one object, or a single face\n"))
            return
        if len(selection[0].SubObjects) == 0:
            FreeCAD.Console.PrintError(translate("Path_Pocket","Please select an edges loop from one object, or a single face\n"))
            return
        for s in selection[0].SubObjects:
            if s.ShapeType != "Edge":
                if (s.ShapeType != "Face") or (len(selection[0].SubObjects) != 1):
                    FreeCAD.Console.PrintError(translate("Path_Pocket","Please select only edges or a single face\n"))
                    return
        if selection[0].SubObjects[0].ShapeType == "Edge":
            try:
                import Part
                w = Part.Wire(selection[0].SubObjects)
            except:
                FreeCAD.Console.PrintError(translate("Path_Pocket","The selected edges don't form a loop\n"))
                return
        
        # if everything is ok, execute and register the transaction in the undo/redo stack
        FreeCAD.ActiveDocument.openTransaction(translate("Path_Pocket","Create Pocket"))
        FreeCADGui.addModule("PathScripts.PathPocket")
        FreeCADGui.doCommand('prjexists = False')
        FreeCADGui.doCommand('obj = FreeCAD.ActiveDocument.addObject("Path::FeaturePython","Pocket")')
        FreeCADGui.doCommand('PathScripts.PathPocket.ObjectPocket(obj)')
        FreeCADGui.doCommand('PathScripts.PathPocket.ViewProviderPocket(obj.ViewObject)')
        subs = "["
        for s in selection[0].SubElementNames:
            subs += '"' + s + '",'
        subs += "]"
        FreeCADGui.doCommand('obj.Base = (FreeCAD.ActiveDocument.' + selection[0].ObjectName + ',' + subs + ')')
        FreeCADGui.doCommand('obj.Active = True')
        snippet = '''
from PathScripts import PathUtils
PathUtils.addToProject(obj)

ZMax = obj.Base[0].Shape.BoundBox.ZMax
ZMin = obj.Base[0].Shape.BoundBox.ZMin
obj.StepDown = 1.0
obj.StartDepth = ZMax
obj.FinalDepth = ZMin
obj.ClearanceHeight =  ZMax + 5.0
    
'''
        FreeCADGui.doCommand(snippet)
        FreeCAD.ActiveDocument.commitTransaction()
        FreeCAD.ActiveDocument.recompute()
Пример #4
0
    def Activated(self):
        import Path
        import Part

        from PathScripts import PathUtils, PathDrilling, PathProject
        prjexists = False
        selection = FreeCADGui.Selection.getSelectionEx()

        if not selection:
            return
        # if everything is ok, execute and register the transaction in the undo/redo stack
        FreeCAD.ActiveDocument.openTransaction(
            translate("Path_Drilling", "Create Drilling"))
        FreeCADGui.addModule("PathScripts.PathDrilling")

        obj = FreeCAD.ActiveDocument.addObject("Path::FeaturePython",
                                               "Drilling")
        PathDrilling.ObjectDrilling(obj)

        myList = obj.locations
        for sub in selection:
            for point in sub.SubObjects:
                if isinstance(point, Part.Vertex):
                    myList.append(FreeCAD.Vector(point.X, point.Y, point.Z))
                if isinstance(point, Part.Edge):
                    if isinstance(point.Curve, Part.Circle):
                        center = point.Curve.Center
                        myList.append(
                            FreeCAD.Vector(center.x, center.y, center.z))

        obj.locations = myList

        PathDrilling._ViewProviderDrill(obj.ViewObject)
        #        obj.ViewObject.Proxy = 0
        obj.Active = True

        project = PathUtils.addToProject(obj)

        tl = PathUtils.changeTool(obj, project)
        if tl:
            obj.ToolNumber = tl

        FreeCAD.ActiveDocument.commitTransaction()
        FreeCAD.ActiveDocument.recompute()
Пример #5
0
    def Activated(self):
        import Path
        import Part

        from PathScripts import PathUtils,PathDrilling,PathProject
        prjexists = False
        selection = FreeCADGui.Selection.getSelectionEx()

        if not selection:
            return
        # if everything is ok, execute and register the transaction in the undo/redo stack
        FreeCAD.ActiveDocument.openTransaction(translate("PathDrilling","Create Drilling"))
        FreeCADGui.addModule("PathScripts.PathDrilling")
        
        obj = FreeCAD.ActiveDocument.addObject("Path::FeaturePython","Drilling")
        PathDrilling.ObjectDrilling(obj)

        myList = obj.locations
        for sub in selection:
            for point in sub.SubObjects:
                if isinstance(point,Part.Vertex):
                    myList.append(FreeCAD.Vector(point.X, point.Y, point.Z))
                if isinstance(point,Part.Edge):
                    if isinstance(point.Curve,Part.Circle):
                        center = point.Curve.Center
                        myList.append(FreeCAD.Vector(center.x,center.y,center.z))
        
        obj.locations = myList

        PathDrilling._ViewProviderDrill(obj.ViewObject)
#        obj.ViewObject.Proxy = 0
        obj.Active = True
       
        project = PathUtils.addToProject(obj)

        tl = PathUtils.changeTool(obj,project)
        if tl:
            obj.ToolNumber = tl

        FreeCAD.ActiveDocument.commitTransaction()
        FreeCAD.ActiveDocument.recompute()
Пример #6
0
 def onDelete(self, arg1=None, arg2=None):
     FreeCADGui.ActiveDocument.getObject(
         arg1.Object.Base.Name).Visibility = True
     P.addToProject(arg1.Object.Base)
     return True
 def onDelete(self, arg1=None, arg2=None):
     '''this makes sure that the base operation is added back to the project and visible'''
     FreeCADGui.ActiveDocument.getObject(arg1.Object.Base.Name).Visibility = True
     P.addToProject(arg1.Object.Base)
     return True
Пример #8
0
 def onDelete(self, arg1=None, arg2=None):
     FreeCADGui.ActiveDocument.getObject(arg1.Object.Base.Name).Visibility = True
     P.addToProject(arg1.Object.Base)
     return True
Пример #9
0
    def Activated(self):
        import Path
        from PathScripts import PathUtils, PathProfile, PathProject
        prjexists = False
        selection = PathSelection.multiSelect()

        if not selection:
            return

        # if everything is ok, execute and register the transaction in the undo/redo stack
        FreeCAD.ActiveDocument.openTransaction(
            translate("PathProfile", "Create Profile"))
        FreeCADGui.addModule("PathScripts.PathProfile")

        obj = FreeCAD.ActiveDocument.addObject("Path::FeaturePython",
                                               "Profile")
        PathProfile.ObjectProfile(obj)
        PathProfile.ViewProviderProfile(obj.ViewObject)

        obj.Base = (FreeCAD.ActiveDocument.getObject(selection['objname']))

        if selection['facenames']:
            #FreeCAD.Console.PrintMessage('There are edges selected\n')
            obj.Face1 = (FreeCAD.ActiveDocument.getObject(
                selection['objname']), selection['facenames'][0])
            if len(selection['facenames']) > 1:
                obj.Face2 = (FreeCAD.ActiveDocument.getObject(
                    selection['objname']), selection['facenames'][-1])

        if selection['edgenames']:
            #FreeCAD.Console.PrintMessage('There are edges selected\n')

            obj.Edge1 = (FreeCAD.ActiveDocument.getObject(
                selection['objname']), (selection['edgenames'][0]))
            if len(selection['edgenames']) > 1:
                obj.Edge2 = (FreeCAD.ActiveDocument.getObject(
                    selection['objname']), (selection['edgenames'][-1]))

        if selection['pointlist']:
            FreeCADGui.doCommand('from FreeCAD import Vector')
            stptX, stptY, stptZ = selection['pointlist'][0].X, selection[
                'pointlist'][0].Y, selection['pointlist'][0].Z
            obj.StartPoint = Vector((stptX), (stptY), (stptZ))
            if len(
                    selection['pointlist']
            ) > 1:  # we have more than one point so we have an end point
                endptX, endptY, endptZ = selection['pointlist'][
                    -1].X, selection['pointlist'][-1].Y, selection[
                        'pointlist'][-1].Z
                obj.EndPoint = Vector(endptX, endptY, endptZ)
        if selection['pathwire'].isClosed():
            obj.PathClosed = True
            if selection['clockwise']:
                obj.Side = "Left"
                obj.Direction = "CW"
            elif selection['clockwise'] == False:
                obj.Side = "Right"
                obj.Direction = "CCW"
        else:
            obj.Side = "On"
            obj.Direction = "CCW"
            obj.PathClosed = False

        ZMax = obj.Base[0].Shape.BoundBox.ZMax
        ZMin = obj.Base[0].Shape.BoundBox.ZMin
        obj.StepDown.Value = 1.0
        obj.StartDepth.Value = ZMax - obj.StepDown.Value
        obj.FinalDepth.Value = ZMin - 1.0
        obj.ClearanceHeight.Value = ZMax + 5.0
        obj.SegLen.Value = 0.5
        obj.Active = True
        obj.ViewObject.ShowFirstRapid = False

        project = PathUtils.addToProject(obj)

        tl = PathUtils.changeTool(obj, project)
        if tl:
            obj.ToolNumber = tl

        FreeCAD.ActiveDocument.commitTransaction()
        FreeCAD.ActiveDocument.recompute()
Пример #10
0
    def Activated(self):
        import Path
        from PathScripts import PathUtils,PathProfile,PathProject
        prjexists = False
        selection = PathSelection.multiSelect()

        if not selection:
            return

        # if everything is ok, execute and register the transaction in the undo/redo stack
        FreeCAD.ActiveDocument.openTransaction(translate("Path_Profile","Create Profile"))
        FreeCADGui.addModule("PathScripts.PathProfile")

        obj = FreeCAD.ActiveDocument.addObject("Path::FeaturePython","Profile")
        PathProfile.ObjectProfile(obj)
        PathProfile.ViewProviderProfile(obj.ViewObject)

        obj.Base = (FreeCAD.ActiveDocument.getObject(selection['objname']))

        if selection['facenames']:
            #FreeCAD.Console.PrintMessage('There are edges selected\n')
            obj.Face1 = (FreeCAD.ActiveDocument.getObject(selection['objname']),selection['facenames'][0])
            if len(selection['facenames'])>1:
                obj.Face2 = (FreeCAD.ActiveDocument.getObject(selection['objname']),selection['facenames'][-1])

        if selection['edgenames']:
            #FreeCAD.Console.PrintMessage('There are edges selected\n')
            
            obj.Edge1 =(FreeCAD.ActiveDocument.getObject(selection['objname']),(selection['edgenames'][0]))
            if len(selection['edgenames'])>1:
                obj.Edge2 =(FreeCAD.ActiveDocument.getObject(selection['objname']),(selection['edgenames'][-1]))

        if selection['pointlist']:
            FreeCADGui.doCommand('from FreeCAD import Vector')
            stptX, stptY, stptZ = selection['pointlist'][0].X, selection['pointlist'][0].Y, selection['pointlist'][0].Z
            obj.StartPoint = Vector((stptX),(stptY),(stptZ))
            if len(selection['pointlist'])>1: # we have more than one point so we have an end point
                endptX, endptY, endptZ = selection['pointlist'][-1].X, selection['pointlist'][-1].Y, selection['pointlist'][-1].Z
                obj.EndPoint = Vector(endptX,endptY,endptZ)
        if selection['pathwire'].isClosed():
            obj.PathClosed = True
            if selection['clockwise']:
                obj.Side = "Left"
                obj.Direction = "CW"
            elif selection['clockwise'] == False: 
                obj.Side = "Right"
                obj.Direction = "CCW"
        else:
            obj.Side = "On"
            obj.Direction = "CCW"
            obj.PathClosed = False

        ZMax = obj.Base[0].Shape.BoundBox.ZMax
        ZMin = obj.Base[0].Shape.BoundBox.ZMin
        obj.StepDown.Value = 1.0
        obj.StartDepth.Value = ZMax- obj.StepDown.Value
        obj.FinalDepth.Value = ZMin-1.0
        obj.ClearanceHeight.Value =  ZMax + 5.0
        obj.SegLen.Value = 0.5
        obj.Active = True
        obj.ViewObject.ShowFirstRapid = False

        project = PathUtils.addToProject(obj)

        tl = PathUtils.changeTool(obj,project)
        if tl:
            obj.ToolNumber = tl

        FreeCAD.ActiveDocument.commitTransaction()
        FreeCAD.ActiveDocument.recompute()