Ejemplo n.º 1
0
    def Activated(self):
        try:
            s = Gui.Selection.getSelectionEx()
            if (len(s) < 2):
                # Two object must be selected
                errMessage = "Select two or more objects to use Magnet Tool"
                faced.getInfo(s).errorDialog(errMessage)
                return
            sub1 = Gui.Selection.getSelectionEx()[0]
            sub2 = Gui.Selection.getSelectionEx()[1]
            face1 = faced.getInfo(sub1).getObjectFromFaceName(
                sub1.SubElementNames[0])
            face2 = faced.getInfo(sub2).getObjectFromFaceName(
                sub2.SubElementNames[0])

            sub2.Object.Placement.Base = face1.CenterOfMass
            sub2.Object.Placement.Rotation = face1.Faces[0].Surface.Rotation
            sub2.Object.Placement.Rotation.Q = face1.Faces[
                0].Surface.Rotation.Q
            App.ActiveDocument.recompute()
        except Exception as err:
            App.Console.PrintError("'Magnet' Failed. "
                                   "{err}\n".format(err=str(err)))
            exc_type, exc_obj, exc_tb = sys.exc_info()
            fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
            print(exc_type, fname, exc_tb.tb_lineno)
Ejemplo n.º 2
0
 def Activated(self):
     try:
         s = Gui.Selection.getSelectionEx()
         if (len(s) < 1):
             # Two object must be selected
             errMessage = "Select two or more objects to use Shell Tool"
             faced.getInfo(s).errorDialog(errMessage)
             return
         App.ActiveDocument.openTransaction(
             translate("Design456", "Part Shell"))
         thickness = QtGui.QInputDialog.getDouble(None, "Thickness",
                                                  "Value:", 0, -1000.0,
                                                  1000.0, 2)[0]
         if (thickness == 0):
             return  # Nothing to do
         allObjects = []
         for o in s:
             allObjects.append(App.ActiveDocument.getObject(o.ObjectName))
         currentObj = App.ActiveDocument.getObject(s[0].ObjectName)
         currentObjLink = currentObj.getLinkedObject(True)
         thickObj = App.ActiveDocument.addObject("Part::Thickness",
                                                 "Thickness")
         thickObj.Value = thickness
         thickObj.Join = 0
         thickObj.Mode = 0
         thickObj.Intersection = False
         thickObj.SelfIntersection = False
         getfacename = faced.getInfo(s[0]).getFaceName()
         thickObj.Faces = (
             currentObj,
             getfacename,
         )
         if thickObj.isValid() == False:
             App.ActiveDocument.removeObject(thickObj.Name)
             # Shape is not OK
             errMessage = "Failed create shell"
             faced.getInfo(s).errorDialog(errMessage)
         else:
             App.ActiveDocument.recompute()
             NewJ = App.ActiveDocument.addObject(
                 'Part::Feature', 'Shell').Shape = thickObj.Shape
             App.ActiveDocument.recompute()
             # Remove Old objects
             for obj in allObjects:
                 App.ActiveDocument.removeObject(obj.Name)
             App.ActiveDocument.removeObject(thickObj.Name)
         App.ActiveDocument.commitTransaction()  #undo reg.
         App.ActiveDocument.recompute()
         del allObjects[:]
     except Exception as err:
         App.Console.PrintError("'Part::Shell' Failed. "
                                "{err}\n".format(err=str(err)))
         exc_type, exc_obj, exc_tb = sys.exc_info()
         fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
         print(exc_type, fname, exc_tb.tb_lineno)
Ejemplo n.º 3
0
    def Activated(self):
        try:
            s = Gui.Selection.getSelectionEx()

            if len(s) < 1:
                # several selections - Error
                errMessage = "Select a line or a point to extend."
                faced.getInfo(s).errorDialog(errMessage)
                return
            sel = s[0]
            _type = faced.getInfo(sel).selectedObjectType()
            if not (_type == 'Wire' or _type == 'Line'):
                print(_type)
                print("Wrong object selected")
                return  # Not supported yet.
                # TODO: Is it necessary to extend Arc, Square ..etc shapes? Don't know now
            # User decided where to extend the line.
            # Otherwise we extend the line only to the end of the line
            VertPoint = None
            if hasattr(sel.SubObjects[0], 'Point'):
                VertPoint = sel.SubObjects[0].Point
            elif hasattr(sel.SubObjects[0], 'Edges'):
                _point = sel.SubObjects[0].Vertexes[1].Point
                VertPoint = sel.SubObjects[0].Vertexes[1].Point  # last point
            newPoint = []
            _point = sel.Object.Points
            positionSave = 0

            for i in _point:
                newPoint.append(App.Vector(i))
                if VertPoint == i:
                    positionSave = newPoint.index(i)
            if VertPoint == newPoint[len(newPoint) - 1]:
                # add last point and then moved
                newPoint.append(App.Vector(newPoint[len(newPoint) - 1]))
                sel.Object.Points = newPoint
                sel.Object.End = VertPoint
            elif positionSave == 0:
                # add last point and then

                newPoint.insert(0, App.Vector(VertPoint))
                sel.Object.Points = newPoint
                sel.Object.Start = VertPoint
            _view = Gui.ActiveDocument.ActiveView

            faced.mousePointMove(sel, _view)
            del newPoint[:]

        except Exception as err:
            App.Console.PrintError("'Extend' Failed. "
                                   "{err}\n".format(err=str(err)))
            exc_type, exc_obj, exc_tb = sys.exc_info()
            fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
            print(exc_type, fname, exc_tb.tb_lineno)
Ejemplo n.º 4
0
    def Activated(self):
        try:
            oneObject = False
            selected = Gui.Selection.getSelectionEx()
            selectedOne1 = Gui.Selection.getSelectionEx()[0]
            selectedOne2 = Gui.Selection.getSelectionEx()[0]
            selectedOne3 = Gui.Selection.getSelectionEx()[0]
            allSelected = []
            if ((len(selected) < 3 or len(selected) > 3)
                    and (selectedOne1.HasSubObjects == False
                         or selectedOne2.HasSubObjects == False
                         or selectedOne3.HasSubObjects == False)):
                # Two object must be selected
                errMessage = "Select two or more objects to useArc3Points Tool"
                faced.getInfo(selected).errorDialog(errMessage)
                return
            if selectedOne1.HasSubObjects and len(selected) == 1:
                # We have only one object that we take vertices from
                oneObject = True
                subObjects = selected[0].SubObjects
                for n in subObjects:
                    allSelected.append(n.Point)
            elif len(selected) == 3:
                for t in selected:
                    allSelected.append(
                        t.Object.Shape.Vertexes[0].Placement.Base)
                    print(len(allSelected))
            else:
                oneObject = False
                print("A combination of objects")
                print("Not implemented")
                return
            C1 = _part.Arc(App.Vector(allSelected[0]),
                           App.Vector(allSelected[1]),
                           App.Vector(allSelected[2]))
            S1 = _part.Shape([C1])
            W = _part.Wire(S1.Edges)
            _part.show(W)
            App.ActiveDocument.recompute()
            App.ActiveDocument.ActiveObject.Label = "Arc_3_Points"
            # Remove only if it is not one object
            if oneObject == False:
                for n in selected:
                    App.ActiveDocument.removeObject(n.ObjectName)
            del allSelected[:]
            App.ActiveDocument.recompute()

        except Exception as err:
            App.Console.PrintError("'Arc3Points' Failed. "
                                   "{err}\n".format(err=str(err)))
            exc_type, exc_obj, exc_tb = sys.exc_info()
            fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
            print(exc_type, fname, exc_tb.tb_lineno)
Ejemplo n.º 5
0
 def Activated(self):
     try:
         s = Gui.Selection.getSelectionEx()
         if (len(s) < 2):
             # Two object must be selected
             errMessage = "Select two or more objects to Subtract"
             faced.getInfo(s).errorDialog(errMessage)
             return
         App.ActiveDocument.openTransaction(
             translate("Design456", "Part Subtract"))
         newObj = App.ActiveDocument.addObject("Part::Cut", "tempSubtract")
         newObj.Base = App.ActiveDocument.getObject(
             s[0].ObjectName)  # Target
         newObj.Tool = App.ActiveDocument.getObject(
             s[1].ObjectName)  # Subtracted shape/object
         App.ActiveDocument.recompute()
         newObj.Refine = True
         App.ActiveDocument.recompute()
         # Make a simple copy
         newShape = Part.getShape(newObj,
                                  '',
                                  needSubElement=False,
                                  refine=False)
         NewJ = App.ActiveDocument.addObject('Part::Feature',
                                             'Subtract').Shape = newShape
         App.ActiveDocument.recompute()
         if newObj.isValid() == False:
             App.ActiveDocument.removeObject(NewJ.Name)
             # Shape is not OK
             errMessage = "Failed to subtract objects"
             faced.getInfo(s).errorDialog(errMessage)
         else:
             # Remove Old objects
             allObjects = []
             for o in s:
                 allObjects.append(
                     App.ActiveDocument.getObject(o.ObjectName))
             for obj in allObjects:
                 App.ActiveDocument.removeObject(obj.Name)
             App.ActiveDocument.removeObject(newObj.Name)
         App.ActiveDocument.commitTransaction()  #undo reg.
         App.ActiveDocument.recompute()
         del allObjects[:]
     except Exception as err:
         App.Console.PrintError("'Part::Subtract' Failed. "
                                "{err}\n".format(err=str(err)))
         exc_type, exc_obj, exc_tb = sys.exc_info()
         fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
         print(exc_type, fname, exc_tb.tb_lineno)
Ejemplo n.º 6
0
    def Activated(self):
        try:
            s = Gui.Selection.getSelectionEx()
            temp = None
            if (len(s) < 2):
                # Two object must be selected
                errMessage = "Select two or more objects to Merge"
                faced.getInfo(s).errorDialog(errMessage)
                return
            allObjects = []
            for o in s:
                allObjects.append(App.ActiveDocument.getObject(o.ObjectName))

            newObj = App.activeDocument().addObject("Part::MultiFuse",
                                                    "MergedTemp")
            newObj.Shapes = allObjects
            newObj.Refine = True
            App.ActiveDocument.recompute()
            if newObj.isValid() == False:
                App.ActiveDocument.removeObject(newObj.Name)
                # Shape is not OK
                errMessage = "Failed create shell"
                faced.getInfo(s).errorDialog(errMessage)
            else:

                # Make a simple copy
                newShape = Part.getShape(newObj,
                                         '',
                                         needSubElement=False,
                                         refine=False)
                NewJ = App.ActiveDocument.addObject('Part::Feature',
                                                    'Merged').Shape = newShape
                App.ActiveDocument.recompute()
                # Remove Old objects
                # for obj in allObjects:
                #	App.ActiveDocument.removeObject(obj.Name)
                # App.ActiveDocument.removeObject(newObj.Name)
            App.ActiveDocument.recompute()
            del allObjects[:]
        except Exception as err:
            App.Console.PrintError("'Part::Merge' Failed. "
                                   "{err}\n".format(err=str(err)))
            exc_type, exc_obj, exc_tb = sys.exc_info()
            fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
            print(exc_type, fname, exc_tb.tb_lineno)
Ejemplo n.º 7
0
 def Activated(self):
     try:
         s = Gui.Selection.getSelectionEx()
         App.ActiveDocument.openTransaction(
             translate("Design456", "Part Intersect"))
         if (len(s) < 2):
             # Two object must be selected
             errMessage = "Select two or more objects to Intersect"
             faced.getInfo(s).errorDialog(errMessage)
             return
         newObj = App.ActiveDocument.addObject("Part::MultiCommon",
                                               "tempIntersect")
         newObj.Shapes = [
             App.ActiveDocument.getObject(s[0].ObjectName),
             App.ActiveDocument.getObject(s[1].ObjectName)
         ]
         App.ActiveDocument.recompute()
         # Make a simple copy
         newShape = Part.getShape(newObj,
                                  '',
                                  needSubElement=False,
                                  refine=False)
         NewJ = App.ActiveDocument.addObject('Part::Feature',
                                             'Intersect').Shape = newShape
         App.ActiveDocument.recompute()
         # Remove Old objects
         allObjects = []
         for o in s:
             allObjects.append(App.ActiveDocument.getObject(o.ObjectName))
         for obj in allObjects:
             App.ActiveDocument.removeObject(obj.Name)
         App.ActiveDocument.removeObject(newObj.Name)
         App.ActiveDocument.commitTransaction()  #undo reg.
         App.ActiveDocument.recompute()
         del allObjects[:]
     except Exception as err:
         App.Console.PrintError("'Part::Intersect' Failed. "
                                "{err}\n".format(err=str(err)))
         exc_type, exc_obj, exc_tb = sys.exc_info()
         fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
         print(exc_type, fname, exc_tb.tb_lineno)
Ejemplo n.º 8
0
    def Activated(self):
        try:
            s = Gui.Selection.getSelectionEx()
            if (len(s) < 1):
                # One object must be selected at least
                errMessage = "Select a face or an edge use Chamfer"
                faced.getInfo(s).errorDialog(errMessage)
                return
            App.ActiveDocument.openTransaction(
                translate("Design456", "Part Chamfer"))
            Radius = QtGui.QInputDialog.getDouble(None, "Radius", "Radius:", 0,
                                                  -10000.0, 10000.0, 2)[0]
            if (Radius == 0):
                return  # Nothing to do here
            sub1 = s[0]
            tempNewObj = App.ActiveDocument.addObject("Part::Chamfer",
                                                      "tempChamfer")
            tempNewObj.Base = sub1.Object
            names = sub1.SubElementNames
            EdgesToBeChanged = []
            if (len(names) != 0):
                for name in names:
                    edgeNumbor = int(name[4:len(name)])
                    EdgesToBeChanged.append((edgeNumbor, Radius, Radius))
                tempNewObj.Edges = EdgesToBeChanged
            else:
                errMessage = "Chamfer failed. No subelements found"
                faced.getInfo(s).errorDialog(errMessage)
                return
            # Make a simple copy of the object
            App.ActiveDocument.recompute()
            if tempNewObj.isValid() == False:
                App.ActiveDocument.removeObject(tempNewObj.Name)
                # Shape is not OK
                errMessage = "Failed to fillet the objects"
                faced.getInfo(s).errorDialog(errMessage)
            else:
                newShape = Part.getShape(tempNewObj,
                                         '',
                                         needSubElement=False,
                                         refine=False)
                newObj = App.ActiveDocument.addObject(
                    'Part::Feature', 'Chamfer').Shape = newShape
                App.ActiveDocument.recompute()
                App.ActiveDocument.ActiveObject.Label = 'Chamfer'

                App.ActiveDocument.removeObject(sub1.Object.Name)
                App.ActiveDocument.removeObject(tempNewObj.Name)
            del EdgesToBeChanged[:]
            App.ActiveDocument.commitTransaction()  #undo reg.
            App.ActiveDocument.recompute()

        except Exception as err:
            App.Console.PrintError("'Chamfer' Failed. "
                                   "{err}\n".format(err=str(err)))
            exc_type, exc_obj, exc_tb = sys.exc_info()
            fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
            print(exc_type, fname, exc_tb.tb_lineno)
Ejemplo n.º 9
0
 def Activated(self):
     try:
         objectCreate=False
         newobj=App.ActiveDocument.ActiveObject  #Dummy code.
         s = Gui.Selection.getSelectionEx()
         if (len(s) < 1):
             # An object must be selected
             errMessage = "Select a face from an objects to use Extract"
             faced.getInfo(s).errorDialog(errMessage)
             return
         App.ActiveDocument.openTransaction(translate("Design456","Extract Face"))
         for o in s:
             objName = o.ObjectName
             sh = o.Object.Shape.copy()
             if hasattr(o.Object, "getGlobalPlacement"):
                 gpl = o.Object.getGlobalPlacement()
                 sh.Placement = gpl
             for name in o.SubElementNames:
                 fullname = objName+"_"+name
                 newobj = o.Document.addObject("Part::Feature", fullname)
                 newobj.Shape = sh.getElement(name)
                 objectCreate=True
         App.ActiveDocument.commitTransaction()
         App.ActiveDocument.recompute()
         if  newobj.isValid()==False:
             if objectCreate==True:
                 App.ActiveDocument.removeObject(newobj.Name)
             # Shape is not OK
             errMessage = "Failed to extract the shape"
             faced.getInfo(s).errorDialog(errMessage)
             return
     except Exception as err:
         App.Console.PrintError("'Design456_Extract' Failed. "
                                "{err}\n".format(err=str(err)))
         exc_type, exc_obj, exc_tb = sys.exc_info()
         fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
         print(exc_type, fname, exc_tb.tb_lineno)
Ejemplo n.º 10
0
    def Activated(self):
        try:
            selected = Gui.Selection.getSelectionEx()
            oneObject = False

            for n in selected:
                if n.HasSubObjects == True:
                    oneObject = True
            if (len(selected) < 2):
                # Two object must be selected
                errMessage = "Select two or more objects to use MultiPointsToLineOpen Tool"
                faced.getInfo(selected).errorDialog(errMessage)
                return
            allSelected = []
            for t in selected:
                allSelected.append(t.PickedPoints[0])
            print(allSelected)
            if self.type == 0:
                Wire1 = _draft.makeWire(allSelected, closed=True)
            else:
                Wire1 = _draft.makeWire(allSelected, closed=False)
            """
            I have to find a way to avoid deleting Vertices if they are a part from another object.
            This is disabled at the moment.

            for n in selected:
                App.ActiveDocument.removeObject(n.Object.Name)
            """
            del allSelected[:]
            App.ActiveDocument.recompute()

        except Exception as err:
            App.Console.PrintError("'MultiPointsToWire' Failed. "
                                   "{err}\n".format(err=str(err)))
            exc_type, exc_obj, exc_tb = sys.exc_info()
            fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
            print(exc_type, fname, exc_tb.tb_lineno)
Ejemplo n.º 11
0
    def Activated(self):
        try:
            s = Gui.Selection.getSelectionEx()
            temp = None
            if (len(s) < 2):
                # Two object must be selected
                errMessage = "Select two or more objects to Merge"
                faced.getInfo(s).errorDialog(errMessage)
                return
            allObjects = []
            for o in s:
                allObjects.append(App.ActiveDocument.getObject(o.ObjectName))

            newObj = App.activeDocument().addObject("Part::Compound",
                                                    "TempCompound")
            App.ActiveDocument.Compund.Links = allObjects
            # Make a simple copy
            newShape = Part.getShape(newObj,
                                     '',
                                     needSubElement=False,
                                     refine=False)
            NewJ = App.ActiveDocument.addObject('Part::Feature',
                                                'Compound').Shape = newShape

            # Remove Old objects
            for obj in allObjects:
                App.ActiveDocument.removeObject(obj.Name)
            App.ActiveDocument.removeObject(newObj.Name)

            App.ActiveDocument.recompute()
            del allObjects[:]
        except Exception as err:
            App.Console.PrintError("'Part::Compund' Failed. "
                                   "{err}\n".format(err=str(err)))
            exc_type, exc_obj, exc_tb = sys.exc_info()
            fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
            print(exc_type, fname, exc_tb.tb_lineno)
Ejemplo n.º 12
0
    def Activated(self):
        try:
            s = Gui.Selection.getSelectionEx()
            if (len(s) < 2):
                # Two object must be selected
                #App.ActiveDocument.openTransaction(translate("Design456","Part Group")) TODO: Doesn't work
                errMessage = "Select two or more objects to create a group"
                faced.getInfo(s).errorDialog(errMessage)
                return

            newObj = App.ActiveDocument.Tip = App.ActiveDocument.addObject(
                'App::Part', 'Group')
            newObj.Label = 'Group'
            for obj_ in s:
                obj = App.ActiveDocument.getObject(obj_.ObjectName)
                newObj.addObject(obj)
            #App.ActiveDocument.commitTransaction() #undo reg.
            App.ActiveDocument.recompute()
        except Exception as err:
            App.Console.PrintError("'Part::Part' Failed. "
                                   "{err}\n".format(err=str(err)))
            exc_type, exc_obj, exc_tb = sys.exc_info()
            fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
            print(exc_type, fname, exc_tb.tb_lineno)
Ejemplo n.º 13
0
    def Activated(self):
        try:
            App.ActiveDocument.openTransaction(
                translate("Design456", "Surface"))
            s = Gui.Selection.getSelectionEx()
            if (len(s) < 2 or len(s) > 2):
                # Two object must be selected
                errMessage = "Select two edges or two wire to make a face or "
                faced.getInfo(s).errorDialog(errMessage)
                return
            from textwrap import wrap
            for ss in s:
                word = ss.FullName
                if (word.find('Vertex') != -1):
                    # Two lines or curves or wires must be selected
                    errMessage = "Select two edges or two wires not Vertex"
                    faced.getInfo(s).errorDialog(errMessage)
                    return

            newObj = App.ActiveDocument.addObject('Part::RuledSurface',
                                                  'tempSurface')
            for sub in s:
                newObj.Curve1 = (s[0].Object, s[0].SubElementNames)
                newObj.Curve2 = (s[1].Object, s[1].SubElementNames)
            App.ActiveDocument.recompute()
            # Make a simple copy of the object
            newShape = _part.getShape(newObj,
                                      '',
                                      needSubElement=False,
                                      refine=True)
            tempNewObj = App.ActiveDocument.addObject('Part::Feature',
                                                      'Surface')
            tempNewObj.Shape = newShape
            App.ActiveDocument.ActiveObject.Label = 'Surface'
            App.ActiveDocument.recompute()
            if tempNewObj.isValid() == False:
                App.ActiveDocument.removeObject(tempNewObj.Name)
                # Shape is not OK
                errMessage = "Failed to fillet the objects"
                faced.getInfo(s).errorDialog(errMessage)
            else:
                App.ActiveDocument.removeObject(newObj.Name)
                # Removing these could cause problem if the line is a part of an object
                # You cannot hide them either. TODO: I have to find a solution later
                # App.ActiveDocument.removeObject(s[0].Object.Name)
                # App.ActiveDocument.removeObject(s[1].Object.Name)
                s[0].Object.ViewObject.Visibility = False
                s[1].Object.ViewObject.Visibility = False
                App.ActiveDocument.commitTransaction()  #undo reg.de here
                App.ActiveDocument.recompute()
        except Exception as err:
            App.Console.PrintError("'Part Surface' Failed. "
                                   "{err}\n".format(err=str(err)))
            exc_type, exc_obj, exc_tb = sys.exc_info()
            fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
            print(exc_type, fname, exc_tb.tb_lineno)
Ejemplo n.º 14
0
    def Activated(self):
        try:
            s = Gui.Selection.getSelectionEx()
            temp = None
            if (len(s) < 2):
                # Two object must be selected
                errMessage = "Select two or more objects to create a group"
                faced.getInfo(s).errorDialog(errMessage)
                return

            newObj = App.activeDocument().Tip = App.activeDocument().addObject(
                'App::Part', 'Group')
            newObj.Label = 'Group'
            for obj_ in s:
                obj = App.ActiveDocument.getObject(obj_.ObjectName)
                newObj.addObject(obj)

            App.ActiveDocument.recompute()
        except Exception as err:
            App.Console.PrintError("'Part::Part' Failed. "
                                   "{err}\n".format(err=str(err)))
            exc_type, exc_obj, exc_tb = sys.exc_info()
            fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
            print(exc_type, fname, exc_tb.tb_lineno)
Ejemplo n.º 15
0
    def runClass(self):
        try:
            sel = Gui.Selection.getSelectionEx()
            if (len(sel) < 1 or len(sel) > 1 or len(
                    Gui.Selection.getSelectionEx()[0].SubElementNames) == 0):
                # Two object must be selected
                errMessage = "Select a face to use LoftOnDirection Tool"
                faced.getInfo(sel[0]).errorDialog(errMessage)
                return

            selectedEdge = Gui.Selection.getSelectionEx()[0].SubObjects[
                0]  # select one element
            SubElementName = Gui.Selection.getSelectionEx(
            )[0].SubElementNames[0]

            #### configuration ####
            ValueLength = -(float)(self.inLength.value())
            ValueScaleX = (float)(self.inScaleX.value())
            ValueScaleY = (float)(self.inScaleY.value())
            ValueScaleZ = (float)(self.inScaleZ.value())

            ####
            createAxis = self.chkAxis.isChecked()  # 0 = not Axis, other = Axis
            createLoft = self.chkLoft.isChecked()  # 0 = not loft, other = loft
            #### configuration ####
            App.ActiveDocument.openTransaction(
                translate("Design456", "LoftOnDirection"))
            if hasattr(selectedEdge, 'Surface'):
                plr = plDirection = App.Placement()

                # section direction
                yL = selectedEdge.CenterOfMass
                uv = selectedEdge.Surface.parameter(yL)
                nv = selectedEdge.normalAt(uv[0], uv[1])
                direction = yL.sub(nv + yL)
                r = App.Rotation(App.Vector(0, 0, 0), direction)
                plDirection.Rotation.Q = r.Q
                #print(r.Q)
                plDirection.Base = yL
                plr = plDirection
                #print("surface : ", sel[0].Name, " ",SubElementName, "  ", direction)
                # section direction

                # section axis
                if createAxis != 0:
                    # section axis
                    points = [
                        App.Vector(0.0, 0.0, 0.0),
                        App.Vector(0.0, 0.0, ValueLength)
                    ]
                    centerX = _draft.makeWire(points,
                                              closed=False,
                                              face=False,
                                              support=None)
                    centerX.Placement = plr
                    centerX.Label = "Axis_" + SubElementName
                    # section axis

                #### section scale ####
                if createLoft != 0:
                    #### section scale ####
                    _part.show(selectedEdge.copy())
                    firstFace = App.ActiveDocument.ActiveObject
                    objClone = _draft.scale(
                        firstFace,
                        App.Vector(ValueScaleX, ValueScaleY, ValueScaleZ),
                        center=App.Vector(plDirection.Base),
                        copy=True)  # False

                    # section placement face in length and direction
                    newLocation = (App.Vector(direction).scale(
                        ValueLength, ValueLength, ValueLength))
                    if (direction.x != 0 and abs(direction.x) == direction.x):
                        newLocation.x = newLocation.x + selectedEdge.Placement.Base.x * direction.x
                    elif (direction.x != 0
                          and abs(direction.x) != direction.x):
                        newLocation.x = newLocation.x - selectedEdge.Placement.Base.x * direction.x
                    else:
                        newLocation.x = selectedEdge.Placement.Base.x
                    if (direction.y != 0
                            and abs(direction.y) == direction.y):  #positive >0
                        newLocation.y = newLocation.y + selectedEdge.Placement.Base.y * direction.y
                    elif (direction.y != 0
                          and abs(direction.x) != direction.y):  #negative <0
                        newLocation.y = newLocation.y - selectedEdge.Placement.Base.y * direction.y
                    else:
                        newLocation.y = selectedEdge.Placement.Base.y
                    if (direction.z != 0 and abs(direction.z) == direction.z):
                        newLocation.z = newLocation.z + selectedEdge.Placement.Base.z * direction.z
                    elif (direction.z != 0
                          and abs(direction.z) != direction.z):  #negative <0:
                        newLocation.z = newLocation.z - selectedEdge.Placement.Base.z * direction.z
                    else:
                        newLocation.z = selectedEdge.Placement.Base.z
                    objClone.Placement.Base = newLocation

                    # section loft
                    newObj = App.ActiveDocument.addObject('Part::Loft', 'Loft')
                    App.ActiveDocument.ActiveObject.Sections = [
                        App.ActiveDocument.getObject(firstFace.Name),
                        App.ActiveDocument.getObject(objClone.Name),
                    ]
                    App.ActiveDocument.ActiveObject.Solid = True
                    newObj = App.ActiveDocument.ActiveObject
                    App.ActiveDocument.recompute()

                    # copy
                    App.ActiveDocument.addObject('Part::Feature', newObj.Name +
                                                 'N').Shape = _part.getShape(
                                                     newObj,
                                                     '',
                                                     needSubElement=False,
                                                     refine=True)
                    App.ActiveDocument.recompute()

                    # Remove Old objects. I don't like to keep so many objects without any necessity.

                    for obj in newObj.Sections:
                        App.ActiveDocument.removeObject(obj.Name)
                    App.ActiveDocument.removeObject(newObj.Name)
                    App.ActiveDocument.commitTransaction()
                    App.ActiveDocument.recompute()
                    # section hidden faces work
            self.window.hide()
        except Exception as err:
            App.Console.PrintError("'Design456_loftOnDirection' Failed. "
                                   "{err}\n".format(err=str(err)))
            exc_type, exc_obj, exc_tb = sys.exc_info()
            fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
            print(exc_type, fname, exc_tb.tb_lineno)
Ejemplo n.º 16
0
    def makeIt(self, commandType):
        self.commandType = commandType
        selection = Gui.Selection.getSelectionEx()
        # Two object must be selected
        if(len(selection) < 2 or len(selection) > 2):
            errMessage = "Select two objects to use Common 2D Tool"
            faced.getInfo(selection).errorDialog(errMessage)
        else:
            nObjects = []
            nObjects.clear()
            GlobalPlacement = App.activeDocument().getObject(
                selection[0].Object.Name).Placement
            for a2dobj in selection:
                m = App.activeDocument().getObject(a2dobj.Object.Name)
                f = App.activeDocument().addObject('Part::Extrusion', 'ExtrudeOriginal')
                f.Base = App.activeDocument().getObject(m.Name)
                f.DirMode = "Normal"
                f.DirLink = a2dobj.Object
                f.LengthFwd = 1.00
                f.LengthRev = 0.0
                f.Solid = True
                f.Reversed = False
                f.Symmetric = False
                f.TaperAngle = 0.0
                f.TaperAngleRev = 0.0
                App.ActiveDocument.recompute()

                # Make a simple copy of the object
                newShape = Part.getShape(
                    f, '', needSubElement=False, refine=True)
                newObj = App.ActiveDocument.addObject(
                    'Part::Feature', 'Extrude')
                newObj.Shape = newShape
                App.ActiveDocument.recompute()
                App.ActiveDocument.ActiveObject.Label = f.Label
                App.ActiveDocument.recompute()
                App.ActiveDocument.removeObject(f.Name)
                App.ActiveDocument.removeObject(m.Name)
                App.ActiveDocument.recompute()
                nObjects.append(newObj)

            tempResult = self.DoCommand(self.commandType)
            if(commandType == 1):
                tempResult.Shapes = nObjects
            elif(commandType == 2 or commandType == 3):
                tempResult.Tool = nObjects[1]
                tempResult.Base = nObjects[0]
            App.ActiveDocument.recompute()
            newShape = Part.getShape(
                tempResult, '', needSubElement=False, refine=True)
            Result = App.ActiveDocument.addObject('Part::Feature', 'Shape')
            Result.Shape = newShape
            for name in nObjects:
                App.ActiveDocument.removeObject(name.Name)
            App.ActiveDocument.removeObject(tempResult.Name)
            Gui.Selection.clearSelection()
            App.ActiveDocument.recompute()
            Gui.Selection.addSelection(App.ActiveDocument.Name, Result.Name)
            s = Gui.Selection.getSelectionEx()[0]
            obFace = faced.getInfo(s)
            faceName = obFace.SelectTopFace()
            # Extract the face
            sh = Result.Shape.copy()
            sh.Placement = GlobalPlacement  # Result.Placement
            sh.Placement.Base.z = -1
            newobj = Result.Document.addObject(
                "Part::Feature", self.localShapeName)
            newobj.Shape = sh.getElement(faceName)
            App.ActiveDocument.removeObject(Result.Name)
            del nObjects[:]
Ejemplo n.º 17
0
    def Activated(self):
        try:
            _points = []
            s = Gui.Selection.getSelectionEx()
            if len(s) > 2:
                # Two object must be selected
                errMessage = "Select only two vertices "
                faced.getInfo(s).errorDialog(errMessage)
                return
            elif len(s) == 1:
                #We have one line .. end and start will be one.
                for pnt in s[0].Object.Shape.Vertexes:
                    if (pnt != s[0].Object.End):
                        _points.append(pnt.Point)
                newObj = _draft.makeWire(_points)
                newObj.Start = _points[0]
                newObj.End = _points[0]
                App.ActiveDocument.removeObject(s[0].Object.Name)
                App.ActiveDocument.recompute()
            elif len(s) == 2:
                s1 = s[0]
                s2 = s[1]
                tempPoint = None

                p1 = []
                p2 = []
                p1.append(s1.Object.Start)
                p1.append(s1.Object.End)
                p2.append(s2.Object.Start)
                p2.append(s2.Object.End)
                if p2[0] == s2.SubObjects[0].Point:
                    for pnt in reversed(s2.Object.Shape.Vertexes):
                        _points.append(pnt.Point)
                else:
                    for pnt in s2.Object.Shape.Vertexes:
                        _points.append(pnt.Point)

                if p1[0] != s1.SubObjects[0].Point:
                    for pnt in reversed(s1.Object.Shape.Vertexes):
                        if pnt.Point != p1[0]:
                            #Start and selected is the same ignore it
                            _points.append(pnt.Point)
                else:
                    for pnt in s1.Object.Shape.Vertexes:
                        if pnt.Point != p1[1]:
                            #End and selected is the same ignore it
                            _points.append(pnt.Point)

                plc = s2.Object.Placement
                plc.Rotation.Q = s2.Object.Placement.Rotation.Q
                ang = s2.Object.Placement.Rotation.Angle
                axes = s2.Object.Placement.Rotation.Axis
                newObj = _draft.makeWire(_points)
                newObj.Start = _points[0]
                newObj.End = _points[len(_points) - 1]

                #newObj.Placement=plc
                #newObj.Placement.Rotation.Axis=axes
                #newObj.Placement.Rotation.Angle=ang

                App.ActiveDocument.removeObject(s1.Object.Name)
                App.ActiveDocument.removeObject(s2.Object.Name)
            App.ActiveDocument.recompute()

        except Exception as err:
            App.Console.PrintError("'Part Surface' Failed. "
                                   "{err}\n".format(err=str(err)))
            exc_type, exc_obj, exc_tb = sys.exc_info()
            fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
            print(exc_type, fname, exc_tb.tb_lineno)
Ejemplo n.º 18
0
    def ExtrudeFace(self, allObjects):
        try:
            for obj in allObjects:
                App.ActiveDocument.openTransaction(
                    translate("Design456", "Extrude"))
                m = obj
                f = App.ActiveDocument.addObject('Part::Extrusion',
                                                 'ExtrudeOriginal')
                # section direction
                yL = m.Shape.Faces[0].CenterOfMass
                uv = m.Shape.Faces[0].Surface.parameter(yL)
                nv = m.Shape.Faces[0].normalAt(uv[0], uv[1])
                direction = yL.sub(nv + yL)
                direction = App.Vector(round(direction.x, 2),
                                       round(direction.y, 2),
                                       round(direction.z, 2))
                f.Dir = direction
                f.Base = m
                # F.DirMode causes too many failure. Some faces needs custom, other needs Normal.
                # Difficult to know when you use each of them.
                if (f.Dir.x != 1 or f.Dir.y != 1 or f.Dir.z != 1):
                    f.DirMode = "Custom"
                else:
                    f.DirMode = "Normal"
                f.DirLink = None  # Above statement != always correct. Some faces require 'custom'
                f.LengthFwd = self.extrusionLength
                f.LengthRev = 0.0
                f.Solid = True
                f.Reversed = False
                f.Symmetric = False
                f.TaperAngle = 0.0
                f.TaperAngleRev = 0.0
                r = App.Rotation(App.Vector(0, 0, 0), direction)
                f.Dir = direction

                # Make a simple copy of the object
                App.ActiveDocument.recompute()
                newShape = Part.getShape(f,
                                         '',
                                         needSubElement=False,
                                         refine=False)
                newObj = App.ActiveDocument.addObject(
                    'Part::Feature', 'Extrude').Shape = newShape
                App.ActiveDocument.recompute()
                # if something went wrong .. delete all new objects.
                if newObj.isValid() is False:
                    App.ActiveDocument.removeObject(newObj.Name)
                    App.ActiveDocument.removeObject(f.Name)
                    # Shape != OK
                    errMessage = "Failed to extrude the shape"
                    faced.getInfo(m).errorDialog(errMessage)
                else:
                    App.ActiveDocument.recompute()
                    App.ActiveDocument.removeObject(f.Name)
                    App.ActiveDocument.removeObject(m.Name)
            App.ActiveDocument.commitTransaction()  # undo reg.
            App.ActiveDocument.recompute()

        except Exception as err:
            App.Console.PrintError("'Design456_Extrude' Failed. "
                                   "{err}\n".format(err=str(err)))
            exc_type, exc_obj, exc_tb = sys.exc_info()
            fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
            print(exc_type, fname, exc_tb.tb_lineno)
Ejemplo n.º 19
0
    def Activated(self):

        try:
            sel = Gui.Selection.getSelectionEx()
            if len(sel) < 1:
                # several selections - Error
                errMessage = "Select one or more edges to trim"
                faced.getInfo(sel).errorDialog(errMessage)
                return
            SelectedPoints = []
            sel1 = sel[0]

            if sel1.HasSubObjects:
                # We have several objects that has subobject(Edges) that should be trimmed

                # Save position and angle
                _placement = sel1.Object.Placement
                _placement.Rotation.Q = sel1.Object.Placement.Rotation.Q
                currentObject = App.ActiveDocument.getObject(sel1.Object.Name)
                SelectedPoints.clear(
                )  # points in the targeted line to be trimmed
                _edg = sel1.SubObjects[0]
                # TODO: trim only 2 points at the moment
                Vert = _edg.Vertexes

                # Save all points we have in the edge or line/wire which should be trimmed
                for n in Vert:
                    SelectedPoints.append(App.Vector(n.Point))

                WireOrEdgeMadeOfPoints = []
                # Bring all points from the object
                for item in sel1.Object.Shape.Vertexes:
                    WireOrEdgeMadeOfPoints.append(App.Vector(item.Point))
                totalPoints = len(WireOrEdgeMadeOfPoints)
                position1 = position2 = None
                count = 0
                # First find their locations

                for j in range(totalPoints):
                    if SelectedPoints[0] == WireOrEdgeMadeOfPoints[j]:
                        position1 = count
                    elif (SelectedPoints[1] == WireOrEdgeMadeOfPoints[j]):
                        position2 = count
                    count = count + 1
                # Try to reconstruct the shape/wire
                TestTwoObjectCreate = False
                _all_points2 = []
                objType = faced.getInfo(sel1).selectedObjectType()
                closedShape = None
                EndPoint = StartPoint = None
                if (objType == 'Wire' or objType == 'Line'):
                    closedShape = sel1.Object.Closed
                elif objType == 'Unknown':
                    closedShape = False
                    return  # We don't know what the shape is
                elif objType == 'Arc':
                    App.ActiveDocument.removeObject(sel1.Object.Name)
                    return
                else:
                    closedShape = True
                if closedShape == True:
                    # We have a shape with closed lines
                    # Here we need to do 2 things, 1 remove closed, 2 rearrange start-end
                    scan1 = min(position1, position2)
                    scan2 = max(position1, position2)
                    sortAll = 0
                    Index = scan2
                    EndPoint = WireOrEdgeMadeOfPoints[scan1]
                    StartPoint = WireOrEdgeMadeOfPoints[scan2]
                    while (sortAll < totalPoints):
                        _all_points2.append(WireOrEdgeMadeOfPoints[Index])
                        Index = Index + 1
                        if Index >= totalPoints:
                            Index = 0
                        sortAll = sortAll + 1
                    WireOrEdgeMadeOfPoints.clear()
                    WireOrEdgeMadeOfPoints = _all_points2

                elif (abs(position2 - position1) == 1):
                    # It must be a line and not closed
                    if position1 != 0 and position2 != totalPoints - 1:
                        # In the middle of the array.
                        # Two objects must be created.
                        print("between first and last")
                        _all_points2.clear()
                        plusOrMinus = 0
                        scan1 = min(position1, position2)
                        scan2 = max(position1, position2)
                        SaveValue = None
                        index = 0
                        while (index <= scan1):
                            _all_points2.append(WireOrEdgeMadeOfPoints[index])
                            index = index + 1
                        index = 0
                        StartPoint = WireOrEdgeMadeOfPoints[scan2]
                        EndPoint = WireOrEdgeMadeOfPoints[
                            len(WireOrEdgeMadeOfPoints) - 1]

                        for index in range(0, scan2):
                            print(index)
                            WireOrEdgeMadeOfPoints.pop(index)

                        pnew2DObject1 = _draft.makeWire(_all_points2,
                                                        placement=None,
                                                        closed=False,
                                                        face=False,
                                                        support=None)
                        pnew2DObject1.Label = 'Wire'
                        pnew2DObject1.Start = _all_points2[0]
                        pnew2DObject1.End = _all_points2[len(_all_points2) - 1]

                    elif position1 == 0 and position2 != totalPoints - 1:
                        # First Points, remove  'closed' and start = pos+1
                        print("in the beginning")
                        StartPoint = WireOrEdgeMadeOfPoints[position2]
                        WireOrEdgeMadeOfPoints.pop(position1)
                        EndPoint = WireOrEdgeMadeOfPoints[
                            len(WireOrEdgeMadeOfPoints) - 1]
                        # don't add first point
                    elif position2 == totalPoints - 1:
                        # point 2 is the last point in the shape
                        print("at the end")
                        StartPoint = WireOrEdgeMadeOfPoints[0]
                        EndPoint = WireOrEdgeMadeOfPoints[position2 - 1]
                        WireOrEdgeMadeOfPoints.pop(position2 - 1)

                        # don't add last point

                pnew2DObject2 = _draft.makeWire(WireOrEdgeMadeOfPoints,
                                                placement=None,
                                                closed=False,
                                                face=False,
                                                support=None)
                App.ActiveDocument.removeObject(sel1.ObjectName)
                App.ActiveDocument.recompute()
                pnew2DObject2.Label = 'Wire'

                pnew2DObject2.End = EndPoint
                pnew2DObject2.Start = StartPoint

                # If nothing left, remove the object
                if len(pnew2DObject2.Shape.Vertexes) == 0:
                    App.ActiveDocument.removeObject(pnew2DObject2.Label)
                App.ActiveDocument.recompute()

            else:
                # No Edges found
                errMessage = "Select one or more edges to trim"
                faced.getInfo(sel1).errorDialog(errMessage)
                return
        except Exception as err:
            App.Console.PrintError("'Trim 2D' Failed. "
                                   "{err}\n".format(err=str(err)))
            exc_type, exc_obj, exc_tb = sys.exc_info()
            fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
            print(exc_type, fname, exc_tb.tb_lineno)
Ejemplo n.º 20
0
    def Activated(self):
        try:
            selection = Gui.Selection.getSelectionEx()
            if (len(selection) < 1):
                # An object must be selected
                errMessage = "Select a face to use Extrude"
                faced.getInfo(selection).errorDialog(errMessage)
                return
            m = selection[0].Object
            f = App.activeDocument().addObject('Part::Extrusion',
                                               'ExtrudeOriginal')
            faceSelected = faced.getInfo(selection[0]).getFaceName()
            f.Base = m
            #f.Base = App.activeDocument().getObject(m.Name)
            f.DirMode = "Normal"  #Dont use Custom as it leads to PROBLEM!
            f.DirLink = None
            degreeAngle = m.Placement.Rotation.Angle * 180 * 22 / 7  # Convert to Radians
            print(degreeAngle)
            """
            YOU SHOULD NOT SPECIFY THIS .. OTHERWISE WOULD BE WRONG!!
            if degreeAngle == 0:
                f.Dir = m.Placement.Rotation.Axis
            elif ((degreeAngle== 90) or (degreeAngle== -90)):
                f.Dir = (0, 1, 0)
            elif ((degreeAngle == 120) or (degreeAngle== -120)):
                f.Dir = (1, 0, 0)
            """
            f.LengthFwd = QtGui.QInputDialog.getDouble(None, "Get length",
                                                       "Length:", 0, -10000.0,
                                                       10000.0, 2)[0]
            while (f.LengthFwd == 0):
                _sleep(.1)
                Gui.updateGui()
            f.LengthRev = 0.0
            f.Solid = True
            f.Reversed = False
            f.Symmetric = False
            f.TaperAngle = 0.0
            f.TaperAngleRev = 0.0

            # Make a simple copy of the object
            App.ActiveDocument.recompute()
            newShape = Part.getShape(f, '', needSubElement=False, refine=False)
            newObj = App.ActiveDocument.addObject('Part::Feature',
                                                  'Extrude').Shape = newShape
            App.ActiveDocument.ActiveObject.Label = f.Label
            App.ActiveDocument.recompute()
            # if something went wrong .. delete all new objecst.
            if newObj.isValid() == False:
                App.ActiveDocument.removeObject(newObj.Name)
                App.ActiveDocument.removeObject(f.Name)
                # Shape is not OK
                errMessage = "Failed to extrude the shape"
                faced.getInfo(m).errorDialog(errMessage)
            else:
                # Remove old objects
                App.ActiveDocument.clearUndos()
                App.ActiveDocument.recompute()
                App.ActiveDocument.removeObject(f.Name)
                App.ActiveDocument.removeObject(m.Name)
                return
            App.ActiveDocument.recompute()
        except Exception as err:
            App.Console.PrintError("'Design456_Extrude' Failed. "
                                   "{err}\n".format(err=str(err)))
            exc_type, exc_obj, exc_tb = sys.exc_info()
            fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
            print(exc_type, fname, exc_tb.tb_lineno)
Ejemplo n.º 21
0
    def Activated(self):
        try:
            sel = Gui.Selection.getSelection()
            if (len(sel) != 2):
                # Two object must be selected
                errMessage = "Select two objects to use the Tool"
                faced.getInfo(sel).errorDialog(errMessage)
                return
            reply = self.askQuestion()
            App.ActiveDocument.openTransaction(
                translate("Design456", "UnifySplitFuse1"))
            Gui.ActiveDocument.getObject(sel[0].Name).Visibility = False
            Gui.ActiveDocument.getObject(sel[1].Name).Visibility = False

            #### Config Begin ####

            switchRemoveConstructionObject = self.askQuestion(
            )  # if 0 (NO) not removed creation objects 1= (YES) remove objects
            colorCommon = (0.9373, 0.1608, 0.1608)
            colorCut1 = (0.4471, 0.6235, 0.8118)
            colorCut2 = (0.0235, 0.6902, 0.6902)
            colorFuse = (1.0000, 0.6667, 0.0000)
            #### Config End ####

            ##### Begin command _part_Common
            #### create copy
            shapeCommon = _part.getShape(App.ActiveDocument.getObject(
                sel[0].Name),
                                         '',
                                         needSubElement=False,
                                         refine=False)
            App.ActiveDocument.addObject('Part::Feature',
                                         'Common1').Shape = shapeCommon
            newObjectCut_A1 = App.ActiveDocument.ActiveObject
            shapeCommon = _part.getShape(App.ActiveDocument.getObject(
                sel[1].Name),
                                         '',
                                         needSubElement=False,
                                         refine=False)
            App.ActiveDocument.addObject('Part::Feature',
                                         'Common2').Shape = shapeCommon
            newObjectCut_A2 = App.ActiveDocument.ActiveObject
            ####
            commonObject = App.ActiveDocument.addObject(
                "Part::MultiCommon", "Common")
            commonObjectMake = App.ActiveDocument.getObject(
                commonObject.Name).Shapes = [
                    App.ActiveDocument.getObject(newObjectCut_A1.Name),
                    App.ActiveDocument.getObject(newObjectCut_A2.Name),
                ]
            shapeCommonMake = App.ActiveDocument.ActiveObject
            App.ActiveDocument.recompute()
            Gui.ActiveDocument.activeObject().ShapeColor = colorCommon
            ####
            shapeCommon = _part.getShape(App.ActiveDocument.getObject(
                shapeCommonMake.Name),
                                         '',
                                         needSubElement=False,
                                         refine=False)
            App.ActiveDocument.addObject('Part::Feature',
                                         'shapeCommon').Shape = shapeCommon
            Gui.ActiveDocument.activeObject().ShapeColor = colorCommon
            if switchRemoveConstructionObject == 1:
                App.ActiveDocument.removeObject(shapeCommonMake.Name)
                App.ActiveDocument.removeObject(newObjectCut_A1.Name)
                App.ActiveDocument.removeObject(newObjectCut_A2.Name)
            #### End command Part_Common

            #### Begin command Part_Cut First
            #### create copy
            shapeCut1 = _part.getShape(App.ActiveDocument.getObject(
                sel[0].Name),
                                       '',
                                       needSubElement=False,
                                       refine=False)
            App.ActiveDocument.addObject('Part::Feature',
                                         'Cut01').Shape = shapeCut1
            newObjectCut_A1 = App.ActiveDocument.ActiveObject
            shapeCut1 = _part.getShape(App.ActiveDocument.getObject(
                sel[1].Name),
                                       '',
                                       needSubElement=False,
                                       refine=False)
            App.ActiveDocument.addObject('Part::Feature',
                                         'Cut02').Shape = shapeCut1
            newObjectCut_A2 = App.ActiveDocument.ActiveObject
            ####
            App.ActiveDocument.addObject("Part::Cut", "Cut_01")
            App.ActiveDocument.Cut_01.Base = App.ActiveDocument.getObject(
                newObjectCut_A1.Name)
            App.ActiveDocument.Cut_01.Tool = App.ActiveDocument.getObject(
                newObjectCut_A2.Name)
            shapeCutMake = App.ActiveDocument.ActiveObject
            App.ActiveDocument.recompute()
            Gui.ActiveDocument.activeObject().ShapeColor = colorCut1
            ####
            shapeCut01 = _part.getShape(App.ActiveDocument.getObject(
                shapeCutMake.Name),
                                        '',
                                        needSubElement=False,
                                        refine=False)
            App.ActiveDocument.addObject('Part::Feature',
                                         'shapeCut01').Shape = shapeCut01
            Gui.ActiveDocument.activeObject().ShapeColor = colorCut1
            if switchRemoveConstructionObject == 1:
                App.ActiveDocument.removeObject(shapeCutMake.Name)
                App.ActiveDocument.removeObject(newObjectCut_A1.Name)
                App.ActiveDocument.removeObject(newObjectCut_A2.Name)
            #### End command Part_Cut First

            #### Begin command Part_Cut Second
            #### create copy
            shapeCut2 = _part.getShape(App.ActiveDocument.getObject(
                sel[1].Name),
                                       '',
                                       needSubElement=False,
                                       refine=False)
            App.ActiveDocument.addObject('Part::Feature',
                                         'Cut01').Shape = shapeCut2
            newObjectCut_A1 = App.ActiveDocument.ActiveObject
            shapeCut2 = _part.getShape(App.ActiveDocument.getObject(
                sel[0].Name),
                                       '',
                                       needSubElement=False,
                                       refine=False)
            App.ActiveDocument.addObject('Part::Feature',
                                         'Cut02').Shape = shapeCut2
            newObjectCut_A2 = App.ActiveDocument.ActiveObject
            ####
            App.ActiveDocument.addObject("Part::Cut", "Cut_02")
            App.ActiveDocument.Cut_02.Base = App.ActiveDocument.getObject(
                newObjectCut_A1.Name)
            App.ActiveDocument.Cut_02.Tool = App.ActiveDocument.getObject(
                newObjectCut_A2.Name)
            shapeCutMake = App.ActiveDocument.ActiveObject
            App.ActiveDocument.recompute()
            Gui.ActiveDocument.activeObject().ShapeColor = colorCut2
            ####
            shapeCut02 = _part.getShape(App.ActiveDocument.getObject(
                shapeCutMake.Name),
                                        '',
                                        needSubElement=False,
                                        refine=False)
            App.ActiveDocument.addObject('Part::Feature',
                                         'shapeCut02').Shape = shapeCut02
            Gui.ActiveDocument.activeObject().ShapeColor = colorCut2
            if switchRemoveConstructionObject == 1:
                App.ActiveDocument.removeObject(shapeCutMake.Name)
                App.ActiveDocument.removeObject(newObjectCut_A1.Name)
                App.ActiveDocument.removeObject(newObjectCut_A2.Name)
            #### End command Part_Cut Second

            #### Begin command Part_Fuse
            #### create copy
            shapeFuse1 = _part.getShape(App.ActiveDocument.getObject(
                sel[1].Name),
                                        '',
                                        needSubElement=False,
                                        refine=False)
            App.ActiveDocument.addObject('Part::Feature',
                                         'Fuse01').Shape = shapeFuse1
            newObjectFuse1 = App.ActiveDocument.ActiveObject
            shapeFuse2 = _part.getShape(App.ActiveDocument.getObject(
                sel[0].Name),
                                        '',
                                        needSubElement=False,
                                        refine=False)
            App.ActiveDocument.addObject('Part::Feature',
                                         'Fuse02').Shape = shapeFuse2
            newObjectFuse2 = App.ActiveDocument.ActiveObject
            ####
            App.ActiveDocument.addObject("Part::MultiFuse", "Fusion")
            App.ActiveDocument.Fusion.Shapes = [
                App.ActiveDocument.getObject(newObjectFuse1.Name),
                App.ActiveDocument.getObject(newObjectFuse2.Name),
            ]
            shapeCutFusion = App.ActiveDocument.ActiveObject
            App.ActiveDocument.recompute()
            Gui.ActiveDocument.activeObject().ShapeColor = colorFuse
            ####
            shapeFusion = _part.getShape(App.ActiveDocument.getObject(
                shapeCutFusion.Name),
                                         '',
                                         needSubElement=False,
                                         refine=False)
            App.ActiveDocument.addObject('Part::Feature',
                                         'shapeFusion').Shape = shapeFusion
            Gui.ActiveDocument.activeObject().ShapeColor = colorFuse
            if switchRemoveConstructionObject == 1:
                App.ActiveDocument.removeObject(shapeCutFusion.Name)
                App.ActiveDocument.removeObject(newObjectFuse1.Name)
                App.ActiveDocument.removeObject(newObjectFuse2.Name)
            #### End command Part_Fuse
            App.ActiveDocument.commitTransaction()  #undo reg.
        except Exception as err:
            App.Console.PrintError("'makeIt' Failed. "
                                   "{err}\n".format(err=str(err)))
            exc_type, exc_obj, exc_tb = sys.exc_info()
            fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
            print(exc_type, fname, exc_tb.tb_lineno)
Ejemplo n.º 22
0
    def Activated(self):
        try:
            #### Config Begin ####
            switchRemoveConstructionObject = self.askQuestion(
            )  # if 0= (NO) not removed creation objects 1= (YES) remove objects
            #### Config End ####
            App.ActiveDocument.openTransaction(
                translate("Design456", "UnifySplitFuse1"))
            selectedEdge = Gui.Selection.getSelectionEx()
            sel = selObjects = Gui.Selection.getSelection()
            try:
                subElementName = Gui.Selection.getSelectionEx(
                )[0].SubElementNames[0]  # for color first face selected
            except:
                subElementName = Gui.Selection.getSelectionEx(
                )[0].SubObjects[0]

            if (len(sel) != 2):
                # Two object must be selected
                errMessage = "Select two objects to use the Tool"
                faced.getInfo(sel).errorDialog(errMessage)
                return

            try:
                colorFace = App.ActiveDocument.getObject(
                    sel[0].Name).ViewObject.DiffuseColor[int(
                        SubElementName[4:]) - 1]  # color face selected
                ##App.ActiveDocument.getObject(sel[0].Name).ViewObject.DiffuseColor[int(SubElementName[4:])-1] = colorFace# give color on face
            except Exception:
                colorFace = App.ActiveDocument.getObject(
                    sel[0].Name).ViewObject.DiffuseColor[
                        0]  # color face selected [0]

            ### Begin command Part_ElementCopy First selection
            newFace1 = _part.getShape(App.ActiveDocument.getObject(
                sel[0].Name),
                                      selectedEdge[0].SubElementNames[0],
                                      needSubElement=True,
                                      refine=False).copy()
            App.ActiveDocument.addObject('Part::Feature',
                                         'Face1').Shape = newFace1
            shapeFace1 = App.ActiveDocument.ActiveObject
            ####

            ### Begin command Part_ElementCopy Second selection
            try:  # independent object
                newFace2 = _part.getShape(App.ActiveDocument.getObject(
                    sel[1].Name),
                                          selectedEdge[1].SubElementNames[0],
                                          needSubElement=True,
                                          refine=False).copy()
            except Exception:
                # same object other face  TODO: This will fail if you have a sphere shape or a ball Mariwan 2021-03-18
                newFace2 = _part.getShape(App.ActiveDocument.getObject(
                    sel[0].Name),
                                          selectedEdge[0].SubElementNames[1],
                                          needSubElement=True,
                                          refine=False).copy()

            App.ActiveDocument.addObject('Part::Feature',
                                         'Face2').Shape = newFace2
            shapeFace2 = App.ActiveDocument.ActiveObject
            App.ActiveDocument.recompute()
            ### End command Part_ElementCopy

            ### Begin command Part_Loft
            attached = App.ActiveDocument.addObject('Part::Loft', 'Attached')
            attached.Sections = [
                App.ActiveDocument.Face1,
                App.ActiveDocument.Face2,
            ]
            attached.Solid = True
            attached.Ruled = False
            attached.Closed = False
            ### End command Part_Loft

            ### Begin command Part_Fuse
            fusion = App.ActiveDocument.addObject("Part::MultiFuse", "Fusion")
            try:  # multiple objects
                App.ActiveDocument.Fusion.Shapes = [
                    App.ActiveDocument.getObject(selObjects[0].Name),
                    App.ActiveDocument.Attached,
                    App.ActiveDocument.getObject(selObjects[1].Name),
                ]
            except Exception:  # single object
                App.ActiveDocument.Fusion.Shapes = [
                    App.ActiveDocument.getObject(selObjects[0].Name),
                    App.ActiveDocument.Attached,
                    App.ActiveDocument.getObject(selObjects[0].Name),
                ]
            App.ActiveDocument.recompute()
            ### End command Part_Fuse

            # create single object
            _part.show(fusion.Shape.copy())
            App.ActiveDocument.ActiveObject.ViewObject.DiffuseColor = colorFace  # give face color on object
            App.ActiveDocument.ActiveObject.Label = sel[
                0].Label + "_" + subElementName

            ##### removeObject work
            if switchRemoveConstructionObject == 1:
                App.ActiveDocument.removeObject(selObjects[0].Name)
                try:  # multiple objects
                    App.ActiveDocument.removeObject(selObjects[1].Name)
                except Exception:  # single object
                    None
                App.ActiveDocument.removeObject(attached.Name)
                App.ActiveDocument.removeObject(fusion.Name)
                App.ActiveDocument.removeObject(shapeFace1.Name)
                App.ActiveDocument.removeObject(shapeFace2.Name)
            App.ActiveDocument.commitTransaction()  #undo reg.
        except Exception as err:
            App.Console.PrintError("'UnifySplitFuse1' Failed. "
                                   "{err}\n".format(err=str(err)))
            exc_type, exc_obj, exc_tb = sys.exc_info()
            fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
            print(exc_type, fname, exc_tb.tb_lineno)
Ejemplo n.º 23
0
    def Activated(self):
        try:
            s = Gui.Selection.getSelectionEx()
            if (len(s) < 1):
                # One object must be selected at least
                errMessage = "Select a face or an edge use Fillet"
                faced.getInfo(s).errorDialog(errMessage)
                return
            Radius = QtGui.QInputDialog.getDouble(None, "Fillet Radius",
                                                  "Radius:", 0, 1.0, 20.0,
                                                  2)[0]
            if (Radius == 0):
                return
            tempNewObj = App.ActiveDocument.addObject("Part::Fillet",
                                                      "tempFillet")
            sub1 = s[0]
            tempNewObj.Base = sub1.Object
            names = sub1.SubElementNames
            print(names)
            EdgesToBeChanged = []
            if (len(names) != 0):
                counter = 1
                """ we need to take the rest of the string
							i.e. 'Edge15' --> take out 'Edge'-->4 bytes
							len('Edge')] -->4
				"""
                for name in names:
                    edgeNumbor = int(name[4:len(name)])
                    EdgesToBeChanged.append((edgeNumbor, Radius, Radius))
                print(EdgesToBeChanged)
                tempNewObj.Edges = EdgesToBeChanged
            else:
                errMessage = "Fillet failed. No subelements found"
                faced.getInfo(s).errorDialog(errMessage)
                return

            if tempNewObj.isValid() == False:
                App.ActiveDocument.removeObject(tempNewObj.Name)
                # Shape is not OK
                errMessage = "Failed to fillet the objects"
                faced.getInfo(s).errorDialog(errMessage)
            else:
                # Make a simple copy of the object
                App.ActiveDocument.recompute()
                newShape = Part.getShape(tempNewObj,
                                         '',
                                         needSubElement=False,
                                         refine=False)
                newObj = App.ActiveDocument.addObject(
                    'Part::Feature', 'Fillet').Shape = newShape
                App.ActiveDocument.recompute()
                App.ActiveDocument.ActiveObject.Label = 'Fillet'

                App.ActiveDocument.removeObject(sub1.Object.Name)
                App.ActiveDocument.removeObject(tempNewObj.Name)
            App.ActiveDocument.recompute()
            del EdgesToBeChanged[:]

        except Exception as err:
            App.Console.PrintError("'Fillet' Failed. "
                                   "{err}\n".format(err=str(err)))
            exc_type, exc_obj, exc_tb = sys.exc_info()
            fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
            print(exc_type, fname, exc_tb.tb_lineno)
Ejemplo n.º 24
0
    def Activated(self):
        try:

            s = Gui.Selection.getSelectionEx()
            if (len(s) < 1):
                # An object must be selected
                errMessage = "Select an object to use Extrude Face"
                faced.getInfo(s).errorDialog(errMessage)
                return
            lengthForward = QtGui.QInputDialog.getDouble(
                None, "Get value", "Input:", 0, -10000.0, 10000.0, 2)[0]
            if(lengthForward == 0):
                return  # nothing to do here

            objName = s[0].ObjectName
            sh = s[0].Object.Shape.copy()
            if hasattr(s[0].Object, "getGlobalPlacement"):
                gpl = s[0].Object.getGlobalPlacement()
                sh.Placement = gpl
            name = s[0].SubElementNames[0]
            fullname = objName+"_"+name  # Name of the face extracted
            newobj = s[0].Document.addObject("Part::Feature", fullname)
            newobj.Shape = sh.getElement(name)
            selection = newobj  # The face extraced
            activeSel = Gui.Selection.getSelection(App.ActiveDocument.Name)
            Gui.Selection.removeSelection(activeSel[0])
            # Select the face extracted before
            Gui.Selection.addSelection(selection)
            App.ActiveDocument.recompute()
            m = App.activeDocument().getObject(fullname)
            f = App.activeDocument().addObject(
                'Part::Extrusion', 'ExtrudeFace')	  # Add extrusion
            f.Base = newobj				# App.activeDocument().getObject(fullname)
            f.DirMode = "Normal"
            f.DirLink = None
            f.LengthFwd = lengthForward
            f.LengthRev = 0.0
            f.Solid = True
            f.Reversed = False
            f.Symmetric = False
            f.TaperAngle = 0.0
            f.TaperAngleRev = 0.0
            App.ActiveDocument.recompute()
            newPart_ = App.ActiveDocument.addObject(
                'Part::Feature', f.Name+'N')
            newPart_.Shape = Part.getShape(
                f, '', needSubElement=False, refine=False)
            if newPart_.isValid() == False:
                App.ActiveDocument.removeObject(newPart_.Name)
                App.ActiveDocument.removeObject(f.Name)
                # Shape is not OK
                errMessage = "Failed to extrude the Face"
                faced.getInfo(m).errorDialog(errMessage)
            else:
                # remove old objects
                App.ActiveDocument.removeObject(f.Name)
                App.ActiveDocument.removeObject(m.Name)
                # This will not work for split objects as they are not two separate objects.2021-02-22
                # Make the two objects merged
                obj1 = App.ActiveDocument.getObject(s[0].ObjectName)
                obj2 = newPart_
                selections = Gui.Selection.getSelectionEx()
                for i in selections:
                    Gui.Selection.removeSelection(selections)
                    Gui.Selection.addSelection(obj1)
                    Gui.Selection.addSelection(obj2)
                    Gui.runCommand('Design456_Part_Merge', 0)
            App.ActiveDocument.recompute()

            return
        except Exception as err:
            App.Console.PrintError("'ExtrudeFace' Failed. "
                                   "{err}\n".format(err=str(err)))
            exc_type, exc_obj, exc_tb = sys.exc_info()
            fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
            print(exc_type, fname, exc_tb.tb_lineno)
Ejemplo n.º 25
0
    def Activated(self):
        try:
            # Save object name that will be divided.
            selection = Gui.Selection.getSelectionEx()
            if (len(selection) < 1):
                # An object must be selected
                errMessage = "Select an object to use Split Tool"
                faced.getInfo(selection).errorDialog(errMessage)
                return
            shape = selection[0].Object.Shape
            bb = shape.BoundBox
            length = max(bb.XLength, bb.YLength, bb.ZLength)

            nameOfselectedObject = selection[0].ObjectName
            totalName = nameOfselectedObject + '_cs'
            """ slow function . . you need to use wait before getting 
				the answer as the execution is continuing down """
            Gui.runCommand('Part_CrossSections', 0)
            gcompund = App.ActiveDocument.addObject("Part::Compound",
                                                    "Compound")

            App.ActiveDocument.recompute()

            # get object name
            # We need this delay to let user choose the split form. And
            getExtrude_cs = None  # Dummy variable used to wait for the Extrude_cs be made
            while (getExtrude_cs is None):
                getExtrude_cs = App.ActiveDocument.getObject(totalName)
                _sleep(.1)
                Gui.updateGui()
            # Begin command Part_Compound
            gcompund.Links = [
                getExtrude_cs,
            ]

            # Begin command Part_BooleanFragments
            j = SPLIT.makeBooleanFragments(name='BooleanFragments')
            j.Objects = [
                gcompund,
                App.ActiveDocument.getObject(nameOfselectedObject)
            ]
            j.Mode = 'Standard'
            j.Proxy.execute(j)
            j.purgeTouched()
            App.ActiveDocument.recompute()
            if j.isValid() == False:
                App.ActiveDocument.removeObject(j.Name)
                # Shape is not OK
                errMessage = "Failed to fillet the objects"
                faced.getInfo(selection).errorDialog(errMessage)
            else:
                # Make a simple copy
                newShape = Part.getShape(j,
                                         '',
                                         needSubElement=False,
                                         refine=False)
                NewJ = App.ActiveDocument.addObject(
                    'Part::Feature', 'SplitedObject').Shape = newShape
                # Remove Old objects
                for obj in j.Objects:
                    App.ActiveDocument.removeObject(obj.Name)
                App.ActiveDocument.removeObject(totalName)
                App.ActiveDocument.removeObject(j.Name)

            App.ActiveDocument.recompute()
        except Exception as err:
            App.Console.PrintError("'SplitObject' Failed. "
                                   "{err}\n".format(err=str(err)))
            exc_type, exc_obj, exc_tb = sys.exc_info()
            fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
            print(exc_type, fname, exc_tb.tb_lineno)
Ejemplo n.º 26
0
    def makeIt(self, commandType):
        try:
            nObjects = []
            newShape = None
            simpl_cpy = None
            self.commandType = commandType
            selection = Gui.Selection.getSelectionEx()
            # Two object must be selected
            if (len(selection) < 2 or len(selection) > 2):
                errMessage = "Select two objects to use Common 2D Tool"
                faced.getInfo(selection).errorDialog(errMessage)
                return None
            else:
                nObjects.clear()
                GlobalPlacement = App.ActiveDocument.getObject(
                    selection[0].Object.Name).Placement
                for a2dobj in selection:
                    m = App.ActiveDocument.getObject(a2dobj.Object.Name)
                    f = App.ActiveDocument.addObject('Part::Extrusion',
                                                     'ExtrudeOriginal')
                    f.Base = App.ActiveDocument.getObject(m.Name)
                    f.DirMode = "Normal"
                    f.DirLink = a2dobj.Object
                    if faced.getDirectionAxis() == "x":
                        f.Dir = (1, 0, 0)
                    elif faced.getDirectionAxis() == "y":
                        f.Dir = (0, 1, 0)
                    else:
                        f.Dir = (0, 0, 1)

                    f.LengthFwd = 1.00
                    f.LengthRev = 0.0
                    f.Solid = True
                    f.Reversed = False
                    f.Symmetric = False
                    f.TaperAngle = 0.0
                    f.TaperAngleRev = 0.0
                    App.ActiveDocument.recompute()

                    # Make a simple copy of the object
                    newShape = _part.getShape(f,
                                              '',
                                              needSubElement=False,
                                              refine=True)
                    newObj = App.ActiveDocument.addObject(
                        'Part::Feature', 'Extrude')
                    newObj.Shape = newShape
                    App.ActiveDocument.recompute()
                    App.ActiveDocument.ActiveObject.Label = f.Label
                    App.ActiveDocument.recompute()
                    App.ActiveDocument.removeObject(f.Name)
                    App.ActiveDocument.removeObject(m.Name)
                    App.ActiveDocument.recompute()
                    nObjects.append(newObj)

                tempResult = self.DoCommand(
                    self.commandType)  #Create the common 3D shape
                if (self.commandType == 1 or self.commandType == 3):
                    tempResult.Shapes = nObjects
                    tempResult.Refine = True
                elif (self.commandType == 2):
                    tempResult.Tool = nObjects[1]
                    tempResult.Base = nObjects[0]
                App.ActiveDocument.recompute()
                #Make a simple version
                newShape = _part.getShape(tempResult,
                                          '',
                                          needSubElement=False,
                                          refine=False)
                simpl_cpy = App.ActiveDocument.addObject(
                    'Part::Feature', 'Shape')
                simpl_cpy.Shape = newShape  #simple version of the 3D common
                App.ActiveDocument.recompute()
                for name in nObjects:
                    App.ActiveDocument.removeObject(name.Name)
                App.ActiveDocument.removeObject(tempResult.Name)
                App.ActiveDocument.recompute()
            # Extract the face
            sh = simpl_cpy.Shape.copy()
            #sh.Placement = GlobalPlacement  # Result.Placement
            sh.Placement.Base.z = -1

            Gui.Selection.clearSelection()
            App.ActiveDocument.recompute()
            Gui.Selection.addSelection(App.ActiveDocument.Name, simpl_cpy.Name)
            s = Gui.Selection.getSelectionEx()[0]
            faceName = faced.SelectTopFace(simpl_cpy).Activated()

            newobj = App.ActiveDocument.addObject("Part::Feature",
                                                  self.localShapeName)
            print(faceName)
            newobj.Shape = sh.getElement(faceName)
            App.ActiveDocument.removeObject(simpl_cpy.Name)
            del nObjects[:]
        except Exception as err:
            App.Console.PrintError("'makeIt' Failed. "
                                   "{err}\n".format(err=str(err)))
            exc_type, exc_obj, exc_tb = sys.exc_info()
            fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
            print(exc_type, fname, exc_tb.tb_lineno)