Example #1
0
    def execute(self, selfobj):
        """ Doing a recomputation.
        """
        m_properties_list = ['Edge',
                             'Point1',
                             'Point2',
                             'IndexPart',
                             'NumberLinePart'
                             ]
        for m_property in m_properties_list:
            if m_property not in selfobj.PropertiesList:
                return

        if M_DEBUG:
            print("running CenterLinePoint.execute !")

        # To be compatible with previous version > 2019
        if 'Parametric' in selfobj.PropertiesList:
            # Create the object the first time regardless
            # the parametric behavior
            if selfobj.Parametric == 'Not' and self.created:
                return
            if selfobj.Parametric == 'Interactive' and self.created:
                return
        # To be compatible with previous version 2018
        if 'parametric' in selfobj.PropertiesList:
            self.execute_2018(selfobj)

        try:
            vector_point = None
            if selfobj.Point1 is not None and selfobj.Point2 is not None:
                # n1 = eval(selfobj.Point1[1][0].lstrip('Vertex'))
                # n2 = eval(selfobj.Point2[1][0].lstrip('Vertex'))
                m_n1 = re.sub('[^0-9]', '', selfobj.Point1[1][0])
                m_n2 = re.sub('[^0-9]', '', selfobj.Point2[1][0])
                m_n1 = int(m_n1)
                m_n2 = int(m_n2)
                if M_DEBUG:
                    print_msg(str(selfobj.Point1))
                    print_msg(str(selfobj.Point2))
                    print_msg("m_n1 = " + str(m_n1))
                    print_msg("m_n2 = " + str(m_n2))

                point1 = selfobj.Point1[0].Shape.Vertexes[m_n1 - 1].Point
                point2 = selfobj.Point2[0].Shape.Vertexes[m_n2 - 1].Point

                vector_point = alongTwoPointsPoint(point1,
                                                   point2,
                                                   selfobj.IndexPart,
                                                   selfobj.NumberLinePart)
            elif selfobj.Edge is not None:
                m_n = re.sub('[^0-9]', '', selfobj.Edge[1][0])
                m_n = int(m_n)
                if M_DEBUG:
                    print_msg(str(selfobj.Edge))
                    print_msg("m_n = " + str(m_n))

                if not selfobj.Edge[0].Shape.Edges:
                    return

                vector_point = alongLinePoint(selfobj.Edge[0].Shape.Edges[m_n - 1],
                                              selfobj.IndexPart,
                                              selfobj.NumberLinePart)
            if vector_point is not None:
                point = Part.Point(vector_point)
                selfobj.Shape = point.toShape()
                propertiesPoint(selfobj.Label, self.color)
                selfobj.X = float(vector_point.x)
                selfobj.Y = float(vector_point.y)
                selfobj.Z = float(vector_point.z)
                # To be compatible with previous version 2018
                if 'Parametric' in selfobj.PropertiesList:
                    self.created = True
        except AttributeError as err:
            print("AttributeError" + str(err))
        except Exception as err:
            printError_msg(err.args[0], title=M_MACRO)
Example #2
0
    def draw(self):
        #Helper variables
        mountHoleSpacing = gv.zRodSupportLength + 2 * gv.slotPadding + gv.slotDia

        try:
            App.getDocument(self.name).recompute()
            App.closeDocument(self.name)
            App.setActiveDocument("")
            App.ActiveDocument = None
        except:
            pass

        #make document
        App.newDocument(self.name)
        App.setActiveDocument(self.name)
        App.ActiveDocument = App.getDocument(self.name)

        #extrude verticalBar
        uf.extrudeFrameMember(self.name, gv.vertBarLength)

        #Make Holes for xRodSupports
        #Sketch Points
        p1x = 0
        p1y = gv.vertBarLength
        p2x = p1x
        p2y = gv.vertBarLength - gv.vertBarDistAboveZRod - gv.zRodSupportLength / 2 + mountHoleSpacing / 2
        p3x = p1x
        p3y = gv.vertBarLength - gv.vertBarDistAboveZRod - gv.zRodSupportLength / 2 - mountHoleSpacing / 2
        p4x = p1x
        p4y = gv.vertBarDistBelowZRod + gv.zRodSupportLength / 2 + mountHoleSpacing / 2
        p5x = p1x
        p5y = gv.vertBarDistBelowZRod + gv.zRodSupportLength / 2 - mountHoleSpacing / 2
        p6x = p1x
        p6y = 0
        p7x = p1x
        p7y = gv.vertBarLength - (gv.zRodSupportLength / 2 +
                                  gv.vertBarDistAboveZRod)
        p8x = p1x
        p8y = gv.vertBarDistBelowZRod + gv.zRodSupportLength / 2

        #Make Sketch
        App.activeDocument().addObject('Sketcher::SketchObject', 'Sketch001')
        App.activeDocument().Sketch001.Support = uf.getFace(
            App.ActiveDocument.Pad, gv.vertBarLength / 2, 0, None, None,
            gv.frameHeight / 2, 0)
        App.activeDocument().recompute()
        App.ActiveDocument.Sketch001.addExternal(
            "Pad",
            uf.getEdge(App.ActiveDocument.Pad, gv.vertBarLength, 0, None, None,
                       gv.frameHeight / 2, 0))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addGeometry(
            Part.Line(App.Vector(p1x, p1y, 0), App.Vector(p2x, p2y, 0)))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('PointOnObject', 0, 1, -3))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Vertical', 0))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addGeometry(
            Part.Line(App.Vector(p2x, p2y, 0), App.Vector(p3x, p3y, 0)))
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Coincident', 0, 2, 1, 1))
        App.ActiveDocument.recompute()
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('PointOnObject', 1, 2, -2))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Vertical', 1))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addGeometry(
            Part.Line(App.Vector(p3x, p3y, 0), App.Vector(p4x, p4y, 0)))
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Coincident', 1, 2, 2, 1))
        App.ActiveDocument.recompute()
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Vertical', 2))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addGeometry(
            Part.Line(App.Vector(p4x, p4y, 0), App.Vector(p5x, p5y, 0)))
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Coincident', 2, 2, 3, 1))
        App.ActiveDocument.recompute()
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('PointOnObject', 3, 2, -2))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Vertical', 3))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addGeometry(
            Part.Line(App.Vector(p5x, p5y, 0), App.Vector(p6x, p6y, 0)))
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Coincident', 3, 2, 4, 1))
        App.ActiveDocument.recompute()
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Coincident', 4, 2, -1, 1))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Vertical', 4))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.delConstraint(8)
        App.ActiveDocument.Sketch001.toggleConstruction(4)
        App.ActiveDocument.Sketch001.toggleConstruction(3)
        App.ActiveDocument.Sketch001.toggleConstruction(2)
        App.ActiveDocument.Sketch001.toggleConstruction(1)
        App.ActiveDocument.Sketch001.toggleConstruction(0)
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Equal', 1, 3))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addGeometry(
            Part.Point(App.Vector(p7x, p7y, 0)))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('PointOnObject', 5, 1, 1))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Symmetric', 0, 2, 1, 2, 5, 1))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addGeometry(
            Part.Point(App.Vector(p8x, p8y, 0)))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('PointOnObject', 6, 1, 3))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Symmetric', 3, 2, 2, 2, 6, 1))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addGeometry(
            Part.Circle(App.Vector(p2x, p2y, 0), App.Vector(0, 0, 1),
                        gv.mountToFrameDia / 2))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Coincident', 7, 3, 0, 2))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addGeometry(
            Part.Circle(App.Vector(p3x, p3y, 0), App.Vector(0, 0, 1),
                        gv.mountToFrameDia / 2))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Coincident', 8, 3, 1, 2))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addGeometry(
            Part.Circle(App.Vector(p4x, p4y, 0), App.Vector(0, 0, 1),
                        gv.mountToFrameDia / 2))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Coincident', 9, 3, 2, 2))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addGeometry(
            Part.Circle(App.Vector(p5x, p5y, 0), App.Vector(0, 0, 1),
                        gv.mountToFrameDia / 2))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Coincident', 10, 3, 3, 2))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Equal', 7, 8))
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Equal', 8, 9))
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Equal', 9, 10))
        App.ActiveDocument.recompute()

        #Add dimensions
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Radius', 7, gv.mountToFrameDia / 2))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('DistanceY', 1, -mountHoleSpacing))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint(
                'Distance', 0, 1, 5, 1,
                gv.zRodSupportLength / 2 + gv.vertBarDistAboveZRod))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint(
                'Distance', -1, 1, 6, 1,
                gv.vertBarDistBelowZRod + gv.zRodSupportLength / 2))
        App.ActiveDocument.recompute()
        App.getDocument(self.name).recompute()

        #Cut holes through all
        App.activeDocument().addObject("PartDesign::Pocket", "Pocket")
        App.activeDocument().Pocket.Sketch = App.activeDocument().Sketch001
        App.activeDocument().Pocket.Length = 5.0
        App.ActiveDocument.recompute()
        App.ActiveDocument.Pocket.Length = 5.000000
        App.ActiveDocument.Pocket.Type = 1
        App.ActiveDocument.Pocket.UpToFace = None
        App.ActiveDocument.recompute()
Example #3
0
    def draw(self):
        if self.side == "Right":
            self.rodDia = gv.yRodDiaR
            self.bushingNutFaceToFace = gv.yBushingNutR[2]
            self.bushingNutThickness = gv.yBushingNutR[3]
        elif self.side == "Left":
            self.rodDia = gv.yRodDiaL
            self.bushingNutFaceToFace = gv.yBushingNutL[2]
            self.bushingNutThickness = gv.yBushingNutL[3]

        #helper Variables

        columnWidth = gv.PBBHMaxFaceToFace / math.cos(
            math.pi / 6) + 2 * gv.bushingNutPadding

        #Make file and build part
        try:
            App.getDocument(self.name).recompute()
            App.closeDocument(self.name)
            App.setActiveDocument("")
            App.ActiveDocument = None
        except:
            pass

        #Create Document
        App.newDocument(self.name)
        App.setActiveDocument(self.name)
        App.ActiveDocument = App.getDocument(self.name)

        #Make base
        #Sketch points
        p1x = -gv.printBedBusingSupportWidth / 2
        p1y = -gv.PBBHDepth / 2
        p2x = -gv.printBedBusingSupportWidth / 2
        p2y = gv.PBBHDepth / 2
        p3x = gv.printBedBusingSupportWidth / 2
        p3y = gv.PBBHDepth / 2
        p4x = gv.printBedBusingSupportWidth / 2
        p4y = -gv.PBBHDepth / 2

        #Make Sketch
        App.activeDocument().addObject('Sketcher::SketchObject', 'Sketch')
        App.activeDocument().Sketch.Placement = App.Placement(
            App.Vector(0.000000, 0.000000, 0.000000),
            App.Rotation(0.000000, 0.000000, 0.000000, 1.000000))

        App.ActiveDocument.Sketch.addGeometry(
            Part.Line(App.Vector(p1x, p1y, 0), App.Vector(p4x, p4y, 0)))
        App.ActiveDocument.Sketch.addGeometry(
            Part.Line(App.Vector(p4x, p4y, 0), App.Vector(p3x, p3y, 0)))
        App.ActiveDocument.Sketch.addGeometry(
            Part.Line(App.Vector(p3x, p3y, 0), App.Vector(p2x, p2y, 0)))
        App.ActiveDocument.Sketch.addGeometry(
            Part.Line(App.Vector(p2x, p2y, 0), App.Vector(p1x, p1y, 0)))
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('Coincident', 0, 2, 1, 1))
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('Coincident', 1, 2, 2, 1))
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('Coincident', 2, 2, 3, 1))
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('Coincident', 3, 2, 0, 1))
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('Horizontal', 0))
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('Horizontal', 2))
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('Vertical', 1))
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('Vertical', 3))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('Symmetric', 1, 2, 0, 1, -1, 1))
        App.ActiveDocument.recompute()

        #add dimensions
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('DistanceY', 1, gv.PBBHDepth))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('DistanceX', 0, gv.printBedBusingSupportWidth))
        App.ActiveDocument.recompute()
        App.getDocument(self.name).recompute()

        #Pad base
        App.activeDocument().addObject("PartDesign::Pad", "Pad")
        App.activeDocument().Pad.Sketch = App.activeDocument().Sketch
        App.activeDocument().Pad.Length = 10.0
        App.ActiveDocument.recompute()
        App.ActiveDocument.Pad.Length = gv.tabThickness
        App.ActiveDocument.Pad.Reversed = 0
        App.ActiveDocument.Pad.Midplane = 0
        App.ActiveDocument.Pad.Length2 = 100.000000
        App.ActiveDocument.Pad.Type = 0
        App.ActiveDocument.Pad.UpToFace = None
        App.ActiveDocument.recompute()

        #Cut slot on right side
        #Sketch points
        p1x = gv.printBedBusingSupportWidth / 2 - gv.slotPadding - gv.printedToPrintedDia / 2 - gv.slotWidth
        p1y = 0
        p2x = gv.printBedBusingSupportWidth / 2 - gv.slotPadding - gv.printedToPrintedDia / 2
        p2y = 0
        p3x = gv.printBedBusingSupportWidth / 2 - gv.slotPadding - gv.printedToPrintedDia / 2 - gv.slotWidth
        p3y = -gv.printedToPrintedDia / 2
        p4x = gv.printBedBusingSupportWidth / 2 - gv.slotPadding - gv.printedToPrintedDia / 2 - gv.slotWidth
        p4y = gv.printedToPrintedDia / 2
        p5x = gv.printBedBusingSupportWidth / 2 - gv.slotPadding - gv.printedToPrintedDia / 2
        p5y = gv.printedToPrintedDia / 2
        p6x = gv.printBedBusingSupportWidth / 2 - gv.slotPadding - gv.printedToPrintedDia / 2
        p6y = -gv.printedToPrintedDia / 2
        p7x = gv.printBedBusingSupportWidth / 2 - gv.slotPadding
        p7y = 0

        #Make sketch
        App.activeDocument().addObject('Sketcher::SketchObject', 'Sketch001')
        App.activeDocument().Sketch001.Support = uf.getFace(
            App.ActiveDocument.Pad, None, None, None, None, gv.tabThickness, 0)
        App.activeDocument().recompute()
        App.ActiveDocument.Sketch001.addExternal(
            "Pad",
            uf.getEdge(App.ActiveDocument.Pad, 0, 1, 0, 0, gv.tabThickness, 0))

        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addGeometry(
            Part.ArcOfCircle(
                Part.Circle(App.Vector(p1x, p1y, 0), App.Vector(0, 0, 1),
                            4.217310), math.pi / 2, -math.pi / 2))
        App.ActiveDocument.Sketch001.addGeometry(
            Part.ArcOfCircle(
                Part.Circle(App.Vector(p2x, p2y, 0), App.Vector(0, 0, 1),
                            4.217310), -math.pi / 2, math.pi / 2))
        App.ActiveDocument.Sketch001.addGeometry(
            Part.Line(App.Vector(p3x, p3y, 0), App.Vector(p6x, p6y, 0)))
        App.ActiveDocument.Sketch001.addGeometry(
            Part.Line(App.Vector(p4x, p4y, 0), App.Vector(p5x, p5y, 0)))
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Tangent', 0, 2))
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Tangent', 0, 3))
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Tangent', 1, 2))
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Tangent', 1, 3))
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Coincident', 0, 1, 3, 1))
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Coincident', 0, 2, 2, 1))
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Coincident', 2, 2, 1, 1))
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Coincident', 3, 2, 1, 2))
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Horizontal', 2))
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Equal', 0, 1))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('PointOnObject', 0, 3, -1))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addGeometry(
            Part.Point(App.Vector(32.724319, -0.106919, 0)))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('PointOnObject', 4, 1, -1))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('PointOnObject', 4, 1, 1))

        #add dimensions
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('DistanceX', 2, gv.slotWidth))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Radius', 1, gv.printedToPrintedDia / 2))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Distance', 4, 1, -3, gv.slotPadding))
        App.ActiveDocument.recompute()
        App.getDocument(self.name).recompute()

        #Cut slot through all
        App.activeDocument().addObject("PartDesign::Pocket", "Pocket")
        App.activeDocument().Pocket.Sketch = App.activeDocument().Sketch001
        App.activeDocument().Pocket.Length = 5.0
        App.ActiveDocument.recompute()
        App.ActiveDocument.Pocket.Length = 5.000000
        App.ActiveDocument.Pocket.Type = 1
        App.ActiveDocument.Pocket.UpToFace = None
        App.ActiveDocument.recompute()

        #Mirror the slot
        App.activeDocument().addObject("PartDesign::Mirrored", "Mirrored")
        App.ActiveDocument.recompute()
        App.activeDocument().Mirrored.Originals = [
            App.activeDocument().Pocket,
        ]
        App.activeDocument().Mirrored.MirrorPlane = (
            App.activeDocument().Sketch001, ["V_Axis"])
        App.ActiveDocument.Mirrored.Originals = [
            App.ActiveDocument.Pocket,
        ]
        App.ActiveDocument.Mirrored.MirrorPlane = (
            App.ActiveDocument.Sketch001, ["V_Axis"])
        App.ActiveDocument.recompute()

        #Make bushing holder column
        #Sketch Points
        p1x = -columnWidth / 2
        p1y = gv.tabThickness
        p2x = -columnWidth / 2
        p2y = gv.PBBHStandoff
        p3x = 0
        p3y = gv.PBBHStandoff
        p4x = columnWidth / 2
        p4y = gv.PBBHStandoff
        p5x = columnWidth / 2
        p5y = gv.tabThickness

        #Make Sketch
        App.activeDocument().addObject('Sketcher::SketchObject', 'Sketch002')
        App.activeDocument().Sketch002.Support = uf.getFace(
            App.ActiveDocument.Mirrored, 0, 0, -gv.PBBHDepth / 2, 0, None,
            None)
        App.activeDocument().recompute()
        App.ActiveDocument.Sketch002.addExternal(
            "Mirrored",
            uf.getEdge(App.ActiveDocument.Mirrored, 0, 0, -gv.PBBHDepth / 2, 0,
                       gv.tabThickness, 0))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch002.addGeometry(
            Part.Line(App.Vector(p1x, p1y, 0), App.Vector(p2x, p2y, 0)))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('PointOnObject', 0, 1, -3))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('Vertical', 0))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch002.addGeometry(
            Part.ArcOfCircle(
                Part.Circle(App.Vector(p3x, p3y, 0), App.Vector(0, 0, 1),
                            self.rodDia / 2 + gv.bushingNutRodGap), 0,
                math.pi))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('PointOnObject', 1, 3, -2))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('Coincident', 1, 2, 0, 2))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch002.addGeometry(
            Part.Line(App.Vector(p4x, p4y, 0), App.Vector(p5x, p5y, 0)))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('Coincident', 2, 1, 1, 1))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('PointOnObject', 2, 2, -3))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('Vertical', 2))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch002.addGeometry(
            Part.Line(App.Vector(p5x, p5y, 0), App.Vector(p1x, p1y, 0)))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('Coincident', 3, 1, 2, 2))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('Coincident', 3, 2, 0, 1))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('Equal', 0, 2))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('Symmetric', 1, 1, 0, 2, 1, 3))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch002.addGeometry(
            Part.Circle(App.Vector(p3x, p3y, 0), App.Vector(0, 0, 1),
                        self.rodDia / 2 + gv.bushingNutRodGap))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('Coincident', 4, 3, 1, 3))
        App.ActiveDocument.recompute()

        #Add dimensions
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('Distance', 0, 1, 2, 2, columnWidth))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('Distance', -1, 1, 1, 3, gv.PBBHStandoff))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('Radius', 4,
                                self.rodDia / 2 + gv.bushingNutRodGap))
        App.ActiveDocument.recompute()
        App.getDocument(self.name).recompute()

        #Extrude column
        App.activeDocument().addObject("PartDesign::Pad", "Pad001")
        App.activeDocument().Pad001.Sketch = App.activeDocument().Sketch002
        App.activeDocument().Pad001.Length = 10.0
        App.ActiveDocument.recompute()
        App.ActiveDocument.Pad001.Length = gv.PBBHDepth
        App.ActiveDocument.Pad001.Reversed = 1
        App.ActiveDocument.Pad001.Midplane = 0
        App.ActiveDocument.Pad001.Length2 = 100.000000
        App.ActiveDocument.Pad001.Type = 0
        App.ActiveDocument.Pad001.UpToFace = None
        App.ActiveDocument.recompute()

        #Refine shape
        App.ActiveDocument.addObject(
            'Part::Feature',
            'Pad002').Shape = App.ActiveDocument.Pad001.Shape.removeSplitter()
        App.ActiveDocument.ActiveObject.Label = App.ActiveDocument.Pad001.Label
        App.ActiveDocument.recompute()

        #make bushing nut trap
        #Sketch Points
        mat = uf.hexagonPoints(0, gv.PBBHStandoff, self.bushingNutFaceToFace,
                               0)

        p1x = mat[0][0]
        p1y = mat[0][1]
        p2x = mat[1][0]
        p2y = mat[1][1]
        p3x = mat[2][0]
        p3y = mat[2][1]
        p4x = mat[3][0]
        p4y = mat[3][1]
        p5x = mat[4][0]
        p5y = mat[4][1]
        p6x = mat[5][0]
        p6y = mat[5][1]
        p7x = mat[6][0]
        p7y = mat[6][1]
        hexRadius = mat[7][0]

        App.activeDocument().addObject('Sketcher::SketchObject', 'Sketch003')
        App.activeDocument().Sketch003.Support = uf.getFace(
            App.ActiveDocument.Pad002, 0, 0, -gv.PBBHDepth / 2, 0, None, None)
        App.activeDocument().recompute()
        App.ActiveDocument.Sketch003.addGeometry(
            Part.Line(App.Vector(p1x, p1y, 0), App.Vector(p2x, p2y, 0)))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch003.addGeometry(
            Part.Line(App.Vector(p2x, p2y, 0), App.Vector(p3x, p3y, 0)))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch003.addConstraint(
            Sketcher.Constraint('Coincident', 0, 2, 1, 1))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch003.addGeometry(
            Part.Line(App.Vector(p3x, p3y, 0), App.Vector(p4x, p4y, 0)))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch003.addConstraint(
            Sketcher.Constraint('Coincident', 1, 2, 2, 1))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch003.addGeometry(
            Part.Line(App.Vector(p4x, p4y, 0), App.Vector(p5x, p5y, 0)))
        App.ActiveDocument.Sketch003.addConstraint(
            Sketcher.Constraint('Coincident', 2, 2, 3, 1))
        App.ActiveDocument.recompute()
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch003.addGeometry(
            Part.Line(App.Vector(p5x, p5y, 0), App.Vector(p6x, p6y, 0)))
        App.ActiveDocument.Sketch003.addConstraint(
            Sketcher.Constraint('Coincident', 3, 2, 4, 1))
        App.ActiveDocument.recompute()
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch003.addGeometry(
            Part.Line(App.Vector(p6x, p6y, 0), App.Vector(p1x, p1y, 0)))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch003.addConstraint(
            Sketcher.Constraint('Coincident', 4, 2, 5, 1))
        App.ActiveDocument.recompute()
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch003.addConstraint(
            Sketcher.Constraint('Coincident', 5, 2, 0, 1))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch003.addGeometry(
            Part.Circle(App.Vector(p7x, p7y, 0), App.Vector(0, 0, 1),
                        hexRadius))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch003.addConstraint(
            Sketcher.Constraint('PointOnObject', 0, 1, 6))
        App.ActiveDocument.Sketch003.addConstraint(
            Sketcher.Constraint('PointOnObject', 0, 2, 6))
        App.ActiveDocument.Sketch003.addConstraint(
            Sketcher.Constraint('PointOnObject', 1, 2, 6))
        App.ActiveDocument.Sketch003.addConstraint(
            Sketcher.Constraint('PointOnObject', 2, 2, 6))
        App.ActiveDocument.Sketch003.addConstraint(
            Sketcher.Constraint('PointOnObject', 3, 2, 6))
        App.ActiveDocument.Sketch003.addConstraint(
            Sketcher.Constraint('PointOnObject', 4, 2, 6))
        App.ActiveDocument.Sketch003.addConstraint(
            Sketcher.Constraint('Equal', 5, 0))
        App.ActiveDocument.Sketch003.addConstraint(
            Sketcher.Constraint('Equal', 0, 1))
        App.ActiveDocument.Sketch003.addConstraint(
            Sketcher.Constraint('Equal', 1, 2))
        App.ActiveDocument.Sketch003.addConstraint(
            Sketcher.Constraint('Equal', 2, 3))
        App.ActiveDocument.Sketch003.addConstraint(
            Sketcher.Constraint('Equal', 3, 4))
        App.ActiveDocument.Sketch003.toggleConstruction(6)
        App.ActiveDocument.Sketch003.addExternal(
            "Pad002",
            uf.getEdge(App.ActiveDocument.Pad002,
                       0,
                       0,
                       -gv.PBBHDepth / 2,
                       0,
                       None,
                       None,
                       radius=self.rodDia / 2 + gv.bushingNutRodGap))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch003.addConstraint(
            Sketcher.Constraint('Coincident', -3, 3, 6, 3))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch003.addConstraint(
            Sketcher.Constraint('Horizontal', 4))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch003.addConstraint(
            Sketcher.Constraint('Distance', 0, 2, 4,
                                self.bushingNutFaceToFace))
        App.ActiveDocument.recompute()
        App.getDocument(self.name).recompute()

        #cut nut trap out
        App.activeDocument().addObject("PartDesign::Pocket", "Pad003")
        App.activeDocument().Pad003.Sketch = App.activeDocument().Sketch003
        App.activeDocument().Pad003.Length = 5.0
        App.ActiveDocument.recompute()
        App.ActiveDocument.Pad003.Length = gv.yBushingNutR[3]
        App.ActiveDocument.Pad003.Type = 0
        App.ActiveDocument.Pad003.UpToFace = None
        App.ActiveDocument.recompute()
Example #4
0
 def hPointAt(self, x, pos):
     v = self.profile.getHPoint(self.widthAt(x), self.thicknessAt(x))
     vs = Part.Shape([Part.Point(v)])
     vs.rotate(Vector(0, 0, 0), Vector(0, 1, 0), -90)
     vs.translate(pos)
     return vs
Example #5
0
    def draw(self):
        #helper Variables

        xRodClampMountHoleSpacingVert = gv.xRodSpacing - 2 * gv.xRodAxisToMountHoleDist
        xRodClampMountHoleSpacingHoriz = gv.xRodClampWidth - 2 * gv.xRodClampEdgeToMountHoleDist

        #safety check
        #xRodSpacing must be wide enough for the motor to be mounted between the rods

        #Make file and build part
        try:
            App.getDocument('xEndIdlerPlate').recompute()
            App.closeDocument("xEndIdlerPlate")
            App.setActiveDocument("")
            App.ActiveDocument = None
        except:
            pass

        App.newDocument("xEndIdlerPlate")
        App.setActiveDocument("xEndIdlerPlate")
        App.ActiveDocument = App.getDocument("xEndIdlerPlate")

        #Make the plate
        #Sketch points
        p1x = 0
        p1y = 0
        p2x = 0
        p2y = gv.xMotorMountPlateWidth
        p3x = gv.xRodClampWidth
        p3y = gv.xMotorMountPlateWidth
        p4x = gv.xRodClampWidth
        p4y = 0

        #Make Sketch
        App.activeDocument().addObject('Sketcher::SketchObject', 'Sketch')
        App.activeDocument().Sketch.Placement = App.Placement(
            App.Vector(0.000000, 0.000000, 0.000000),
            App.Rotation(0.000000, 0.000000, 0.000000, 1.000000))
        App.ActiveDocument.Sketch.addGeometry(
            Part.Line(App.Vector(p1x, p1y, 0), App.Vector(p2x, p2y, 0)))
        App.ActiveDocument.Sketch.addGeometry(
            Part.Line(App.Vector(p2x, p2y, 0), App.Vector(p3x, p3y, 0)))
        App.ActiveDocument.Sketch.addGeometry(
            Part.Line(App.Vector(p3x, p3y, 0), App.Vector(p4x, p4y, 0)))
        App.ActiveDocument.Sketch.addGeometry(
            Part.Line(App.Vector(p4x, p4y, 0), App.Vector(p1x, p1y, 0)))
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('Coincident', 0, 2, 1, 1))
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('Coincident', 1, 2, 2, 1))
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('Coincident', 2, 2, 3, 1))
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('Coincident', 3, 2, 0, 1))
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('Vertical', 0))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('Vertical', 2))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('Horizontal', 3))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('Horizontal', 1))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('Coincident', 0, 1, -1, 1))
        App.ActiveDocument.recompute()

        #Add dimensions
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('DistanceX', 3, -gv.xRodClampWidth))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('DistanceY', 2, -gv.xMotorMountPlateWidth))
        App.ActiveDocument.recompute()

        App.getDocument('xEndIdlerPlate').recompute()

        #extrude x motor mount plate
        App.activeDocument().addObject("PartDesign::Pad", "Pad")
        App.activeDocument().Pad.Sketch = App.activeDocument().Sketch
        App.activeDocument().Pad.Length = 10.0
        App.ActiveDocument.recompute()
        App.ActiveDocument.Pad.Length = gv.xMotorMountPlateThickness
        App.ActiveDocument.Pad.Reversed = 0
        App.ActiveDocument.Pad.Midplane = 0
        App.ActiveDocument.Pad.Length2 = 100.000000
        App.ActiveDocument.Pad.Type = 0
        App.ActiveDocument.Pad.UpToFace = None
        App.ActiveDocument.recompute()

        #cut holes for xRodClamp
        #Sketch Points
        p1x = 0
        p1y = gv.xMotorMountPlateWidth / 2
        p2x = gv.xRodClampWidth
        p2y = gv.xMotorMountPlateWidth / 2
        p3x = gv.xRodClampEdgeToMountHoleDist
        p3y = gv.xRodAxisToMountHoleDist
        p4x = gv.xRodClampEdgeToMountHoleDist
        p4y = gv.xMotorMountPlateWidth - gv.xRodAxisToMountHoleDist
        p5x = gv.xRodClampWidth - gv.xRodClampEdgeToMountHoleDist
        p5y = gv.xMotorMountPlateWidth - gv.xRodAxisToMountHoleDist
        p6x = gv.xRodClampWidth - gv.xRodClampEdgeToMountHoleDist
        p6y = gv.xRodAxisToMountHoleDist
        p7x = gv.xRodClampEdgeToMountHoleDist
        p7y = gv.xMotorMountPlateWidth / 2
        p8x = gv.xRodClampWidth / 2
        p8y = gv.xMotorMountPlateWidth / 2

        #Make sketch
        App.activeDocument().addObject('Sketcher::SketchObject', 'Sketch001')
        App.activeDocument().Sketch001.Support = uf.getFace(
            App.ActiveDocument.Pad, None, None, None, None,
            gv.xMotorMountPlateThickness,
            0)  #(App.ActiveDocument.Pad,["Face6"])
        App.activeDocument().recompute()

        App.ActiveDocument.Sketch001.addExternal(
            "Pad",
            uf.getEdge(App.ActiveDocument.Pad, 0, 0,
                       gv.xMotorMountPlateWidth / 2, 0,
                       gv.xMotorMountPlateThickness, 0))
        App.ActiveDocument.Sketch001.addExternal(
            "Pad",
            uf.getEdge(App.ActiveDocument.Pad, gv.xRodClampWidth, 0,
                       gv.xMotorMountPlateWidth / 2, 0,
                       gv.xMotorMountPlateThickness, 0))

        App.ActiveDocument.Sketch001.addGeometry(
            Part.Line(App.Vector(p1x, p1y, 0), App.Vector(p2x, p2y, 0)))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('PointOnObject', 0, 1, -3))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('PointOnObject', 0, 2, -4))
        App.ActiveDocument.Sketch001.addGeometry(
            Part.Line(App.Vector(p3x, p3y, 0), App.Vector(p4x, p4y, 0)))
        App.ActiveDocument.Sketch001.addGeometry(
            Part.Line(App.Vector(p4x, p4y, 0), App.Vector(p5x, p5y, 0)))
        App.ActiveDocument.Sketch001.addGeometry(
            Part.Line(App.Vector(p5x, p5y, 0), App.Vector(p6x, p6y, 0)))
        App.ActiveDocument.Sketch001.addGeometry(
            Part.Line(App.Vector(p6x, p6y, 0), App.Vector(p3x, p3y, 0)))
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Coincident', 1, 2, 2, 1))
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Coincident', 2, 2, 3, 1))
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Coincident', 3, 2, 4, 1))
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Coincident', 4, 2, 1, 1))
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Horizontal', 2))
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Horizontal', 4))
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Vertical', 1))
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Vertical', 3))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.toggleConstruction(0)
        App.ActiveDocument.Sketch001.toggleConstruction(4)
        App.ActiveDocument.Sketch001.toggleConstruction(3)
        App.ActiveDocument.Sketch001.toggleConstruction(2)
        App.ActiveDocument.Sketch001.toggleConstruction(1)
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addGeometry(
            Part.Point(App.Vector(p7x, p7y, 0)))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('PointOnObject', 5, 1, 1))
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('PointOnObject', 5, 1, 0))

        App.ActiveDocument.Sketch001.addGeometry(
            Part.Circle(App.Vector(p3x, p3y, 0), App.Vector(0, 0, 1),
                        gv.mountToPrintedDia / 2))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Coincident', 1, 1, 6, 3))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addGeometry(
            Part.Circle(App.Vector(p4x, p4y, 0), App.Vector(0, 0, 1),
                        gv.mountToPrintedDia / 2))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Coincident', 7, 3, 1, 2))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addGeometry(
            Part.Circle(App.Vector(p5x, p5y, 0), App.Vector(0, 0, 1),
                        gv.mountToPrintedDia / 2))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Coincident', 2, 2, 8, 3))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addGeometry(
            Part.Circle(App.Vector(p6x, p6y, 0), App.Vector(0, 0, 1),
                        gv.mountToPrintedDia / 2))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Coincident', 9, 3, 3, 2))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Equal', 6, 7))
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Equal', 7, 8))
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Equal', 8, 9))
        App.ActiveDocument.recompute()

        App.ActiveDocument.Sketch001.addGeometry(
            Part.Circle(App.Vector(p8x, p8y, 0), App.Vector(0, 0, 1),
                        gv.xEndIdlerHoleDia / 2))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('PointOnObject', 10, 3, 0))
        App.ActiveDocument.recompute()

        #add dimensions
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('DistanceX', 4,
                                -xRodClampMountHoleSpacingHoriz))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Distance', 3, 2, -4,
                                gv.xRodClampEdgeToMountHoleDist))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('DistanceY', 3,
                                -xRodClampMountHoleSpacingVert))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Radius', 8, gv.mountToPrintedDia / 2))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Radius', 10, gv.xEndIdlerHoleDia / 2))
        App.ActiveDocument.recompute()

        #add Symmetric constraints
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Symmetric', 1, 1, 1, 2, 5, 1))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Symmetric', 1, 1, 2, 2, 10, 3))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Symmetric', -1, 1, -3, 2, 0, 1))
        App.ActiveDocument.recompute()

        #exit sketch
        App.getDocument('xEndIdlerPlate').recompute()

        #Cut holes through all
        App.activeDocument().addObject("PartDesign::Pocket", "Pocket")
        App.activeDocument().Pocket.Sketch = App.activeDocument().Sketch001
        App.activeDocument().Pocket.Length = 5.0
        App.ActiveDocument.recompute()
        App.ActiveDocument.Pocket.Length = 5.000000
        App.ActiveDocument.Pocket.Type = 1
        App.ActiveDocument.Pocket.UpToFace = None
        App.ActiveDocument.recompute()
Example #6
0
    def getCoG(self,
               fp,
               vol,
               roll=Units.parseQuantity("0 deg"),
               trim=Units.parseQuantity("0 deg")):
        """Return the fluid volume center of gravity, provided the volume of
        fluid inside the tank.

        The returned center of gravity is referred to the untransformed ship.

        Keyword arguments:
        fp -- Part::FeaturePython object affected.
        vol -- Volume of fluid.
        roll -- Ship roll angle.
        trim -- Ship trim angle.

        If the fluid volume is bigger than the total tank one, it will be
        conveniently clamped.
        """
        # Change the units of the volume, and clamp the value
        if vol <= 0.0:
            return Vector()
        if vol >= fp.Shape.Volume:
            vol = 0.0
            cog = Vector()
            for solid in fp.Shape.Solids:
                vol += solid.Volume
                sCoG = solid.CenterOfMass
                cog.x = cog.x + sCoG.x * solid.Volume
                cog.y = cog.y + sCoG.y * solid.Volume
                cog.z = cog.z + sCoG.z * solid.Volume
            cog.x = cog.x / vol
            cog.y = cog.y / vol
            cog.z = cog.z / vol
            return cog

        # Get a first estimation of the level
        level = vol.Value / fp.Shape.Volume

        # Transform the tank shape
        current_placement = fp.Placement
        m = current_placement.toMatrix()
        m.rotateX(roll.getValueAs("rad"))
        m.rotateY(-trim.getValueAs("rad"))
        fp.Placement = Placement(m)

        # Iterate to find the fluid shape
        for i in range(COMMON_BOOLEAN_ITERATIONS):
            shape = self.getVolume(fp, level, return_shape=True)
            error = (vol.Value - shape.Volume) / fp.Shape.Volume
            if abs(error) < 0.01:
                break
            level += error

        # Get the center of gravity
        vol = 0.0
        cog = Vector()
        if len(shape.Solids) > 0:
            for solid in shape.Solids:
                vol += solid.Volume
                sCoG = solid.CenterOfMass
                cog.x = cog.x + sCoG.x * solid.Volume
                cog.y = cog.y + sCoG.y * solid.Volume
                cog.z = cog.z + sCoG.z * solid.Volume
            cog.x = cog.x / vol
            cog.y = cog.y / vol
            cog.z = cog.z / vol

        # Untransform the object to retrieve the original position
        fp.Placement = current_placement
        p = Part.Point(cog)
        m = Matrix()
        m.rotateY(trim.getValueAs("rad"))
        m.rotateX(-roll.getValueAs("rad"))
        p.rotate(Placement(m))

        return Vector(p.X, p.Y, p.Z)
    def execute(self, selfobj):
        """ Doing a recomputation.
        """
        if m_debug:
            print("running CenterLinePoint.execute !")

        # To be compatible with previous version > 2019
        if 'Parametric' in selfobj.PropertiesList:
            # Create the object the first time regardless
            # the parametric behavior
            if selfobj.Parametric == 'Not' and self.created:
                return
            if selfobj.Parametric == 'Interactive' and self.created:
                return
        # To be compatible with previous version 2018
        if 'parametric' in selfobj.PropertiesList:
            self.execute_2018(selfobj)

        if WF.verbose():
            m_msg = "Recompute Python CenterLinePoint feature\n"
            App.Console.PrintMessage(m_msg)

        m_PropertiesList = ['Edge',
                            'Point1',
                            'Point2',
                            'IndexPart',
                            'NumberLinePart'
                            ]
        for m_Property in m_PropertiesList:
            if m_Property not in selfobj.PropertiesList:
                return

        try:
            Vector_point = None
            if selfobj.Point1 is not None and selfobj.Point2 is not None:
                n1 = eval(selfobj.Point1[1][0].lstrip('Vertex'))
                n2 = eval(selfobj.Point2[1][0].lstrip('Vertex'))
                if m_debug:
                    print_msg(str(selfobj.Point1))
                    print_msg(str(selfobj.Point2))
                    print_msg("n1 = " + str(n1))
                    print_msg("n2 = " + str(n2))

                point1 = selfobj.Point1[0].Shape.Vertexes[n1 - 1].Point
                point2 = selfobj.Point2[0].Shape.Vertexes[n2 - 1].Point

                Vector_point = alongTwoPointsPoint(point1,
                                                   point2,
                                                   selfobj.IndexPart,
                                                   selfobj.NumberLinePart)
            elif selfobj.Edge is not None:
                n = eval(selfobj.Edge[1][0].lstrip('Edge'))
                if m_debug:
                    print_msg(str(selfobj.Edge))
                    print_msg("n = " + str(n))
                    print_msg(str(selfobj.Edge[0].Shape.Edges))

                if len(selfobj.Edge[0].Shape.Edges) == 0:
                    return
                Vector_point = alongLinePoint(selfobj.Edge[0].Shape.Edges[n - 1],
                                              selfobj.IndexPart,
                                              selfobj.NumberLinePart)
            if Vector_point is not None:
                point = Part.Point(Vector_point)
                selfobj.Shape = point.toShape()
                propertiesPoint(selfobj.Label, self.color)
                selfobj.X = float(Vector_point.x)
                selfobj.Y = float(Vector_point.y)
                selfobj.Z = float(Vector_point.z)
                # To be compatible with previous version 2018
                if 'Parametric' in selfobj.PropertiesList:
                    self.created = True
        except Exception as err:
            printError_msg(err.args[0], title=m_macro)
Example #8
0
    def draw(self):

        #helper Variables
        gv.xRodClampOverallThickness = 2 * gv.xRodClampThickness + gv.xRodDiaMax
        mountHoleInsetVert = gv.printedToPrintedDia / 2 + gv.xRodClampMountHoleToRodPadding + gv.xRodDiaMax / 2
        mountHoleInsetHoriz = gv.xRodClampMountHoleToEdgePadding + gv.printedToPrintedDia / 2
        beltChannelDepth = (gv.xRodDiaTop if gv.xRodDiaTop > gv.xRodDiaBottom
                            else gv.xRodDiaBottom) + gv.xRodClampThickness

        #Make file and build part
        try:
            Gui.getDocument(self.name)
            Gui.getDocument(self.name).resetEdit()
            App.getDocument(self.name).recompute()
            App.closeDocument(self.name)
            App.setActiveDocument("")
            App.ActiveDocument = None
            Gui.ActiveDocument = None
        except:
            pass

        #Create Document
        App.newDocument(self.name)
        App.setActiveDocument(self.name)
        App.ActiveDocument = App.getDocument(self.name)
        Gui.ActiveDocument = Gui.getDocument(self.name)

        #Extrude body of xRodClamp
        #sketch Points
        p1x = 0
        p1y = 0
        p2x = 0
        p2y = gv.xRodClampOverallThickness / 2
        p3x = 0
        p3y = gv.xRodClampOverallThickness
        p4x = gv.xRodSpacing
        p4y = gv.xRodClampOverallThickness
        p5x = gv.xRodSpacing
        p5y = gv.xRodClampOverallThickness / 2
        p6x = gv.xRodSpacing
        p6y = 0

        #Make Sketch
        App.activeDocument().addObject('Sketcher::SketchObject', 'Sketch')
        App.activeDocument().Sketch.Placement = App.Placement(
            App.Vector(0.000000, 0.000000, 0.000000),
            App.Rotation(0.500000, 0.500000, 0.500000, 0.500000))
        #		Gui.activeDocument().activeView().setCamera('#Inventor V2.1 ascii \n OrthographicCamera {\n viewportMapping ADJUST_CAMERA\n  position 87 0 0 \n  orientation 0.57735026 0.57735026 0.57735026  2.0943952 \n  nearDistance -112.887\n  farDistance 287.28699\n  aspectRatio 1\n  focalDistance 87\n  height 143.52005\n\n}')
        #		Gui.activeDocument().setEdit('Sketch')
        App.ActiveDocument.Sketch.addGeometry(
            Part.ArcOfCircle(
                Part.Circle(App.Vector(p2x, p2y, 0), App.Vector(0, 0, 1),
                            gv.xRodClampOverallThickness / 2), 0.5 * math.pi,
                1.5 * math.pi))
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('PointOnObject', 0, 3, -2))
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('Coincident', 0, 2, -1, 1))
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('PointOnObject', 0, 1, -2))
        App.ActiveDocument.Sketch.addGeometry(
            Part.Line(App.Vector(p3x, p3y, 0), App.Vector(p4x, p4y, 0)))
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('Coincident', 1, 1, 0, 1))
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('Horizontal', 1))
        App.ActiveDocument.Sketch.addGeometry(
            Part.ArcOfCircle(
                Part.Circle(App.Vector(p5x, p5y, 0), App.Vector(0, 0, 1),
                            gv.xRodClampOverallThickness / 2), 1.5 * math.pi,
                0.5 * math.pi))
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('Coincident', 2, 2, 1, 2))
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('PointOnObject', 2, 1, -1))
        App.ActiveDocument.Sketch.addGeometry(
            Part.Line(App.Vector(p6x, p6y, 0), App.Vector(p1x, p1y, 0)))
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('Coincident', 3, 1, 2, 1))
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('Coincident', 3, 2, -1, 1))
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('Equal', 1, 3))
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('Symmetric', 1, 2, 2, 1, 2, 3))

        #add dimensions
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('Radius', 2, gv.xRodClampOverallThickness / 2))
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('DistanceX', 3, -gv.xRodSpacing))
        #		Gui.getDocument(self.name).resetEdit()
        App.getDocument(self.name).recompute()

        #Pad the xRodClamp body
        App.activeDocument().addObject("PartDesign::Pad", "Pad")
        App.activeDocument().Pad.Sketch = App.activeDocument().Sketch
        App.activeDocument().Pad.Length = 10.0
        App.ActiveDocument.recompute()
        Gui.activeDocument().hide("Sketch")
        App.ActiveDocument.Pad.Length = gv.xRodClampWidth  # xRodClamp gv.xRodClampWidth
        App.ActiveDocument.Pad.Reversed = 0
        App.ActiveDocument.Pad.Midplane = 0
        App.ActiveDocument.Pad.Length2 = 100.000000
        App.ActiveDocument.Pad.Type = 0
        App.ActiveDocument.Pad.UpToFace = None
        App.ActiveDocument.recompute()
        #		Gui.activeDocument().resetEdit()

        #Make holes for x rods
        #Sketch Points
        p1x = 0
        p1y = gv.xRodClampOverallThickness / 2
        p2x = gv.xRodSpacing
        p2y = gv.xRodClampOverallThickness / 2

        #Make Sketch
        App.activeDocument().addObject('Sketcher::SketchObject', 'Sketch001')
        App.activeDocument().Sketch001.Support = uf.getFace(
            App.ActiveDocument.Pad, gv.xRodClampWidth, 0, None, None, None,
            None)  #(App.ActiveDocument.Pad,["Face6"])
        App.activeDocument().recompute()
        #		Gui.activeDocument().setEdit('Sketch001')
        App.ActiveDocument.Sketch001.addExternal(
            "Pad",
            uf.getEdge(App.ActiveDocument.Pad, gv.xRodClampWidth, 0, 0, -1,
                       gv.xRodClampOverallThickness / 2, 0))
        App.ActiveDocument.Sketch001.addExternal(
            "Pad",
            uf.getEdge(App.ActiveDocument.Pad, gv.xRodClampWidth, 0,
                       gv.xRodSpacing, 1, gv.xRodClampOverallThickness / 2, 0))
        App.ActiveDocument.Sketch001.addGeometry(
            Part.Circle(App.Vector(p1x, p1y, 0), App.Vector(0, 0, 1),
                        gv.xRodDiaBottom / 2))
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Coincident', 0, 3, -3, 3))
        App.ActiveDocument.Sketch001.addGeometry(
            Part.Circle(App.Vector(p2x, p2y, 0), App.Vector(0, 0, 1),
                        gv.xRodDiaTop / 2))
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Coincident', 1, 3, -4, 3))

        #add Dimensions
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Radius', 0, gv.xRodDiaBottom / 2))
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Radius', 1, gv.xRodDiaTop / 2))
        #		Gui.getDocument(self.name).resetEdit()
        App.getDocument(self.name).recompute()

        #extrude Cut to depth that Rods will be embeded in clamp
        App.activeDocument().addObject("PartDesign::Pocket", "Pocket")
        App.activeDocument().Pocket.Sketch = App.activeDocument().Sketch001
        App.activeDocument().Pocket.Length = 5.0
        App.ActiveDocument.recompute()
        Gui.activeDocument().hide("Sketch001")
        Gui.activeDocument().hide("Pad")
        #		Gui.ActiveDocument.Pocket.ShapeColor=Gui.ActiveDocument.Pad.ShapeColor
        #		Gui.ActiveDocument.Pocket.LineColor=Gui.ActiveDocument.Pad.LineColor
        #		Gui.ActiveDocument.Pocket.PointColor=Gui.ActiveDocument.Pad.PointColor
        App.ActiveDocument.Pocket.Length = gv.xRodClampPocketDepth + gv.xRodClampExtraPocketDepth  # depth of the holes for the x rods
        App.ActiveDocument.Pocket.Type = 0
        App.ActiveDocument.Pocket.UpToFace = None
        App.ActiveDocument.recompute()
        #		Gui.activeDocument().resetEdit()

        #Make holes for motor mount plate and idler
        #Sketch Points
        p1x = -gv.xRodSpacing
        p1y = gv.xRodClampWidth - mountHoleInsetHoriz
        p2x = -gv.xRodSpacing + gv.xRodAxisToMountHoleDist
        p2y = gv.xRodClampWidth
        p3x = 0
        p3y = mountHoleInsetHoriz
        p4x = -gv.xRodAxisToMountHoleDist
        p4y = 0
        p5x = -gv.xRodSpacing + gv.xRodAxisToMountHoleDist
        p5y = mountHoleInsetHoriz
        p6x = -gv.xRodSpacing + gv.xRodAxisToMountHoleDist
        p6y = gv.xRodClampWidth - mountHoleInsetHoriz
        p7x = -gv.xRodAxisToMountHoleDist
        p7y = gv.xRodClampWidth - mountHoleInsetHoriz
        p8x = -gv.xRodAxisToMountHoleDist
        p8y = mountHoleInsetHoriz
        p9x = -gv.xRodSpacing / 2
        p9y = gv.xRodClampWidth / 2

        #Make sketch
        App.activeDocument().addObject('Sketcher::SketchObject', 'Sketch002')
        App.activeDocument().Sketch002.Support = uf.getFace(
            App.ActiveDocument.Pocket, None, None, None, None,
            gv.xRodClampOverallThickness,
            0)  #(App.ActiveDocument.Pocket,["Face2"])
        App.activeDocument().recompute()
        #		Gui.activeDocument().setEdit('Sketch002')
        App.ActiveDocument.Sketch002.addExternal(
            "Pocket",
            uf.getEdge(App.ActiveDocument.Pocket, gv.xRodClampWidth, 0,
                       gv.xRodSpacing / 2, 0, gv.xRodClampOverallThickness, 0))
        App.ActiveDocument.Sketch002.addExternal(
            "Pocket",
            uf.getEdge(App.ActiveDocument.Pocket, gv.xRodClampWidth / 2, 0,
                       gv.xRodSpacing, 0, gv.xRodClampOverallThickness, 0))
        App.ActiveDocument.Sketch002.addGeometry(
            Part.Line(App.Vector(p1x, p1y, 0), App.Vector(p6x, p6y, 0)))
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('PointOnObject', 0, 1, -4))
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('Horizontal', 0))
        App.ActiveDocument.Sketch002.addGeometry(
            Part.Line(App.Vector(p6x, p6y, 0), App.Vector(p2x, p2y, 0)))
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('Coincident', 0, 2, 1, 1))
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('PointOnObject', 1, 2, -3))
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('Vertical', 1))
        App.ActiveDocument.Sketch002.addGeometry(
            Part.Line(App.Vector(p3x, p3y, 0), App.Vector(p8x, p8y, 0)))
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('PointOnObject', 2, 1, -2))
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('Horizontal', 2))
        App.ActiveDocument.Sketch002.addGeometry(
            Part.Line(App.Vector(p8x, p8y, 0), App.Vector(p4x, p4y, 0)))
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('Coincident', 2, 2, 3, 1))
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('PointOnObject', 3, 2, -1))
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('Vertical', 3))
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('Equal', 1, 3))
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('Equal', 2, 0))
        App.ActiveDocument.Sketch002.toggleConstruction(1)
        App.ActiveDocument.Sketch002.toggleConstruction(0)
        App.ActiveDocument.Sketch002.toggleConstruction(2)
        App.ActiveDocument.Sketch002.toggleConstruction(3)

        App.ActiveDocument.Sketch002.addGeometry(
            Part.Line(App.Vector(p6x, p6y, 0), App.Vector(p7x, p7y, 0)))
        App.ActiveDocument.Sketch002.addGeometry(
            Part.Line(App.Vector(p7x, p7y, 0), App.Vector(p8x, p8y, 0)))
        App.ActiveDocument.Sketch002.addGeometry(
            Part.Line(App.Vector(p8x, p8y, 0), App.Vector(p5x, p5y, 0)))
        App.ActiveDocument.Sketch002.addGeometry(
            Part.Line(App.Vector(p5x, p5y, 0), App.Vector(p6x, p6y, 0)))
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('Coincident', 4, 2, 5, 1))
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('Coincident', 5, 2, 6, 1))
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('Coincident', 6, 2, 7, 1))
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('Coincident', 7, 2, 4, 1))
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('Horizontal', 4))
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('Horizontal', 6))
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('Vertical', 5))
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('Vertical', 7))
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('Coincident', 4, 1, 0, 2))
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('Coincident', 5, 2, 2, 2))

        App.ActiveDocument.Sketch002.toggleConstruction(7)
        App.ActiveDocument.Sketch002.toggleConstruction(4)
        App.ActiveDocument.Sketch002.toggleConstruction(5)
        App.ActiveDocument.Sketch002.toggleConstruction(6)

        App.ActiveDocument.Sketch002.addGeometry(
            Part.Circle(App.Vector(p6x, p6y, 0), App.Vector(0, 0, 1),
                        gv.printedToPrintedDia / 2))
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('Coincident', 8, 3, 0, 2))
        App.ActiveDocument.Sketch002.addGeometry(
            Part.Circle(App.Vector(p7x, p7y, 0), App.Vector(0, 0, 1),
                        gv.printedToPrintedDia / 2))
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('Coincident', 9, 3, 4, 2))
        App.ActiveDocument.Sketch002.addGeometry(
            Part.Circle(App.Vector(p8x, p8y, 0), App.Vector(0, 0, 1),
                        gv.printedToPrintedDia / 2))
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('Coincident', 10, 3, 2, 2))
        App.ActiveDocument.Sketch002.addGeometry(
            Part.Circle(App.Vector(p5x, p5y, 0), App.Vector(0, 0, 1),
                        gv.printedToPrintedDia / 2))
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('Coincident', 11, 3, 6, 2))
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('Equal', 8, 9))
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('Equal', 9, 10))
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('Equal', 10, 11))

        App.ActiveDocument.Sketch002.addGeometry(
            Part.Circle(App.Vector(p9x, p9y, 0), App.Vector(0, 0, 1),
                        gv.xRodClampIdlerHoleDia / 2))
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('Symmetric', 0, 2, 2, 2, 12, 3))

        #add Dimensions
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('DistanceX', 0, gv.xRodAxisToMountHoleDist)
        )  #distance between rod edge and mouunting hole edge
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('DistanceY', 1, mountHoleInsetHoriz)
        )  #distance between edge of part and mounting hole edge
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('Radius', 9, gv.printedToPrintedDia /
                                2))  #mount hole radius
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('Radius', 12, gv.xRodClampIdlerHoleDia /
                                2))  #idler hole radius
        #		Gui.getDocument(self.name).resetEdit()
        App.getDocument(self.name).recompute()

        #Cut holes through all
        App.activeDocument().addObject("PartDesign::Pocket", "Pocket001")
        App.activeDocument().Pocket001.Sketch = App.activeDocument().Sketch002
        App.activeDocument().Pocket001.Length = 5.0
        App.ActiveDocument.recompute()
        Gui.activeDocument().hide("Sketch002")
        Gui.activeDocument().hide("Pocket")
        #		Gui.ActiveDocument.Pocket001.ShapeColor=Gui.ActiveDocument.Pocket.ShapeColor
        #		Gui.ActiveDocument.Pocket001.LineColor=Gui.ActiveDocument.Pocket.LineColor
        #		Gui.ActiveDocument.Pocket001.PointColor=Gui.ActiveDocument.Pocket.PointColor
        App.ActiveDocument.Pocket001.Length = 5.000000
        App.ActiveDocument.Pocket001.Type = 1
        App.ActiveDocument.Pocket001.UpToFace = None
        App.ActiveDocument.recompute()
        #		Gui.activeDocument().resetEdit()

        #Cut away material to make belt channel
        #sketch points
        p1x = -gv.xRodSpacing + gv.xRodAxisToMountHoleDist + gv.printedToPrintedDia / 2 + gv.xRodClampMountHoleToRodPadding
        p1y = 0
        p2x = p1x
        p2y = gv.xRodClampWidth
        p3x = -(gv.xRodAxisToMountHoleDist + gv.printedToPrintedDia / 2 +
                gv.xRodClampMountHoleToRodPadding)
        p3y = gv.xRodClampWidth
        p4x = p3x
        p4y = 0

        #make sketch
        App.activeDocument().addObject('Sketcher::SketchObject', 'Sketch003')
        App.activeDocument().Sketch003.Support = uf.getFace(
            App.ActiveDocument.Pocket001, None, None, None, None,
            gv.xRodClampOverallThickness,
            0)  #(App.ActiveDocument.Pocket001,["Face2"])
        App.activeDocument().recompute()
        #		Gui.activeDocument().setEdit('Sketch003')

        App.ActiveDocument.Sketch003.addExternal(
            "Pocket001",
            uf.getEdge(App.ActiveDocument.Pocket001, gv.xRodClampWidth, 0,
                       gv.xRodSpacing / 2, 0, gv.xRodClampOverallThickness, 0))
        App.ActiveDocument.Sketch003.addExternal(
            "Pocket001",
            uf.getEdge(App.ActiveDocument.Pocket001, gv.xRodClampWidth / 2, 0,
                       gv.xRodSpacing, 0, gv.xRodClampOverallThickness, 0))
        App.ActiveDocument.Sketch003.addGeometry(
            Part.Line(App.Vector(p1x, p1y, 0), App.Vector(p4x, p4y, 0)))
        App.ActiveDocument.Sketch003.addGeometry(
            Part.Line(App.Vector(p4x, p4y, 0), App.Vector(p3x, p3y, 0)))
        App.ActiveDocument.Sketch003.addGeometry(
            Part.Line(App.Vector(p3x, p3y, 0), App.Vector(p2x, p2y, 0)))
        App.ActiveDocument.Sketch003.addGeometry(
            Part.Line(App.Vector(p2x, p2y, 0), App.Vector(p1x, p1y, 0)))
        App.ActiveDocument.Sketch003.addConstraint(
            Sketcher.Constraint('Coincident', 0, 2, 1, 1))
        App.ActiveDocument.Sketch003.addConstraint(
            Sketcher.Constraint('Coincident', 1, 2, 2, 1))
        App.ActiveDocument.Sketch003.addConstraint(
            Sketcher.Constraint('Coincident', 2, 2, 3, 1))
        App.ActiveDocument.Sketch003.addConstraint(
            Sketcher.Constraint('Coincident', 3, 2, 0, 1))
        App.ActiveDocument.Sketch003.addConstraint(
            Sketcher.Constraint('Horizontal', 0))
        App.ActiveDocument.Sketch003.addConstraint(
            Sketcher.Constraint('Horizontal', 2))
        App.ActiveDocument.Sketch003.addConstraint(
            Sketcher.Constraint('Vertical', 1))
        App.ActiveDocument.Sketch003.addConstraint(
            Sketcher.Constraint('Vertical', 3))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch003.addConstraint(
            Sketcher.Constraint('PointOnObject', 0, 1, -1))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch003.addConstraint(
            Sketcher.Constraint('PointOnObject', 1, 2, -3))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch003.addGeometry(
            Part.Point(App.Vector(-34.530499, 62.111320, 0)))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch003.addConstraint(
            Sketcher.Constraint('Symmetric', -4, 2, -3, 1, 4, 1))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch003.movePoint(
            2, 2, App.Vector(-50.355999, 62.922062, 0), 0)
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch003.movePoint(
            1, 2, App.Vector(-19.232504, 62.922058, 0), 0)
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch003.addConstraint(
            Sketcher.Constraint('Symmetric', 2, 2, 1, 2, 4, 1))
        App.ActiveDocument.recompute()

        #Add dimensions
        App.ActiveDocument.Sketch003.addConstraint(
            Sketcher.Constraint('DistanceX', -1, 1, 1, 2, p3x))
        App.ActiveDocument.recompute()
        #		Gui.getDocument(self.name).resetEdit()
        App.getDocument(self.name).recompute()

        #Cut material away
        App.activeDocument().addObject("PartDesign::Pocket", "Pocket002")
        App.activeDocument().Pocket002.Sketch = App.activeDocument().Sketch003
        App.activeDocument().Pocket002.Length = 5.0
        App.ActiveDocument.recompute()
        Gui.activeDocument().hide("Sketch003")
        Gui.activeDocument().hide("Pocket001")
        #		Gui.ActiveDocument.Pocket002.ShapeColor=Gui.ActiveDocument.Pocket001.ShapeColor
        #		Gui.ActiveDocument.Pocket002.LineColor=Gui.ActiveDocument.Pocket001.LineColor
        #		Gui.ActiveDocument.Pocket002.PointColor=Gui.ActiveDocument.Pocket001.PointColor
        App.ActiveDocument.Pocket002.Length = beltChannelDepth
        App.ActiveDocument.Pocket002.Type = 0
        App.ActiveDocument.Pocket002.UpToFace = None
        App.ActiveDocument.recompute()
        #		Gui.activeDocument().resetEdit()

        if self.side == "Left":
            __doc__ = App.getDocument(self.name)
            __doc__.addObject("Part::Mirroring")
            __doc__.ActiveObject.Source = __doc__.getObject("Pocket002")
            __doc__.ActiveObject.Label = "Pocket002 (Mirror #1)"
            __doc__.ActiveObject.Normal = (1, 0, 0)
            __doc__.ActiveObject.Base = (0, 0, 0)
            del __doc__
            #		Gui.ActiveDocument.ActiveObject.ShapeColor=Gui.ActiveDocument.Pocket002.ShapeColor
            #		Gui.ActiveDocument.ActiveObject.LineColor=Gui.ActiveDocument.Pocket002.LineColor
            #		Gui.ActiveDocument.ActiveObject.PointColor=Gui.ActiveDocument.Pocket002.PointColor
            Gui.getDocument(
                self.name).getObject("Pocket002").Visibility = False
Example #9
0
def runAnimation(obj=None,loop=False):

	cww=App.ActiveDocument.getObject(obj.path.Name+"_Path")
	cyy=App.ActiveDocument.getObject(obj.pathName)

	if loop: ixs=obj.kka
	else: 
		ixs=[obj.kka[obj.anim]]
		ixs=[obj.kka[obj.anim-1]]

		ll=len(obj.kka)
		posl=int(round(obj.anim*ll*0.01))
		ixs=[obj.kka[posl]]

#	print "obj.kka",
#	for k in obj.kka: print k

	for i,p in enumerate(ixs):

		pp=Part.Point(FreeCAD.Vector(p))
#		print ("run Anim",i,pp)

		if 0:
			w=App.ActiveDocument.Sketch.Shape
			dist=w.distToShape(pp.toShape())
			print(dist[0])


		testmode=True

#		obj.circle.Placement.Base=p
#		obj.circle.Radius=1

#		kkxx=App.ActiveDocument.Compound001
		kkxx=obj.scooter
		#print kkxx.Label
		if  kkxx != None:
			kkxx.Placement.Base=FreeCAD.Vector(p.Length,0,0)


		alpha=np.arctan2(p.y,p.x)*180/np.pi

		try:pos=obj.path.Shape.Curve.parameter(p)
		except: pos=obj.path.Shape.Edge1.Curve.parameter(p)
		
		arc2=-pos/obj.offsetValue/np.pi/2*180

		#print ("rot",arc2,alpha)

		if obj.mode=='rotate camshaft':
			#print "circle ",alpha
			obj.circle.Placement=FreeCAD.Placement(FreeCAD.Vector(),FreeCAD.Rotation(FreeCAD.Vector(0,0,1),-alpha)).multiply(FreeCAD.Placement(p,FreeCAD.Rotation(FreeCAD.Vector(0,0,1),arc2+alpha)))
			obj.circle2.Placement=obj.circle.Placement
			if  kkxx != None:
				kkxx.Placement=obj.circle.Placement
		else:
			obj.circle.Placement=FreeCAD.Placement(p,FreeCAD.Rotation(FreeCAD.Vector(0,0,1),arc2+alpha))
			obj.circle2.Placement=obj.circle.Placement
			if  kkxx != None:
				kkxx.Placement=obj.circle.Placement



		if obj.mode=='rotate camshaft':
			cww.Shape=Part.makePolygon(obj.pola)
			cww.Placement.Rotation=FreeCAD.Rotation(FreeCAD.Vector(0,0,1),-alpha)

			cyy.Shape=Part.makePolygon(obj.polb)
			cyy.Placement.Rotation=FreeCAD.Rotation(FreeCAD.Vector(0,0,1),-alpha)

	#		App.ActiveDocument.DWire.Placement.Rotation=FreeCAD.Rotation(FreeCAD.Vector(0,0,1),-alpha)


#			kkyy=App.ActiveDocument.Compound
			kkyy=obj.camshaft
#			print kkyy.Label
			if  kkyy != None:
				kkyy.Placement.Rotation=FreeCAD.Rotation(FreeCAD.Vector(0,0,1),-alpha)

#		print cyy.Placement

		if loop:
			App.activeDocument().recompute()
			Gui.updateGui()
			time.sleep(0.1)
			if i>10: return


	def step(self,now):
			self.obj2.time=float(now)
Example #10
0
    def Activated(self):
        doc = FreeCAD.ActiveDocument
        pg = FreeCAD.ParamGet("User parameter:Plugins/MeshRemodel")
        line_width = pg.GetFloat("LineWidth", 5.0)
        point_size = pg.GetFloat("PointSize", 4.0)
        coplanar_tolerance = pg.GetFloat("CoplanarTolerance", .001)
        #QtGui.QApplication.setOverrideCursor(QtCore.Qt.WaitCursor)
        doc.openTransaction("Create coplanar")
        modifiers = QtGui.QApplication.keyboardModifiers()
        trio = [self.pts[0], self.pts[1], self.pts[2]]
        candidates = []
        if self.obj and hasattr(self.obj, "Shape"):
            candidates = self.obj.Shape.Vertexes
        coplanar = []

        for v in candidates:
            if modifiers == QtCore.Qt.AltModifier or modifiers == QtCore.Qt.AltModifier.__or__(
                    QtCore.Qt.ShiftModifier):
                poly = Part.makePolygon([trio[0], trio[1], trio[2], v.Point])
                if DraftGeomUtils.isPlanar(poly):
                    planar = True
                else:
                    planar = False
            else:  #use our own complanar check
                if gu.isCoplanar(trio, v.Point, coplanar_tolerance):
                    planar = True
                else:
                    planar = False

            if planar:
                coplanar.append(Part.Point(v.Point).toShape())
        coplanar.extend([Part.Point(v).toShape() for v in trio])

        Part.show(Part.makeCompound(coplanar), "MR_Points_Coplanar")
        doc.ActiveObject.ViewObject.PointSize = point_size
        mr = doc.ActiveObject
        if not "Sketcher_NewSketch" in Gui.listCommands():
            Gui.activateWorkbench("SketcherWorkbench")
            Gui.activateWorkbench("MeshRemodelWorkbench")
        Gui.runCommand("Sketcher_NewSketch")
        sketch = doc.ActiveObject
        sketch.Label = mr.Name + '_Sketch'
        sketch.MapReversed = True
        for ii in range(0, len(mr.Shape.Vertexes)):
            vname = 'Vertex' + str(ii + 1)
            sketch.addExternal(mr.Name, vname)

        doc.recompute()

        if self.obj and hasattr(self.obj, "ViewObject"):
            self.obj.ViewObject.Visibility = False
        doc.recompute()
        doc.commitTransaction()
        if modifiers == QtCore.Qt.ShiftModifier or modifiers == QtCore.Qt.ShiftModifier.__or__(
                QtCore.Qt.AltModifier):
            doc.openTransaction("explode coplanar points")
            import CompoundTools.Explode
            input_obj = doc.ActiveObject
            comp = CompoundTools.Explode.explodeCompound(input_obj)
            input_obj.ViewObject.hide()
            for obj in comp[1]:
                obj.ViewObject.PointSize = point_size
            doc.recompute()
            doc.commitTransaction()
        #QtGui.QApplication.restoreOverrideCursor()
        return
    def execute(self, selfobj):
        """ Doing a recomputation.
        """
        if m_debug:
            print("running ProjectedPoint.execute !")

        # To be compatible with previous version > 2019
        if 'Parametric' in selfobj.PropertiesList:
            # Create the object the first time regardless
            # the parametric behavior
            if selfobj.Parametric == 'Not' and self.created:
                return
            if selfobj.Parametric == 'Interactive' and self.created:
                return

        if WF.verbose():
            m_msg = "Recompute Python ProjectedPoint feature\n"
            App.Console.PrintMessage(m_msg)

        if m_debug:
            print("selfobj.PropertiesList = " + str(selfobj.PropertiesList))

        m_PropertiesList = [
            'Point',
            "Plane",
            "At",
            # "Show",
        ]
        for m_Property in m_PropertiesList:
            if m_Property not in selfobj.PropertiesList:
                return

        try:
            Vector_point = None
            if m_debug:
                print_msg("selfobj.Point = " + str(selfobj.Point))
                print_msg("selfobj.Plane = " + str(selfobj.Plane))

            if selfobj.Point is not None:
                n = eval(selfobj.Point[1][0].lstrip('Vertex'))
                if m_debug:
                    print_msg("n = " + str(n))

                point_A = selfobj.Point[0].Shape.Vertexes[n - 1].Point
                x = point_A.x
                y = point_A.y
                z = point_A.z
                # No selected plane so projection on one of MAIN planes
                if selfobj.Plane is None:
                    if selfobj.At == "XY plane":
                        Vector_point = Base.Vector(x, y, 0.0)
                    elif selfobj.At == "YZ plane":
                        Vector_point = Base.Vector(0.0, y, z)
                    elif selfobj.At == "XZ plane":
                        Vector_point = Base.Vector(x, 0.0, z)
                    else:
                        printError_msg("Not valid plane option!",
                                       title=m_macro)

                # A selected plane
                else:
                    pass


#                     p=App.Vector(1,1,1)
#                     p.projectToPlane(App.Vector(0,0,0),App.Vector(1,0,1))
#                     projectToPlane parameters are (point on plane,normal direction)

            if Vector_point is not None:
                point = Part.Point(Vector_point)
                selfobj.Shape = point.toShape()
                propertiesPoint(selfobj.Label, self.color)
                selfobj.X = float(Vector_point.x)
                selfobj.Y = float(Vector_point.y)
                selfobj.Z = float(Vector_point.z)

                if m_proj_line and not self.created:
                    point_1 = selfobj.Point
                    object_1 = selfobj
                    twoPL.buildFromOnePointAndOneObject(
                        point_1, object_1, m_group)

                # To be compatible with previous version 2018
                if 'Parametric' in selfobj.PropertiesList:
                    self.created = True
        except Exception as err:
            printError_msg(err.args[0], title=m_macro)
Example #12
0
obj_sketch002_vector_2 = App.Vector(-30.000, 55.000, 0.000)
obj_sketch002_vector_3 = App.Vector(-10.000, 55.000, 0.000)
obj_sketch002_vector_4 = App.Vector(-30.000, 85.000, 0.000)
obj_sketch002_vector_5 = App.Vector(-20.000, 70.000, 0.000)
obj_sketch002_vector_6 = App.Vector(-20.000, 50.000, 0.000)
obj_sketch002_vector_7 = App.Vector(-20.000, 90.000, 0.000)
obj_sketch002_vector_8 = App.Vector(-20.000, -20.000, 0.000)
obj_sketch002_vector_9 = App.Vector(-20.000, 0.000, 0.000)
obj_sketch002_vector_10 = App.Vector(-20.000, -10.000, 0.000)
obj_sketch002_line_1 = Part.LineSegment(obj_sketch002_vector_1,
                                        obj_sketch002_vector_2)
obj_sketch002_line_1.Construction = True
obj_sketch002_line_2 = Part.LineSegment(obj_sketch002_vector_3,
                                        obj_sketch002_vector_4)
obj_sketch002_line_2.Construction = True
obj_sketch002_point_1 = Part.Point(obj_sketch002_vector_5)
obj_sketch002_line_3 = Part.LineSegment(obj_sketch002_vector_6,
                                        obj_sketch002_vector_7)
obj_sketch002_line_3.Construction = True
obj_sketch002_circle_1 = Part.Circle(obj_sketch002_vector_7,
                                     App.Vector(0.0, 0.0, 1.0), 2.6)
obj_sketch002_circle_2 = Part.Circle(obj_sketch002_vector_6,
                                     App.Vector(0.0, 0.0, 1.0), 2.6)
obj_sketch002_point_2 = Part.Point(obj_sketch002_vector_8)
obj_sketch002_point_3 = Part.Point(obj_sketch002_vector_9)
obj_sketch002_circle_3 = Part.Circle(obj_sketch002_vector_10,
                                     App.Vector(0.0, 0.0, 1.0), 2.6)
obj_sketch002_all_geoms = [
    obj_sketch002_line_1, obj_sketch002_line_2, obj_sketch002_point_1,
    obj_sketch002_line_3, obj_sketch002_circle_1, obj_sketch002_circle_2,
    obj_sketch002_point_2, obj_sketch002_point_3, obj_sketch002_circle_3
    def execute(self, selfobj):
        """ Doing a recomputation.
        """
        if m_debug:
            print("running AlongLinePoint.execute !")

        # To be compatible with previous version > 2019
        if 'Parametric' in selfobj.PropertiesList:
            # Create the object the first time regardless
            # the parametric behavior
            if selfobj.Parametric == 'Not' and self.created:
                return
            if selfobj.Parametric == 'Interactive' and self.created:
                return

        if WF.verbose():
            m_msg = "Recompute Python AlongLinePoint feature\n"
            App.Console.PrintMessage(m_msg)

        m_PropertiesList = ["Distance",
                            'AlongEdge',
                            'Edge',
                            'Point'
                            ]
        for m_Property in m_PropertiesList:
            if m_Property not in selfobj.PropertiesList:
                return

        if selfobj.AlongEdge is None:
            return

        if selfobj.Edge is None and selfobj.Point is None:
            return

        if m_debug:
            print("selfobj.AlongEdge = " + str(selfobj.AlongEdge))
            print("selfobj.Edge = " + str(selfobj.Edge))
            print("selfobj.Point = " + str(selfobj.Point))

        try:
            Vector_point = None

            n1 = eval(selfobj.AlongEdge[1][0].lstrip('Edge'))

            if selfobj.Edge is not None:
                n2 = eval(selfobj.Edge[1][0].lstrip('Edge'))
            else:
                if selfobj.Point != selfobj.AlongEdge:
                    n3 = eval(selfobj.Point[1][0].lstrip('Vertex'))
                else:
                    print(selfobj.Point[1][0].name())
                    n3 = eval(selfobj.Point[1][0].lstrip('Edge'))

            m_distanceLinePoint = selfobj.Distance

            if m_debug:
                print_msg("n1 = " + str(n1))
                if selfobj.Edge is not None:
                    print_msg("n2 = " + str(n2))
                else:
                    print_msg("n3 = " + str(n3))
                print_msg("m_distanceLinePoint = " + str(m_distanceLinePoint))

            m_alongedge = selfobj.AlongEdge[0].Shape.Edges[n1 - 1]
            if selfobj.Edge is not None:
                m_edge = selfobj.Edge[0].Shape.Edges[n2 - 1]
            else:
                m_point = selfobj.Point[0].Shape.Vertexes[n3 - 1].Point

            if m_debug:
                print_msg("m_alongedge = " + str(m_alongedge))
                if selfobj.Edge is not None:
                    print_msg("m_edge = " + str(m_edge))
                else:
                    print_msg("m_point = " + str(m_point))

            Vector_A = m_alongedge.valueAt(0.0)
            Vector_B = m_alongedge.valueAt(m_alongedge.Length)
            if m_debug:
                print_msg("Vector_A = " + str(Vector_A))
                print_msg("Vector_B = " + str(Vector_B))

            if isEqualVectors(Vector_A, Vector_B):
                return

            if selfobj.Edge is not None:
                m_dist = m_alongedge.distToShape(m_edge)
                Vector_C = m_dist[1][0][0]
            else:
                Vector_C = m_point

            if m_debug:
                print_msg("Vector_C = " + str(Vector_C))

            # Calculate intersection Point
            Vector_T, _, _ = intersectPerpendicularLine(Vector_A,
                                                        Vector_B,
                                                        Vector_C,)
            if m_debug:
                print_msg("Vector_T = " + str(Vector_T))

            Vector_Translate = (Vector_B - Vector_A)
            if m_distanceLinePoint != 0.0:
                Vector_Translate = Vector_Translate.normalize() * m_distanceLinePoint
                Vector_point = Vector_T + Vector_Translate
            else:
                Vector_point = Vector_T

            if Vector_point is not None:
                point = Part.Point(Vector_point)
                selfobj.Shape = point.toShape()
                propertiesPoint(selfobj.Label, self.color)
                selfobj.X = float(Vector_point.x)
                selfobj.Y = float(Vector_point.y)
                selfobj.Z = float(Vector_point.z)
                # To be compatible with previous version 2018
                if 'Parametric' in selfobj.PropertiesList:
                    self.created = True

        except Exception as err:
            printError_msg(err.message, title=m_macro)
Example #14
0
    def draw(self):
        if self.side == "Right":
            self.rodDia = gv.yRodDiaR
        elif self.side == "Left":
            self.rodDia = gv.yRodDiaL

        #set up helper Variables

        columnWidth = (gv.yRodDiaMax + gv.printedToPrintedDia +
                       gv.clampNutFaceToFace + 2 * gv.clampNutPadding)

        try:
            Gui.getDocument(self.name)
            Gui.getDocument(self.name).resetEdit()
            App.getDocument(self.name).recompute()
            App.closeDocument(self.name)
            App.setActiveDocument("")
            App.ActiveDocument = None
            Gui.ActiveDocument = None
        except:
            pass

        #make document
        App.newDocument(self.name)
        App.setActiveDocument(self.name)
        App.ActiveDocument = App.getDocument(self.name)
        Gui.ActiveDocument = Gui.getDocument(self.name)
        App.ActiveDocument = App.getDocument(self.name)

        #Create tabs
        #Sketch points
        p1x = -gv.yRodSupportWidth / 2
        p1y = gv.frameWidth / 2
        p2x = gv.yRodSupportWidth / 2
        p2y = gv.frameWidth / 2
        p3x = gv.yRodSupportWidth / 2
        p3y = -gv.frameWidth / 2
        p4x = -gv.yRodSupportWidth / 2
        p4y = -gv.frameWidth / 2

        #MakeSketch
        App.activeDocument().addObject('Sketcher::SketchObject', 'Sketch')
        App.activeDocument().Sketch.Placement = App.Placement(
            App.Vector(0.000000, 0.000000, 0.000000),
            App.Rotation(0.000000, 0.000000, 0.000000, 1.000000))
        Gui.activeDocument().activeView().setCamera(
            '#Inventor V2.1 ascii \n OrthographicCamera {\n viewportMapping ADJUST_CAMERA \n position 0 0 87 \n orientation 0 0 1  0 \n nearDistance -112.88701 \n farDistance 287.28702 \n aspectRatio 1 \n focalDistance 87 \n height 143.52005 }'
        )
        #		Gui.activeDocument().setEdit('Sketch')
        App.ActiveDocument.Sketch.addGeometry(
            Part.Line(App.Vector(p1x, p1y, 0), App.Vector(p2x, p2y, 0)))
        App.ActiveDocument.Sketch.addGeometry(
            Part.Line(App.Vector(p2x, p2y, 0), App.Vector(p3x, p3y, 0)))
        App.ActiveDocument.Sketch.addGeometry(
            Part.Line(App.Vector(p3x, p3y, 0), App.Vector(p4x, p4y, 0)))
        App.ActiveDocument.Sketch.addGeometry(
            Part.Line(App.Vector(p4x, p4y, 0), App.Vector(p1x, p1y, 0)))
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('Coincident', 0, 2, 1, 1))
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('Coincident', 1, 2, 2, 1))
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('Coincident', 2, 2, 3, 1))
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('Coincident', 3, 2, 0, 1))
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('Horizontal', 0))
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('Horizontal', 2))
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('Vertical', 1))
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('Vertical', 3))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('Symmetric', 0, 1, 1, 2, -1, 1))
        App.ActiveDocument.recompute()

        #add dimensions
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('DistanceY', 1, -gv.frameWidth))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('DistanceX', 2, -gv.yRodSupportWidth))
        App.ActiveDocument.recompute()
        #		Gui.getDocument(self.name).resetEdit()
        App.getDocument(self.name).recompute()

        #Pad Sketch
        App.activeDocument().addObject("PartDesign::Pad", "Pad")
        App.activeDocument().Pad.Sketch = App.activeDocument().Sketch
        App.activeDocument().Pad.Length = 10.0
        App.ActiveDocument.recompute()
        Gui.activeDocument().hide("Sketch")
        App.ActiveDocument.Pad.Length = gv.tabThickness
        App.ActiveDocument.Pad.Reversed = 0
        App.ActiveDocument.Pad.Midplane = 0
        App.ActiveDocument.Pad.Length2 = 100.000000
        App.ActiveDocument.Pad.Type = 0
        App.ActiveDocument.Pad.UpToFace = None
        App.ActiveDocument.recompute()
        #		Gui.activeDocument().resetEdit()

        #Cut slot on right side
        #Sketch points
        p1x = gv.yRodSupportWidth / 2 - gv.slotPadding - gv.slotDia / 2 - gv.slotWidth
        p1y = 0
        p2x = gv.yRodSupportWidth / 2 - gv.slotPadding - gv.slotDia / 2
        p2y = 0
        p3x = gv.yRodSupportWidth / 2 - gv.slotPadding - gv.slotDia / 2 - gv.slotWidth
        p3y = -gv.slotDia / 2
        p4x = gv.yRodSupportWidth / 2 - gv.slotPadding - gv.slotDia / 2 - gv.slotWidth
        p4y = gv.slotDia / 2
        p5x = gv.yRodSupportWidth / 2 - gv.slotPadding - gv.slotDia / 2
        p5y = gv.slotDia / 2
        p6x = gv.yRodSupportWidth / 2 - gv.slotPadding - gv.slotDia / 2
        p6y = -gv.slotDia / 2
        p7x = gv.yRodSupportWidth / 2 - gv.slotPadding
        p7y = 0

        #Make sketch
        App.activeDocument().addObject('Sketcher::SketchObject', 'Sketch001')
        App.activeDocument().Sketch001.Support = uf.getFace(
            App.ActiveDocument.Pad, None, None, None, None, gv.tabThickness, 0)
        App.activeDocument().recompute()
        #		Gui.activeDocument().setEdit('Sketch001')
        App.ActiveDocument.Sketch001.addExternal(
            "Pad",
            uf.getEdge(App.ActiveDocument.Pad, gv.yRodSupportWidth / 2, 0,
                       None, None, gv.tabThickness, 0))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addGeometry(
            Part.ArcOfCircle(
                Part.Circle(App.Vector(p1x, p1y, 0), App.Vector(0, 0, 1),
                            4.217310), math.pi / 2, -math.pi / 2))
        App.ActiveDocument.Sketch001.addGeometry(
            Part.ArcOfCircle(
                Part.Circle(App.Vector(p2x, p2y, 0), App.Vector(0, 0, 1),
                            4.217310), -math.pi / 2, math.pi / 2))
        App.ActiveDocument.Sketch001.addGeometry(
            Part.Line(App.Vector(p3x, p3y, 0), App.Vector(p6x, p6y, 0)))
        App.ActiveDocument.Sketch001.addGeometry(
            Part.Line(App.Vector(p4x, p4y, 0), App.Vector(p5x, p5y, 0)))
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Tangent', 0, 2))
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Tangent', 0, 3))
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Tangent', 1, 2))
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Tangent', 1, 3))
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Coincident', 0, 1, 3, 1))
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Coincident', 0, 2, 2, 1))
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Coincident', 2, 2, 1, 1))
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Coincident', 3, 2, 1, 2))
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Horizontal', 2))
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Equal', 0, 1))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('PointOnObject', 0, 3, -1))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addGeometry(
            Part.Point(App.Vector(32.724319, -0.106919, 0)))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('PointOnObject', 4, 1, -1))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('PointOnObject', 4, 1, 1))

        #add dimensions
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('DistanceX', 2, gv.slotWidth))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Radius', 1, gv.slotDia / 2))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Distance', 4, 1, -3, gv.slotPadding))
        App.ActiveDocument.recompute()
        #		Gui.getDocument(self.name).resetEdit()
        App.getDocument(self.name).recompute()

        #Cut slot through all
        App.activeDocument().addObject("PartDesign::Pocket", "Pocket")
        App.activeDocument().Pocket.Sketch = App.activeDocument().Sketch001
        App.activeDocument().Pocket.Length = 5.0
        App.ActiveDocument.recompute()
        Gui.activeDocument().hide("Sketch001")
        Gui.activeDocument().hide("Pad")
        #		Gui.ActiveDocument.Pocket.ShapeColor=Gui.ActiveDocument.Pad.ShapeColor
        #		Gui.ActiveDocument.Pocket.LineColor=Gui.ActiveDocument.Pad.LineColor
        #		Gui.ActiveDocument.Pocket.PointColor=Gui.ActiveDocument.Pad.PointColor
        App.ActiveDocument.Pocket.Length = 5.000000
        App.ActiveDocument.Pocket.Type = 1
        App.ActiveDocument.Pocket.UpToFace = None
        App.ActiveDocument.recompute()
        #		Gui.activeDocument().resetEdit()

        #Mirror the slot
        App.activeDocument().addObject("PartDesign::Mirrored", "Mirrored")
        App.ActiveDocument.recompute()
        App.activeDocument().Mirrored.Originals = [
            App.activeDocument().Pocket,
        ]
        App.activeDocument().Mirrored.MirrorPlane = (
            App.activeDocument().Sketch001, ["V_Axis"])
        Gui.activeDocument().Pocket.Visibility = False
        #		Gui.activeDocument().setEdit('Mirrored')
        #		Gui.ActiveDocument.Mirrored.ShapeColor=Gui.ActiveDocument.Pocket.ShapeColor
        #		Gui.ActiveDocument.Mirrored.DisplayMode=Gui.ActiveDocument.Pocket.DisplayMode
        App.ActiveDocument.Mirrored.Originals = [
            App.ActiveDocument.Pocket,
        ]
        App.ActiveDocument.Mirrored.MirrorPlane = (
            App.ActiveDocument.Sketch001, ["V_Axis"])
        App.ActiveDocument.recompute()
        #		Gui.activeDocument().resetEdit()

        #Make rod support column
        #Sketch points
        p1x = -columnWidth / 2
        p1y = -gv.frameWidth / 2
        p2x = -columnWidth / 2
        p2y = gv.frameWidth / 2
        p3x = columnWidth / 2
        p3y = gv.frameWidth / 2
        p4x = columnWidth / 2
        p4y = -gv.frameWidth / 2

        #Make sketch
        App.activeDocument().addObject('Sketcher::SketchObject', 'Sketch002')
        App.activeDocument().Sketch002.Support = uf.getFace(
            App.ActiveDocument.Mirrored, None, None, None, None, 0, 0)
        App.activeDocument().recompute()
        #		Gui.activeDocument().setEdit('Sketch002')
        App.ActiveDocument.Sketch002.addGeometry(
            Part.Line(App.Vector(p1x, p1y, 0), App.Vector(p4x, p4y, 0)))
        App.ActiveDocument.Sketch002.addGeometry(
            Part.Line(App.Vector(p4x, p4y, 0), App.Vector(p3x, p3y, 0)))
        App.ActiveDocument.Sketch002.addGeometry(
            Part.Line(App.Vector(p3x, p3y, 0), App.Vector(p2x, p2y, 0)))
        App.ActiveDocument.Sketch002.addGeometry(
            Part.Line(App.Vector(p2x, p2y, 0), App.Vector(p1x, p1y, 0)))
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('Coincident', 0, 2, 1, 1))
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('Coincident', 1, 2, 2, 1))
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('Coincident', 2, 2, 3, 1))
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('Coincident', 3, 2, 0, 1))
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('Horizontal', 0))
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('Horizontal', 2))
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('Vertical', 1))
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('Vertical', 3))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('Symmetric', 0, 1, 1, 2, -1, 1))
        App.ActiveDocument.recompute()

        #add dimensions
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('DistanceY', 1, gv.frameWidth))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('DistanceX', 2, -columnWidth))
        App.ActiveDocument.recompute()
        #		Gui.getDocument(self.name).resetEdit()
        App.getDocument(self.name).recompute()

        #pad rod support
        App.activeDocument().addObject("PartDesign::Pad", "Pad001")
        App.activeDocument().Pad001.Sketch = App.activeDocument().Sketch002
        App.activeDocument().Pad001.Length = 10.0
        App.ActiveDocument.recompute()
        Gui.activeDocument().hide("Sketch002")
        Gui.activeDocument().hide("Mirrored")
        #		Gui.ActiveDocument.Pad001.ShapeColor=Gui.ActiveDocument.Mirrored.ShapeColor
        #		Gui.ActiveDocument.Pad001.LineColor=Gui.ActiveDocument.Mirrored.LineColor
        #		Gui.ActiveDocument.Pad001.PointColor=Gui.ActiveDocument.Mirrored.PointColor
        App.ActiveDocument.Pad001.Length = gv.yRodStandoff - gv.clampGap / 2
        App.ActiveDocument.Pad001.Reversed = 1
        App.ActiveDocument.Pad001.Midplane = 0
        App.ActiveDocument.Pad001.Length2 = 100.000000
        App.ActiveDocument.Pad001.Type = 0
        App.ActiveDocument.Pad001.UpToFace = None
        App.ActiveDocument.recompute()
        #		Gui.activeDocument().resetEdit()

        #Refine shape
        App.ActiveDocument.addObject(
            'Part::Feature',
            'Refined').Shape = App.ActiveDocument.Pad001.Shape.removeSplitter(
            )
        App.ActiveDocument.ActiveObject.Label = App.ActiveDocument.Pad001.Label
        Gui.ActiveDocument.Pad001.hide()
        #		Gui.ActiveDocument.ActiveObject.ShapeColor=Gui.ActiveDocument.Pad001.ShapeColor
        #		Gui.ActiveDocument.ActiveObject.LineColor=Gui.ActiveDocument.Pad001.LineColor
        #		Gui.ActiveDocument.ActiveObject.PointColor=Gui.ActiveDocument.Pad001.PointColor
        App.ActiveDocument.recompute()

        #make cut out for rod
        #Sketch Points
        p1x = 0
        p1y = gv.yRodStandoff

        #Make Sketch
        App.activeDocument().addObject('Sketcher::SketchObject', 'Sketch003')
        App.activeDocument().Sketch003.Support = uf.getFace(
            App.ActiveDocument.Refined, 0, 0, -gv.frameWidth / 2, 0, None,
            None)
        App.activeDocument().recompute()
        #		Gui.activeDocument().setEdit('Sketch003')
        App.ActiveDocument.Sketch003.addGeometry(
            Part.Circle(App.Vector(p1x, p1y, 0), App.Vector(0, 0, 1),
                        self.rodDia / 2))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch003.addConstraint(
            Sketcher.Constraint('PointOnObject', 0, 3, -2))
        App.ActiveDocument.recompute()

        #Add dimensions
        App.ActiveDocument.Sketch003.addConstraint(
            Sketcher.Constraint('Radius', 0, self.rodDia / 2))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch003.addConstraint(
            Sketcher.Constraint('Distance', -1, 1, 0, 3, gv.yRodStandoff))
        App.ActiveDocument.recompute()
        #		Gui.getDocument(self.name).resetEdit()
        App.getDocument(self.name).recompute()

        #Make Cut
        App.activeDocument().addObject("PartDesign::Pocket", "Pocket001")
        App.activeDocument().Pocket001.Sketch = App.activeDocument().Sketch003
        App.activeDocument().Pocket001.Length = 5.0
        App.ActiveDocument.recompute()
        Gui.activeDocument().hide("Sketch003")
        Gui.activeDocument().hide("Refined")
        #		Gui.ActiveDocument.Pocket001.ShapeColor=Gui.ActiveDocument.Refined.ShapeColor
        #		Gui.ActiveDocument.Pocket001.LineColor=Gui.ActiveDocument.Refined.LineColor
        #		Gui.ActiveDocument.Pocket001.PointColor=Gui.ActiveDocument.Refined.PointColor
        App.ActiveDocument.Pocket001.Length = 5.000000
        App.ActiveDocument.Pocket001.Type = 1
        App.ActiveDocument.Pocket001.UpToFace = None
        App.ActiveDocument.recompute()
        #		Gui.activeDocument().resetEdit()

        #Make Clamp hole
        #Sketch Points
        p1x = gv.yRodDiaMax / 2 + gv.printedToPrintedDia / 2
        p1y = 0

        #Make Sketch
        App.activeDocument().addObject('Sketcher::SketchObject', 'Sketch004')
        App.activeDocument().Sketch004.Support = uf.getFace(
            App.ActiveDocument.Pocket001, 0, 1, None, None,
            gv.yRodStandoff - gv.clampGap / 2, 0)
        App.activeDocument().recompute()
        #		Gui.activeDocument().setEdit('Sketch004')
        App.ActiveDocument.Sketch004.addGeometry(
            Part.Circle(App.Vector(p1x, p1y, 0), App.Vector(0, 0, 1),
                        gv.printedToPrintedDia / 2))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch004.addConstraint(
            Sketcher.Constraint('PointOnObject', 0, 3, -1))
        App.ActiveDocument.recompute()

        #Add Dimensions
        App.ActiveDocument.Sketch004.addConstraint(
            Sketcher.Constraint('DistanceX', -1, 1, 0, 3, gv.yRodDiaMax / 2 +
                                gv.printedToPrintedDia / 2))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch004.addConstraint(
            Sketcher.Constraint('Radius', 0, gv.printedToPrintedDia / 2))
        App.ActiveDocument.recompute()
        #		Gui.getDocument(self.name).resetEdit()
        App.getDocument(self.name).recompute()

        #Cut clamp hole though all
        App.activeDocument().addObject("PartDesign::Pocket", "Pocket002")
        App.activeDocument().Pocket002.Sketch = App.activeDocument().Sketch004
        App.activeDocument().Pocket002.Length = 5.0
        App.ActiveDocument.recompute()
        Gui.activeDocument().hide("Sketch004")
        Gui.activeDocument().hide("Pocket001")
        #		Gui.ActiveDocument.Pocket002.ShapeColor=Gui.ActiveDocument.Pocket001.ShapeColor
        #		Gui.ActiveDocument.Pocket002.LineColor=Gui.ActiveDocument.Pocket001.LineColor
        #		Gui.ActiveDocument.Pocket002.PointColor=Gui.ActiveDocument.Pocket001.PointColor
        App.ActiveDocument.Pocket002.Length = 5.000000
        App.ActiveDocument.Pocket002.Type = 1
        App.ActiveDocument.Pocket002.UpToFace = None
        App.ActiveDocument.recompute()
        #		Gui.activeDocument().resetEdit()

        #Mirror clamp hole
        App.activeDocument().addObject("PartDesign::Mirrored", "Mirrored001")
        App.ActiveDocument.recompute()
        App.activeDocument().Mirrored001.Originals = [
            App.activeDocument().Pocket002,
        ]
        App.activeDocument().Mirrored001.MirrorPlane = (
            App.activeDocument().Sketch004, ["V_Axis"])
        Gui.activeDocument().Pocket002.Visibility = False
        #		Gui.ActiveDocument.Mirrored001.ShapeColor=Gui.ActiveDocument.Pocket002.ShapeColor
        #		Gui.ActiveDocument.Mirrored001.DisplayMode=Gui.ActiveDocument.Pocket002.DisplayMode
        App.ActiveDocument.Mirrored001.Originals = [
            App.ActiveDocument.Pocket002,
        ]
        App.ActiveDocument.Mirrored001.MirrorPlane = (
            App.ActiveDocument.Sketch004, ["V_Axis"])
        App.ActiveDocument.recompute()
        #		Gui.activeDocument().resetEdit()

        App.ActiveDocument.addObject(
            'Part::Feature', 'Refined001'
        ).Shape = App.ActiveDocument.Mirrored001.Shape.removeSplitter()
        App.ActiveDocument.ActiveObject.Label = 'Refined001'
        Gui.ActiveDocument.Mirrored001.hide()

        Gui.ActiveDocument.ActiveObject.ShapeColor = Gui.ActiveDocument.Mirrored001.ShapeColor
        Gui.ActiveDocument.ActiveObject.LineColor = Gui.ActiveDocument.Mirrored001.LineColor
        Gui.ActiveDocument.ActiveObject.PointColor = Gui.ActiveDocument.Mirrored001.PointColor
        App.ActiveDocument.recompute()

        #Cut nut trap in bottom of support
        #Add Nut trap to right side
        #Sketch Points
        mat = uf.hexagonPoints(gv.yRodDiaMax / 2 + gv.printedToPrintedDia / 2,
                               0, gv.clampNutFaceToFace, 0)

        p1x = mat[0][0]
        p1y = mat[0][1]
        p2x = mat[1][0]
        p2y = mat[1][1]
        p3x = mat[2][0]
        p3y = mat[2][1]
        p4x = mat[3][0]
        p4y = mat[3][1]
        p5x = mat[4][0]
        p5y = mat[4][1]
        p6x = mat[5][0]
        p6y = mat[5][1]
        p7x = mat[6][0]
        p7y = mat[6][1]
        hexRadius = mat[7][0]

        #make sketch
        App.activeDocument().addObject('Sketcher::SketchObject', 'Sketch005')
        App.activeDocument().Sketch005.Support = uf.getFace(
            App.ActiveDocument.Refined001, None, None, None, None, 0, 0)
        App.activeDocument().recompute()
        #		Gui.activeDocument().setEdit('Sketch005')

        #error here
        App.ActiveDocument.Sketch005.addExternal(
            "Refined001",
            uf.getEdge(
                App.ActiveDocument.Refined001,
                #  														  gv.yRodDiaMax/2+gv.printedToPrintedDia/2, 0,
                None,
                None,
                None,
                None,
                0,
                0,
                center=(gv.yRodDiaMax / 2 + gv.printedToPrintedDia / 2, 0, 0),
                makeUnique=1))
        #  														  radius = gv.printedToPrintedDia/2))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch005.addGeometry(
            Part.Line(App.Vector(p1x, p1y, 0), App.Vector(p2x, p2y, 0)))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch005.addGeometry(
            Part.Line(App.Vector(p2x, p2y, 0), App.Vector(p3x, p3y, 0)))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch005.addConstraint(
            Sketcher.Constraint('Coincident', 0, 2, 1, 1))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch005.addGeometry(
            Part.Line(App.Vector(p3x, p3y, 0), App.Vector(p4x, p4y, 0)))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch005.addConstraint(
            Sketcher.Constraint('Coincident', 1, 2, 2, 1))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch005.addGeometry(
            Part.Line(App.Vector(p4x, p4y, 0), App.Vector(p5x, p5y, 0)))
        App.ActiveDocument.Sketch005.addConstraint(
            Sketcher.Constraint('Coincident', 2, 2, 3, 1))
        App.ActiveDocument.recompute()
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch005.addGeometry(
            Part.Line(App.Vector(p5x, p5y, 0), App.Vector(p6x, p6y, 0)))
        App.ActiveDocument.Sketch005.addConstraint(
            Sketcher.Constraint('Coincident', 3, 2, 4, 1))
        App.ActiveDocument.recompute()
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch005.addGeometry(
            Part.Line(App.Vector(p6x, p6y, 0), App.Vector(p1x, p1y, 0)))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch005.addConstraint(
            Sketcher.Constraint('Coincident', 4, 2, 5, 1))
        App.ActiveDocument.recompute()
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch005.addConstraint(
            Sketcher.Constraint('Coincident', 5, 2, 0, 1))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch005.addGeometry(
            Part.Circle(App.Vector(p7x, p7y, 0), App.Vector(0, 0, 1),
                        hexRadius))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch005.addConstraint(
            Sketcher.Constraint('PointOnObject', 0, 1, 6))
        App.ActiveDocument.Sketch005.addConstraint(
            Sketcher.Constraint('PointOnObject', 0, 2, 6))
        App.ActiveDocument.Sketch005.addConstraint(
            Sketcher.Constraint('PointOnObject', 1, 2, 6))
        App.ActiveDocument.Sketch005.addConstraint(
            Sketcher.Constraint('PointOnObject', 2, 2, 6))
        App.ActiveDocument.Sketch005.addConstraint(
            Sketcher.Constraint('PointOnObject', 3, 2, 6))
        App.ActiveDocument.Sketch005.addConstraint(
            Sketcher.Constraint('PointOnObject', 4, 2, 6))
        App.ActiveDocument.Sketch005.addConstraint(
            Sketcher.Constraint('Equal', 5, 0))
        App.ActiveDocument.Sketch005.addConstraint(
            Sketcher.Constraint('Equal', 0, 1))
        App.ActiveDocument.Sketch005.addConstraint(
            Sketcher.Constraint('Equal', 1, 2))
        App.ActiveDocument.Sketch005.addConstraint(
            Sketcher.Constraint('Equal', 2, 3))
        App.ActiveDocument.Sketch005.addConstraint(
            Sketcher.Constraint('Equal', 3, 4))
        App.ActiveDocument.Sketch005.toggleConstruction(6)
        App.ActiveDocument.Sketch005.addConstraint(
            Sketcher.Constraint('Coincident', -3, 3, 6, 3))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch005.addConstraint(
            Sketcher.Constraint('Vertical', 2))

        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch005.addConstraint(
            Sketcher.Constraint('Distance', 0, 2, 4, gv.clampNutFaceToFace))
        App.ActiveDocument.recompute()
        #		Gui.getDocument(self.name).resetEdit()
        App.getDocument(self.name).recompute()

        #cut nut trap out
        App.activeDocument().addObject("PartDesign::Pocket", "Pocket003")
        App.activeDocument().Pocket003.Sketch = App.activeDocument().Sketch005
        App.activeDocument().Pocket003.Length = 5.0
        App.ActiveDocument.recompute()
        Gui.activeDocument().hide("Sketch005")
        Gui.activeDocument().hide("Refined001")
        #		Gui.ActiveDocument.Pocket003.ShapeColor=Gui.ActiveDocument.Pocket002.ShapeColor
        #		Gui.ActiveDocument.Pocket003.LineColor=Gui.ActiveDocument.Pocket002.LineColor
        #		Gui.ActiveDocument.Pocket003.PointColor=Gui.ActiveDocument.Pocket002.PointColor
        App.ActiveDocument.Pocket003.Length = gv.rodSupportNutTrapDepthMin
        App.ActiveDocument.Pocket003.Type = 0
        App.ActiveDocument.Pocket003.UpToFace = None
        App.ActiveDocument.recompute()
        #		Gui.activeDocument().resetEdit()

        #Mirror nut trap
        App.activeDocument().addObject("PartDesign::Mirrored", "Mirrored002")
        App.ActiveDocument.recompute()
        App.activeDocument().Mirrored002.Originals = [
            App.activeDocument().Pocket003,
        ]
        App.activeDocument().Mirrored002.MirrorPlane = (
            App.activeDocument().Sketch005, ["V_Axis"])
        Gui.activeDocument().Pocket003.Visibility = False
        #		Gui.ActiveDocument.Mirrored002.ShapeColor=Gui.ActiveDocument.Pocket003.ShapeColor
        #		Gui.ActiveDocument.Mirrored002.DisplayMode=Gui.ActiveDocument.Pocket003.DisplayMode
        App.ActiveDocument.Mirrored002.Originals = [
            App.ActiveDocument.Pocket003,
        ]
        App.ActiveDocument.Mirrored002.MirrorPlane = (
            App.ActiveDocument.Sketch005, ["V_Axis"])
        App.ActiveDocument.recompute()
        #		Gui.activeDocument().resetEdit()
        Gui.getDocument(self.name).getObject("Mirrored001").Visibility = False

        #Set view to axometric
        #		Gui.activeDocument().activeView().viewAxometric()

        #Make Cap
        try:
            #		Gui.getDocument(self.name+"Clamp")
            #		Gui.getDocument(self.name+"Clamp").resetEdit()
            App.getDocument(self.name + "Clamp").recompute()
            App.closeDocument(self.name + "Clamp")
            App.setActiveDocument("")
            App.ActiveDocument = None

    #		Gui.ActiveDocument=None
        except:
            pass

        #make document
        App.newDocument(self.name + "Clamp")
        App.setActiveDocument(self.name + "Clamp")
        App.ActiveDocument = App.getDocument(self.name + "Clamp")
        #		Gui.ActiveDocument=Gui.getDocument(self.name+"Clamp")
        App.ActiveDocument = App.getDocument(self.name + "Clamp")

        #Make clamp body
        #Sketch points
        p1x = -columnWidth / 2
        p1y = -gv.frameWidth / 2
        p2x = -columnWidth / 2
        p2y = gv.frameWidth / 2
        p3x = columnWidth / 2
        p3y = gv.frameWidth / 2
        p4x = columnWidth / 2
        p4y = -gv.frameWidth / 2

        #Make Sketch
        App.activeDocument().addObject('Sketcher::SketchObject', 'Sketch')
        App.activeDocument().Sketch.Placement = App.Placement(
            App.Vector(0.000000, 0.000000, 0.000000),
            App.Rotation(0.000000, 0.000000, 0.000000, 1.000000))
        #		Gui.activeDocument().activeView().setCamera('#Inventor V2.1 ascii \n OrthographicCamera {\n viewportMapping ADJUST_CAMERA \n position 0 0 87 \n orientation 0 0 1  0 \n nearDistance -112.88701 \n farDistance 287.28702 \n aspectRatio 1 \n focalDistance 87 \n height 143.52005 }')
        #		Gui.activeDocument().setEdit('Sketch')
        App.ActiveDocument.Sketch.addGeometry(
            Part.Line(App.Vector(p1x, p1y, 0), App.Vector(p4x, p4y, 0)))
        App.ActiveDocument.Sketch.addGeometry(
            Part.Line(App.Vector(p4x, p4y, 0), App.Vector(p3x, p3y, 0)))
        App.ActiveDocument.Sketch.addGeometry(
            Part.Line(App.Vector(p3x, p3y, 0), App.Vector(p2x, p2y, 0)))
        App.ActiveDocument.Sketch.addGeometry(
            Part.Line(App.Vector(p2x, p2y, 0), App.Vector(p1x, p1y, 0)))
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('Coincident', 0, 2, 1, 1))
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('Coincident', 1, 2, 2, 1))
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('Coincident', 2, 2, 3, 1))
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('Coincident', 3, 2, 0, 1))
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('Horizontal', 0))
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('Horizontal', 2))
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('Vertical', 1))
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('Vertical', 3))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('Symmetric', 0, 1, 1, 2, -1, 1))
        App.ActiveDocument.recompute()

        #add dimensions
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('DistanceY', 1, gv.frameWidth))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('DistanceX', 2, -columnWidth))
        App.ActiveDocument.recompute()
        #		Gui.getDocument(self.name+"Clamp").resetEdit()
        App.getDocument(self.name + "Clamp").recompute()

        #pad rod support
        App.activeDocument().addObject("PartDesign::Pad", "Pad")
        App.activeDocument().Pad.Sketch = App.activeDocument().Sketch
        App.activeDocument().Pad.Length = 10.0
        App.ActiveDocument.recompute()
        Gui.activeDocument().hide("Sketch")
        App.ActiveDocument.Pad.Length = gv.yRodDiaMax / 2 + gv.clampThickness - gv.clampGap / 2
        App.ActiveDocument.Pad.Reversed = 0
        App.ActiveDocument.Pad.Midplane = 0
        App.ActiveDocument.Pad.Length2 = 100.000000
        App.ActiveDocument.Pad.Type = 0
        App.ActiveDocument.Pad.UpToFace = None
        App.ActiveDocument.recompute()
        #		Gui.activeDocument().resetEdit()

        #make cut out for rod
        #sketch points
        p1x = 0
        p1y = gv.yRodDiaMax / 2 + gv.clampThickness
        p2x = -self.rodDia / 2
        p2y = gv.yRodDiaMax + gv.clampThickness
        p3x = self.rodDia / 2
        p3y = gv.yRodDiaMax + gv.clampThickness

        #Make Sketch
        #make sketch
        App.activeDocument().addObject('Sketcher::SketchObject', 'Sketch001')
        App.activeDocument().Sketch001.Support = uf.getFace(
            App.ActiveDocument.Pad, None, None, -gv.frameWidth / 2, 0, None,
            None)
        App.activeDocument().recompute()
        #		Gui.activeDocument().setEdit('Sketch001')
        App.ActiveDocument.Sketch001.addExternal(
            "Pad",
            uf.getEdge(App.ActiveDocument.Pad, None, None, -gv.frameWidth / 2,
                       0,
                       gv.yRodDiaMax / 2 + gv.clampThickness - gv.clampGap / 2,
                       0))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addGeometry(
            Part.ArcOfCircle(
                Part.Circle(App.Vector(p1x, p1y, 0), App.Vector(0, 0, 1),
                            self.rodDia / 2), math.pi, 2 * math.pi))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('PointOnObject', 0, 3, -2))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addGeometry(
            Part.Line(App.Vector(p2x, p2y, 0), App.Vector(p3x, p3y, 0)))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Coincident', 1, 1, 0, 1))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Coincident', 1, 2, 0, 2))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Horizontal', 1))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('PointOnObject', 0, 3, 1))

        #Add dimensions
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Distance', 0, 3, -3, gv.clampGap / 2))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Radius', 0, self.rodDia / 2))
        App.ActiveDocument.recompute()
        #		Gui.getDocument(self.name+"Clamp").resetEdit()
        App.getDocument(self.name + "Clamp").recompute()

        #Cut through all
        App.activeDocument().addObject("PartDesign::Pocket", "Pocket")
        App.activeDocument().Pocket.Sketch = App.activeDocument().Sketch001
        App.activeDocument().Pocket.Length = 5.0
        App.ActiveDocument.recompute()
        Gui.activeDocument().hide("Sketch001")
        Gui.activeDocument().hide("Pad")
        #		Gui.ActiveDocument.Pocket.ShapeColor=Gui.ActiveDocument.Pad.ShapeColor
        #		Gui.ActiveDocument.Pocket.LineColor=Gui.ActiveDocument.Pad.LineColor
        #		Gui.ActiveDocument.Pocket.PointColor=Gui.ActiveDocument.Pad.PointColor
        App.ActiveDocument.Pocket.Length = 5.000000
        App.ActiveDocument.Pocket.Type = 1
        App.ActiveDocument.Pocket.UpToFace = None
        App.ActiveDocument.recompute()
        #		Gui.activeDocument().resetEdit()

        #cut Right clamp hole
        #Sketch points
        p1x = gv.yRodDiaMax / 2 + gv.printedToPrintedDia / 2
        p1y = 0

        #Make sketch
        App.activeDocument().addObject('Sketcher::SketchObject', 'Sketch002')
        App.activeDocument().Sketch002.Support = uf.getFace(
            App.ActiveDocument.Pocket, 0, 1, 0, 0,
            gv.yRodDiaMax / 2 + gv.clampThickness - gv.clampGap / 2, 0)
        App.activeDocument().recompute()
        #		Gui.activeDocument().setEdit('Sketch002')
        App.ActiveDocument.Sketch002.addGeometry(
            Part.Circle(App.Vector(p1x, p1y, 0), App.Vector(0, 0, 1),
                        gv.printedToPrintedDia / 2))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('PointOnObject', 0, 3, -1))
        App.ActiveDocument.recompute()

        #Add dimensions
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('Radius', 0, gv.printedToPrintedDia / 2))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('Distance', -1, 1, 0, 3, gv.yRodDiaMax / 2 +
                                gv.printedToPrintedDia / 2))
        App.ActiveDocument.recompute()
        #		Gui.getDocument(self.name+"Clamp").resetEdit()
        App.getDocument(self.name + "Clamp").recompute()

        #Cut clamp hole through all
        App.activeDocument().addObject("PartDesign::Pocket", "Pocket001")
        App.activeDocument().Pocket001.Sketch = App.activeDocument().Sketch002
        App.activeDocument().Pocket001.Length = 5.0
        App.ActiveDocument.recompute()
        Gui.activeDocument().hide("Sketch002")
        Gui.activeDocument().hide("Pocket")
        #		Gui.ActiveDocument.Pocket001.ShapeColor=Gui.ActiveDocument.Pocket.ShapeColor
        #		Gui.ActiveDocument.Pocket001.LineColor=Gui.ActiveDocument.Pocket.LineColor
        #		Gui.ActiveDocument.Pocket001.PointColor=Gui.ActiveDocument.Pocket.PointColor
        App.ActiveDocument.Pocket001.Length = 5.000000
        App.ActiveDocument.Pocket001.Type = 1
        App.ActiveDocument.Pocket001.UpToFace = None
        App.ActiveDocument.recompute()
        #		Gui.activeDocument().resetEdit()

        #Mirror clamp hole
        App.activeDocument().addObject("PartDesign::Mirrored", "Mirrored")
        App.ActiveDocument.recompute()
        App.activeDocument().Mirrored.Originals = [
            App.activeDocument().Pocket001,
        ]
        App.activeDocument().Mirrored.MirrorPlane = (
            App.activeDocument().Sketch002, ["V_Axis"])
        Gui.activeDocument().Pocket001.Visibility = False
        #		Gui.activeDocument().setEdit('Mirrored')
        #		Gui.ActiveDocument.Mirrored.ShapeColor=Gui.ActiveDocument.Pocket001.ShapeColor
        #		Gui.ActiveDocument.Mirrored.DisplayMode=Gui.ActiveDocument.Pocket001.DisplayMode
        App.ActiveDocument.Mirrored.Originals = [
            App.ActiveDocument.Pocket001,
        ]
        App.ActiveDocument.Mirrored.MirrorPlane = (
            App.ActiveDocument.Sketch002, ["V_Axis"])
        App.ActiveDocument.recompute()
Example #15
0
def createSketch_MiddleProfile(doc):
    MiddleProfile = doc.addObject('Sketcher::SketchObject', 'MiddleProfile')
    MiddleProfile.addGeometry(
        Part.Circle(Vector(45.0, 40.0, 0.0), Vector(0.0, 0.0, 1.0), 10.0),
        True)
    MiddleProfile.addGeometry(
        Part.Circle(Vector(69.0, 40.0, 0.0), Vector(0.0, 0.0, 1.0), 10.0),
        True)
    MiddleProfile.addGeometry(
        Part.Circle(Vector(75.0, 25.0, 0.0), Vector(0.0, 0.0, 1.0), 10.0),
        True)
    MiddleProfile.addGeometry(
        Part.BSplineCurve([
            Vector(45.0, 40.0, 0.0),
            Vector(69.0, 40.0, 0.0),
            Vector(75.0, 25.0, 0.0)
        ]), False)
    MiddleProfile.addGeometry(
        Part.Circle(Vector(45.0, -20.0, 0.0), Vector(0.0, 0.0, 1.0), 10.0),
        True)
    MiddleProfile.addGeometry(
        Part.Circle(Vector(69.0, -20.0, 0.0), Vector(0.0, 0.0, 1.0), 10.0),
        True)
    MiddleProfile.addGeometry(
        Part.Circle(Vector(75.0, -5.0, 0.0), Vector(0.0, 0.0, 1.0), 10.0),
        True)
    MiddleProfile.addGeometry(
        Part.BSplineCurve([
            Vector(45.0, -20.0, 0.0),
            Vector(69.0, -20.0, 0.0),
            Vector(75.0, -5.0, 0.0)
        ]), False)
    MiddleProfile.addGeometry(Part.Point(Vector(45.0, -20.0, 0.0)), False)
    MiddleProfile.addGeometry(
        Part.LineSegment(Vector(75.0, 25.0, 0.0), Vector(75.0, -5.0, 0.0)),
        False)
    MiddleProfile.addGeometry(
        Part.LineSegment(Vector(45.0, 40.0, 0.0), Vector(69.0, 40.0, 0.0)),
        True)
    MiddleProfile.addGeometry(
        Part.LineSegment(Vector(69.0, -20.0, 0.0), Vector(45.0, -20.0, 0.0)),
        True)
    MiddleProfile.addGeometry(
        Part.LineSegment(Vector(45.0, 40.0, 0.0), Vector(0.0, 40.0, 0.0)),
        False)
    MiddleProfile.addGeometry(
        Part.LineSegment(Vector(0.0, 40.0, 0.0), Vector(0.0, -20.0, 0.0)),
        False)
    MiddleProfile.addGeometry(
        Part.LineSegment(Vector(0.0, -20.0, 0.0), Vector(45.0, -20.0, 0.0)),
        False)
    MiddleProfile.addConstraint(Sketcher.Constraint('Radius', 0, 10.0))
    MiddleProfile.addConstraint(Sketcher.Constraint('Equal', 0, 1))
    MiddleProfile.addConstraint(Sketcher.Constraint('Equal', 0, 2))
    MiddleProfile.addConstraint(
        Sketcher.Constraint('InternalAlignment:Sketcher::BSplineControlPoint',
                            0, 3, 3, 0))
    MiddleProfile.addConstraint(
        Sketcher.Constraint('InternalAlignment:Sketcher::BSplineControlPoint',
                            1, 3, 3, 1))
    MiddleProfile.addConstraint(
        Sketcher.Constraint('InternalAlignment:Sketcher::BSplineControlPoint',
                            2, 3, 3, 2))
    MiddleProfile.addConstraint(Sketcher.Constraint('Radius', 4, 10.0))
    MiddleProfile.addConstraint(Sketcher.Constraint('Equal', 4, 5))
    MiddleProfile.addConstraint(Sketcher.Constraint('Equal', 4, 6))
    MiddleProfile.addConstraint(
        Sketcher.Constraint('InternalAlignment:Sketcher::BSplineControlPoint',
                            4, 3, 7, 0))
    MiddleProfile.addConstraint(
        Sketcher.Constraint('InternalAlignment:Sketcher::BSplineControlPoint',
                            5, 3, 7, 1))
    MiddleProfile.addConstraint(
        Sketcher.Constraint('InternalAlignment:Sketcher::BSplineControlPoint',
                            6, 3, 7, 2))
    MiddleProfile.addConstraint(Sketcher.Constraint('Coincident', 9, 2, 7, 2))
    MiddleProfile.addConstraint(Sketcher.Constraint('Vertical', 9))
    MiddleProfile.addConstraint(Sketcher.Constraint('Coincident', 9, 1, 3, 2))
    MiddleProfile.addConstraint(Sketcher.Constraint('DistanceX', 7, 2, 75.0))
    MiddleProfile.addConstraint(Sketcher.Constraint('DistanceY', 3, 2, 25.0))
    MiddleProfile.addConstraint(Sketcher.Constraint('DistanceY', 7, 2, -5.0))
    MiddleProfile.addConstraint(Sketcher.Constraint('Coincident', 10, 1, 3, 1))
    MiddleProfile.addConstraint(Sketcher.Constraint('Coincident', 10, 2, 1, 3))
    MiddleProfile.addConstraint(Sketcher.Constraint('Horizontal', 10))
    MiddleProfile.addConstraint(Sketcher.Constraint('Coincident', 11, 1, 5, 3))
    MiddleProfile.addConstraint(Sketcher.Constraint('Coincident', 11, 2, 7, 1))
    MiddleProfile.addConstraint(Sketcher.Constraint('Horizontal', 11))
    MiddleProfile.addConstraint(Sketcher.Constraint('DistanceY', 3, 1, 40.0))
    MiddleProfile.addConstraint(Sketcher.Constraint('DistanceY', 8, 1, -20.0))
    MiddleProfile.addConstraint(Sketcher.Constraint('Coincident', 8, 1, 7, 1))
    MiddleProfile.addConstraint(Sketcher.Constraint('Equal', 11, 10))
    MiddleProfile.addConstraint(Sketcher.Constraint('Coincident', 12, 1, 3, 1))
    MiddleProfile.addConstraint(Sketcher.Constraint('Horizontal', 12))
    MiddleProfile.addConstraint(Sketcher.Constraint('Vertical', 13))
    MiddleProfile.addConstraint(Sketcher.Constraint('Coincident', 13, 2, 14,
                                                    1))
    MiddleProfile.addConstraint(Sketcher.Constraint('Coincident', 14, 2, 7, 1))
    MiddleProfile.addConstraint(Sketcher.Constraint('Horizontal', 14))
    MiddleProfile.addConstraint(Sketcher.Constraint('Equal', 12, 14))
    MiddleProfile.addConstraint(
        Sketcher.Constraint('DistanceX', 12, 2, 12, 1, 45.0))
    MiddleProfile.addConstraint(Sketcher.Constraint('PointOnObject', 12, 2,
                                                    -2))
    MiddleProfile.addConstraint(
        Sketcher.Constraint('DistanceX', 10, 1, 10, 2, 24.0))
    MiddleProfile.addConstraint(Sketcher.Constraint('Coincident', 13, 1, 12,
                                                    2))
    MiddleProfile.Placement = Placement(
        Vector(0.0, 0.0, 0.0),
        Rotation(0.7071067811865475, -0.0, -0.0, 0.7071067811865476))
    MiddleProfile.ViewObject.Visibility = False
    return MiddleProfile
Example #16
0
def showPoint(v):
    Part.show(Part.Shape([Part.Point(v)]))
Example #17
0
def makeWingletProfile(doc):
    WingletProfile = doc.addObject('Sketcher::SketchObject', 'WingletProfile')
    print(WingletProfile.Label)
    WingletProfile.addGeometry(
        Part.LineSegment(Vector(210.0, 20.0, 0.0), Vector(375.0, 20.0, 0.0)),
        False)
    WingletProfile.addGeometry(
        Part.LineSegment(Vector(375.0, 20.0, 0.0), Vector(385.0, 100.0, 0.0)),
        False)
    WingletProfile.addGeometry(
        Part.LineSegment(Vector(385.0, 100.0, 0.0), Vector(305.0, 100.0, 0.0)),
        False)
    WingletProfile.addGeometry(
        Part.Circle(Vector(305.0, 100.0, 0.0), Vector(0.0, 0.0, 1.0), 0.8),
        True)
    WingletProfile.addGeometry(
        Part.Circle(Vector(295.0, 100.0, 0.0), Vector(0.0, 0.0, 1.0), 0.8),
        True)
    WingletProfile.addGeometry(
        Part.Circle(Vector(210.0, 20.0, 0.0), Vector(0.0, 0.0, 1.0), 0.8),
        True)
    WingletProfile.addGeometry(
        Part.BSplineCurve([
            Vector(305.0, 100.0, 0.0),
            Vector(295.0, 100.0, 0.0),
            Vector(210.0, 20.0, 0.0)
        ]), False)
    WingletProfile.addGeometry(Part.Point(Vector(305.0, 100.0, 0.0)), False)
    WingletProfile.addGeometry(Part.Point(Vector(210.0, 20.0, 0.0)), False)
    WingletProfile.addConstraint(Sketcher.Constraint('Horizontal', 0))
    WingletProfile.addConstraint(Sketcher.Constraint('Distance', 0, 165.0))
    WingletProfile.addConstraint(Sketcher.Constraint('Coincident', 1, 1, 0, 2))
    WingletProfile.addConstraint(Sketcher.Constraint('Coincident', 2, 1, 1, 2))
    WingletProfile.addConstraint(Sketcher.Constraint('Horizontal', 2))
    WingletProfile.addConstraint(Sketcher.Constraint('Radius', 3, 0.8))
    WingletProfile.addConstraint(Sketcher.Constraint('Equal', 3, 4))
    WingletProfile.addConstraint(Sketcher.Constraint('Equal', 3, 5))
    WingletProfile.addConstraint(Sketcher.Constraint('Coincident', 6, 2, 0, 1))
    WingletProfile.addConstraint(
        Sketcher.Constraint('InternalAlignment:Sketcher::BSplineControlPoint',
                            3, 3, 6, 0))
    WingletProfile.addConstraint(
        Sketcher.Constraint('InternalAlignment:Sketcher::BSplineControlPoint',
                            4, 3, 6, 1))
    WingletProfile.addConstraint(
        Sketcher.Constraint('InternalAlignment:Sketcher::BSplineControlPoint',
                            5, 3, 6, 2))
    #WingletProfile.addConstraint(Sketcher.Constraint('InternalAlignment:Sketcher::BSplineControlPoint', 7, 3, 6, 3))
    #WingletProfile.addConstraint(Sketcher.Constraint('InternalAlignment:Sketcher::BSplineControlPoint', 8, 3, 6, 4))
    WingletProfile.addConstraint(
        Sketcher.Constraint('DistanceY', 0, 2, 1, 2, 80.0))
    WingletProfile.addConstraint(Sketcher.Constraint('Coincident', 2, 2, 6, 1))
    WingletProfile.addConstraint(
        Sketcher.Constraint('DistanceX', 0, 2, 1, 2, 10.0))
    WingletProfile.addConstraint(
        Sketcher.Constraint('DistanceX', 4, 3, 1, 2, 90.0))
    WingletProfile.addConstraint(Sketcher.Constraint('PointOnObject', 4, 3, 2))
    WingletProfile.addConstraint(Sketcher.Constraint('DistanceY', 0, 1, 20.0))
    WingletProfile.addConstraint(Sketcher.Constraint('DistanceX', 0, 1, 210.0))
    WingletProfile.addConstraint(
        Sketcher.Constraint('DistanceX', 4, 3, 2, 2, 10.0))
    WingletProfile.Placement = Placement(Vector(0.0, 0.0, 0.0),
                                         Rotation(0.5, 0.5, 0.5, 0.5))
    return WingletProfile
Example #18
0
def displacement(ship,
                 draft=None,
                 roll=Units.parseQuantity("0 deg"),
                 trim=Units.parseQuantity("0 deg")):
    """Compute the ship displacement

    Position arguments:
    ship -- Ship object (see createShip)

    Keyword arguments:
    draft -- Ship draft (Design ship draft by default)
    roll -- Roll angle (0 degrees by default)
    trim -- Trim angle (0 degrees by default)

    Returned values:
    disp -- The ship displacement (a density of the water of 1025 kg/m^3 is
    assumed)
    B -- Bouyance application point, i.e. Center of mass of the underwater side
    Cb -- Block coefficient

    The Bouyance center is referred to the original ship position.
    """
    if draft is None:
        draft = ship.Draft

    shape, base_z = placeShipShape(ship.Shape.copy(), draft, roll, trim)
    shape = getUnderwaterSide(shape)

    vol = 0.0
    cog = Vector()
    if len(shape.Solids) > 0:
        for solid in shape.Solids:
            vol += solid.Volume
            sCoG = solid.CenterOfMass
            cog.x = cog.x + sCoG.x * solid.Volume
            cog.y = cog.y + sCoG.y * solid.Volume
            cog.z = cog.z + sCoG.z * solid.Volume
        cog.x = cog.x / vol
        cog.y = cog.y / vol
        cog.z = cog.z / vol

    bbox = shape.BoundBox
    Vol = (bbox.XMax - bbox.XMin) * (bbox.YMax - bbox.YMin) * abs(bbox.ZMin)

    # Undo the transformations on the bouyance point
    B = Part.Point(Vector(cog.x, cog.y, cog.z))
    m = Matrix()
    m.move(Vector(0.0, 0.0, draft))
    m.move(Vector(-draft * math.sin(trim.getValueAs("rad")), 0.0, 0.0))
    m.rotateY(trim.getValueAs("rad"))
    m.move(Vector(0.0, -draft * math.sin(roll.getValueAs("rad")), base_z))
    m.rotateX(-roll.getValueAs("rad"))
    B.transform(m)

    try:
        cb = vol / Vol
    except ZeroDivisionError:
        msg = QtGui.QApplication.translate(
            "ship_console",
            "ZeroDivisionError: Null volume found during the displacement"
            " computation!", None)
        App.Console.PrintError(msg + '\n')
        cb = 0.0

    # Return the computed data
    return (DENS * Units.Quantity(vol, Units.Volume), Vector(B.X, B.Y,
                                                             B.Z), cb)
Example #19
0
def runAAA(obj, vb2, vb, va):
    ta = time.time()

    sk = obj

    try:
        rc = obj.solve()
        if rc == 0:
            try:
                obj.setDatum('b2x', vb2.x)
                obj.setDatum('b2y', vb2.y)
                rc = sk.solve()
            except:
                obj.setDatum('b2y', vb2.y)
                obj.setDatum('b2x', vb2.x)
                rc = sk.solve()
        if rc == 0:
            try:
                obj.setDatum('ax', va.x)
                obj.setDatum('ay', va.y)
                rc = sk.solve()
            except:
                obj.setDatum('ay', va.y)
                obj.setDatum('ax', va.x)
                rc = sk.solve()
        if rc == 0:
            try:
                obj.setDatum('by', vb.y)
                obj.setDatum('bx', vb.x)
                rc = sk.solve()
            except:
                obj.setDatum('bx', vb.x)
                obj.setDatum('by', vb.y)
                rc = sk.solve()

    except Exception as e:
        if obj.step:
            #			print "EX ",e
            #			print "step ",obj.step
            #			print "b2",vb2
            #			print "a",va
            #			print "b",vb
            App.Console.PrintError(
                '\nEX step"+ str(obj.step)+" "+ str(e)+"\n"')
        rc = -99

    if rc == 0:
        a = App.ActiveDocument.recompute()
        tb = time.time()
        print("update time ", round(tb - ta, 3))
        return

    for lup in range(1):
        # print "LLLLLLLLLLLOOOOP" ,lup
        sk.deleteAllGeometry()

        va2 = va + vb2 - vb
        vm = (va2 + vb2) * 0.5

        b2 = sk.addGeometry(Part.Point(vb2))
        b = sk.addGeometry(Part.Point(vb))
        a = sk.addGeometry(Part.Point(va))
        a2 = sk.addGeometry(Part.Point(va2))
        m = sk.addGeometry(Part.Point(vm))

        b2x = sk.addConstraint(Sketcher.Constraint('DistanceX', b2, 1, vb2.x))
        sk.renameConstraint(b2x, u'b2x')
        b2y = sk.addConstraint(Sketcher.Constraint('DistanceY', b2, 1, vb2.y))
        sk.renameConstraint(b2y, u'b2y')
        c = sk.addConstraint(Sketcher.Constraint('DistanceX', b, 1, vb.x))
        sk.renameConstraint(c, u'bx')
        c = sk.addConstraint(Sketcher.Constraint('DistanceY', b, 1, vb.y))
        sk.renameConstraint(c, u'by')
        c = sk.addConstraint(Sketcher.Constraint('DistanceX', a, 1, va.x))
        sk.renameConstraint(c, u'ax')
        c = sk.addConstraint(Sketcher.Constraint('DistanceY', a, 1, va.y))
        sk.renameConstraint(c, u'ay')

        a2x = sk.addConstraint(Sketcher.Constraint('DistanceX', a2, 1, va2.x))
        sk.renameConstraint(a2x, u'a2x')
        a2y = sk.addConstraint(Sketcher.Constraint('DistanceY', a2, 1, va2.y))
        sk.renameConstraint(a2y, u'a2y')

        ab = sk.addGeometry(Part.LineSegment(va, vb), False)
        sk.addConstraint(Sketcher.Constraint('Coincident', ab, 1, a, 1))
        sk.addConstraint(Sketcher.Constraint('Coincident', ab, 2, b, 1))

        a2b2 = sk.addGeometry(Part.LineSegment(va2, vb2), False)
        sk.addConstraint(Sketcher.Constraint('Coincident', a2b2, 1, a2, 1))
        sk.addConstraint(Sketcher.Constraint('Coincident', a2b2, 2, b2, 1))

        lab = sk.addGeometry(Part.LineSegment(va, va2), False)
        sk.addConstraint(Sketcher.Constraint('Coincident', lab, 1, a, 1))
        sk.toggleConstruction(lab)

        sk.addConstraint(Sketcher.Constraint('Perpendicular', lab, ab))

        r = sk.addGeometry(Part.LineSegment(vm, vb), False)
        sk.addConstraint(Sketcher.Constraint('Coincident', r, 1, m, 1))
        sk.addConstraint(Sketcher.Constraint('Coincident', r, 2, b, 1))
        sk.toggleConstruction(r)

        sk.addConstraint(Sketcher.Constraint('PointOnObject', lab, 2, r))

        #	print "Move ..."
        try:
            sk.movePoint(m, 1, vm, 0)
        except Exception as e:
            App.Console.PrintWarning("\n!!!!!!!!!!!!!!!" + str(e))

        b2m = sk.addGeometry(Part.LineSegment(vb2, vm), False)
        sk.addConstraint(Sketcher.Constraint('Coincident', b2m, 1, b2, 1))
        sk.addConstraint(Sketcher.Constraint('Coincident', b2m, 2, m, 1))
        sk.toggleConstruction(b2m)

        a2m = sk.addGeometry(Part.LineSegment(va2, vm), False)
        sk.addConstraint(Sketcher.Constraint('Coincident', a2m, 1, a2, 1))
        sk.addConstraint(Sketcher.Constraint('Coincident', a2m, 2, m, 1))
        sk.toggleConstruction(a2m)

        a2l = sk.addGeometry(Part.LineSegment(va2, vm), False)
        sk.addConstraint(Sketcher.Constraint('Coincident', a2l, 1, a2, 1))
        sk.addConstraint(Sketcher.Constraint('Coincident', a2l, 2, lab, 2))
        sk.toggleConstruction(a2l)

        b2l = sk.addGeometry(Part.LineSegment(vb2, vm), False)
        sk.addConstraint(Sketcher.Constraint('Coincident', b2l, 1, b2, 1))
        sk.addConstraint(Sketcher.Constraint('Coincident', b2l, 2, lab, 2))
        sk.toggleConstruction(b2l)

        rc = sk.solve()
        #		print "ergebnis solve a_",rc

        sk.addConstraint(Sketcher.Constraint('Symmetric', b2, 1, a2, 1, m, 1))

        rc = sk.solve()
        #		print "ergebnis solve aa_",rc
        #		sk.delConstraint(25)

        cb = sk.addConstraint(Sketcher.Constraint('Equal', 12, 8))
        rc = sk.solve()
        #		print "ergebnis solve ac_",rc,"  bei ",cb

        rc = sk.solve()
        #		print "ergebnis solve ad_",rc

        sk.addConstraint(Sketcher.Constraint('Equal', 11, 7))

        rc = sk.solve()
        #		print "ergebnis solve ae_",rc

        sk.toggleDriving(a2x)

        cb = sk.addConstraint(Sketcher.Constraint('Equal', 12, 9))

        sk.toggleDriving(a2y)

        rc = sk.solve()
        #		print "ergebnis solve b_",rc

        sk.addConstraint(Sketcher.Constraint('Equal', 6, 5))

        sk.delConstraint(25)

        rc = sk.solve()
        #		print "ergebnis solve d_",rc

        #	for i in range(9,27):
        #		sk.setVirtualSpace(i, True)

        rc = sk.solve()
        #		print "ergebnis solve e_",rc

        sk.toggleDriving(b2x)
        rc = sk.solve()
        #		print "ergebnis solve Za_",rc

        sk.toggleDriving(b2x)
        rc = sk.solve()
        #		print "ergebnis solve Zb_",rc

        a = App.ActiveDocument.recompute()
        tb = time.time()
        print('\nrecreate sketch time', round(tb - ta, 3))
        if rc == 0:
            App.Console.PrintWarning(" new and success step:" + str(obj.step))
Example #20
0
    def execute(self, selfobj):
        """ Doing a recomputation.
        """
        m_properties_list = ["Distance",
                             'AlongEdge',
                             'Edge',
                             'Point'
                             ]
        for m_property in m_properties_list:
            if m_property not in selfobj.PropertiesList:
                return

        if M_DEBUG:
            print("running AlongLinePoint.execute !")

        # To be compatible with previous version > 2019
        if 'Parametric' in selfobj.PropertiesList:
            # Create the object the first time regardless
            # the parametric behavior
            if selfobj.Parametric == 'Not' and self.created:
                return
            if selfobj.Parametric == 'Interactive' and self.created:
                return

        if selfobj.AlongEdge is None:
            return

        if selfobj.Edge is None and selfobj.Point is None:
            return

        try:
            vector_point = None
            m_distance = selfobj.Distance

            # m_n1 = eval(selfobj.AlongEdge[1][0].lstrip('Edge'))
            m_n1 = re.sub('[^0-9]', '', selfobj.AlongEdge[1][0])
            m_n1 = int(m_n1)

            if selfobj.Edge is not None:
                # m_n2 = eval(selfobj.Edge[1][0].lstrip('Edge'))
                m_n2 = re.sub('[^0-9]', '', selfobj.Edge[1][0])
                m_n2 = int(m_n2)
            else:
                if selfobj.Point != selfobj.AlongEdge:
                    # m_n3 = eval(selfobj.Point[1][0].lstrip('Vertex'))
                    m_n3 = re.sub('[^0-9]', '', selfobj.Point[1][0])
                else:
                    # m_n3 = eval(selfobj.Point[1][0].lstrip('Edge'))
                    m_n3 = re.sub('[^0-9]', '', selfobj.Point[1][0])
                m_n3 = int(m_n3)

            if M_DEBUG:
                print_msg("m_n1 = " + str(m_n1))
                if selfobj.Edge is not None:
                    print_msg("m_n2 = " + str(m_n2))
                else:
                    print_msg("m_n3 = " + str(m_n3))
                print_msg("m_distance = " + str(m_distance))

            m_alongedge = selfobj.AlongEdge[0].Shape.Edges[m_n1 - 1]
            if selfobj.Edge is not None:
                m_edge = selfobj.Edge[0].Shape.Edges[m_n2 - 1]
            else:
                m_point = selfobj.Point[0].Shape.Vertexes[m_n3 - 1].Point

            vector_a = m_alongedge.valueAt(0.0)
            vector_b = m_alongedge.valueAt(m_alongedge.Length)

            if isEqualVectors(vector_a, vector_b):
                return

            if selfobj.Edge is not None:
                m_dist = m_alongedge.distToShape(m_edge)
                vector_c = m_dist[1][0][0]
            else:
                vector_c = m_point

            # Calculate intersection Point
            vector_t, _, _ = intersectPerpendicularLine(vector_a,
                                                        vector_b,
                                                        vector_c,)
            if M_DEBUG:
                print_msg("m_alongedge = " + str(m_alongedge))
                if selfobj.Edge is not None:
                    print_msg("m_edge = " + str(m_edge))
                else:
                    print_msg("m_point = " + str(m_point))
                print_msg("vector_a = " + str(vector_a))
                print_msg("vector_b = " + str(vector_b))
                print_msg("vector_c = " + str(vector_c))
                print_msg("vector_t = " + str(vector_t))

            vector_translate = (vector_b - vector_a)
            if m_distance != 0.0:
                vector_translate = vector_translate.normalize() * m_distance
                vector_point = vector_t + vector_translate
            else:
                vector_point = vector_t

            if vector_point is not None:
                point = Part.Point(vector_point)
                selfobj.Shape = point.toShape()
                propertiesPoint(selfobj.Label, self.color)
                selfobj.X = float(vector_point.x)
                selfobj.Y = float(vector_point.y)
                selfobj.Z = float(vector_point.z)
                # To be compatible with previous version 2018
                if 'Parametric' in selfobj.PropertiesList:
                    self.created = True
        except AttributeError as err:
            print("AttributeError" + str(err))
        except Exception as err:
            printError_msg(err.args[0], title=M_MACRO)
Example #21
0
def make_sketch(objects_list,
                autoconstraints=False,
                addTo=None,
                delete=False,
                name="Sketch",
                radiusPrecision=-1,
                tol=1e-3):
    """makeSketch(objects_list,[autoconstraints],[addTo],[delete],
                  [name],[radiusPrecision],[tol])

    Makes a Sketch objects_list with the given Draft objects.

    Parameters
    ----------
    objects_list: can be single or list of objects of Draft type objects,
        Part::Feature, Part.Shape, or mix of them.

    autoconstraints(False): if True, constraints will be automatically added to
        wire nodes, rectangles and circles.

    addTo(None) : if set to an existing sketch, geometry will be added to it
        instead of creating a new one.

    delete(False): if True, the original object will be deleted.
        If set to a string 'all' the object and all its linked object will be
        deleted.

    name('Sketch'): the name for the new sketch object.

    radiusPrecision(-1): If <0, disable radius constraint. If =0, add individual
        radius constraint. If >0, the radius will be rounded according to this
        precision, and 'Equal' constraint will be added to curve with equal
        radius within precision.

    tol(1e-3): Tolerance used to check if the shapes are planar and coplanar.
        Consider change to tol=-1 for a more accurate analysis.
    """

    if not App.ActiveDocument:
        App.Console.PrintError("No active document. Aborting\n")
        return

    import Part
    from Sketcher import Constraint
    import Sketcher

    start_point = 1
    end_point = 2
    middle_point = 3
    deletable = None

    if App.GuiUp:
        v_dir = gui_utils.get_3d_view().getViewDirection()
    else:
        v_dir = App.Base.Vector(0, 0, -1)

    # lists to accumulate shapes with defined normal and undefined normal
    shape_norm_yes = list()
    shape_norm_no = list()

    if not isinstance(objects_list, (list, tuple)):
        objects_list = [objects_list]

    for obj in objects_list:
        if isinstance(obj, Part.Shape):
            shape = obj
        elif not hasattr(obj, 'Shape'):
            App.Console.PrintError(translate("draft", "No shape found") + "\n")
            return None
        else:
            shape = obj.Shape

        if not DraftGeomUtils.is_planar(shape, tol):
            App.Console.PrintError(
                translate("draft", "All Shapes must be planar") + "\n")
            return None

        if DraftGeomUtils.get_normal(shape, tol):
            shape_norm_yes.append(shape)
        else:
            shape_norm_no.append(shape)

    shapes_list = shape_norm_yes + shape_norm_no

    # test if all shapes are coplanar
    if len(shape_norm_yes) >= 1:
        for shape in shapes_list[1:]:
            if not DraftGeomUtils.are_coplanar(shapes_list[0], shape, tol):
                App.Console.PrintError(
                    translate("draft", "All Shapes must be coplanar") + "\n")
                return None
        # define sketch normal
        normal = DraftGeomUtils.get_normal(shapes_list[0], tol)

    else:
        # suppose all geometries are straight lines or points
        points = [
            vertex.Point for shape in shapes_list for vertex in shape.Vertexes
        ]
        if len(points) >= 2:
            poly = Part.makePolygon(points)
            if not DraftGeomUtils.is_planar(poly, tol):
                App.Console.PrintError(
                    translate("draft", "All Shapes must be coplanar") + "\n")
                return None
            normal = DraftGeomUtils.get_normal(poly, tol)
            if not normal:
                # all points aligned
                poly_dir = poly.Edges[0].Curve.Direction
                normal = (v_dir - v_dir.dot(poly_dir) * poly_dir).normalize()
                normal = normal.negative()
        else:
            # only one point
            normal = v_dir.negative()

    if addTo:
        nobj = addTo
    else:
        nobj = App.ActiveDocument.addObject("Sketcher::SketchObject", name)
        deletable = nobj
        if App.GuiUp:
            nobj.ViewObject.Autoconstraints = False

    # Collect constraints and add in one go to improve performance
    constraints = []
    radiuses = {}

    def addRadiusConstraint(edge):
        try:
            if radiusPrecision < 0:
                return
            if radiusPrecision == 0:
                constraints.append(
                    Constraint('Radius', nobj.GeometryCount - 1,
                               edge.Curve.Radius))
                return
            r = round(edge.Curve.Radius, radiusPrecision)
            constraints.append(
                Constraint('Equal', radiuses[r], nobj.GeometryCount - 1))
        except KeyError:
            radiuses[r] = nobj.GeometryCount - 1
            constraints.append(Constraint('Radius', nobj.GeometryCount - 1, r))
        except AttributeError:
            pass

    def convertBezier(edge):
        if DraftGeomUtils.geomType(edge) == "BezierCurve":
            return (edge.Curve.toBSpline(edge.FirstParameter,
                                         edge.LastParameter).toShape())
        else:
            return (edge)

    axis = App.Vector(0, 0, 1).cross(normal)
    angle = DraftVecUtils.angle(normal, App.Vector(0, 0, 1)) * App.Units.Radian
    rotation = App.Rotation(axis, angle)

    for obj in objects_list:
        ok = False
        tp = utils.get_type(obj)
        if tp in ["Circle", "Ellipse"]:
            if obj.Shape.Edges:
                edge = obj.Shape.Edges[0]
                if len(edge.Vertexes) == 1:
                    newedge = DraftGeomUtils.orientEdge(edge, normal)
                    nobj.addGeometry(newedge)
                else:
                    # make new ArcOfCircle
                    circle = DraftGeomUtils.orientEdge(edge, normal)
                    first = math.radians(obj.FirstAngle)
                    last = math.radians(obj.LastAngle)
                    arc = Part.ArcOfCircle(circle, first, last)
                    nobj.addGeometry(arc)
                addRadiusConstraint(edge)
                ok = True
        elif tp == "Rectangle":
            if obj.FilletRadius.Value == 0:
                for edge in obj.Shape.Edges:
                    nobj.addGeometry(DraftGeomUtils.orientEdge(edge, normal))
                # TODO: the previous implementation for autoconstraints fails in front
                # and side view. So the autoconstraints for wires is used. This need
                # more checking
                if autoconstraints:
                    last = nobj.GeometryCount
                    segs = list(range(last - len(obj.Shape.Edges), last - 1))
                    for seg in segs:
                        constraints.append(
                            Constraint("Coincident", seg, end_point, seg + 1,
                                       start_point))
                        if DraftGeomUtils.isAligned(nobj.Geometry[seg], "x"):
                            constraints.append(Constraint("Vertical", seg))
                        elif DraftGeomUtils.isAligned(nobj.Geometry[seg], "y"):
                            constraints.append(Constraint("Horizontal", seg))
                    constraints.append(
                        Constraint("Coincident", last - 1, end_point, segs[0],
                                   start_point))
                ok = True
                # if autoconstraints:
                #     last = nobj.GeometryCount - 1
                #     segs = [last-3,last-2,last-1,last]
                #     if obj.Placement.Rotation.Q == (0,0,0,1):
                #         constraints.append(Constraint("Coincident",last-3,end_point,last-2,start_point))
                #         constraints.append(Constraint("Coincident",last-2,end_point,last-1,start_point))
                #         constraints.append(Constraint("Coincident",last-1,end_point,last,start_point))
                #         constraints.append(Constraint("Coincident",last,end_point,last-3,start_point))
                #     constraints.append(Constraint("Horizontal",last-3))
                #     constraints.append(Constraint("Vertical",last-2))
                #     constraints.append(Constraint("Horizontal",last-1))
                #     constraints.append(Constraint("Vertical",last))
                # ok = True
        elif tp in ["Wire", "Polygon"]:
            if obj.FilletRadius.Value == 0:
                closed = False
                if tp == "Polygon":
                    closed = True
                elif hasattr(obj, "Closed"):
                    closed = obj.Closed

                if obj.Shape.Edges:
                    for edge in obj.Shape.Edges:
                        edge = DraftGeomUtils.orientEdge(edge, normal)
                        nobj.addGeometry(edge)
                    if autoconstraints:
                        last = nobj.GeometryCount
                        segs = list(
                            range(last - len(obj.Shape.Edges), last - 1))
                        for seg in segs:
                            constraints.append(
                                Constraint("Coincident", seg, end_point,
                                           seg + 1, start_point))
                            if DraftGeomUtils.isAligned(
                                    nobj.Geometry[seg], "x"):
                                constraints.append(Constraint("Vertical", seg))
                            elif DraftGeomUtils.isAligned(
                                    nobj.Geometry[seg], "y"):
                                constraints.append(
                                    Constraint("Horizontal", seg))
                        if closed:
                            constraints.append(
                                Constraint("Coincident", last - 1, end_point,
                                           segs[0], start_point))
                    ok = True

        elif tp == "BSpline":
            if obj.Shape.Edges:
                edge = DraftGeomUtils.orientEdge(obj.Shape.Edges[0], normal)
                nobj.addGeometry(edge)
                nobj.exposeInternalGeometry(nobj.GeometryCount - 1)
                ok = True

        elif tp == "BezCurve":
            if obj.Shape.Edges:
                for piece in obj.Shape.Edges:
                    bez = piece.Curve
                    bsp = bez.toBSpline(bez.FirstParameter,
                                        bez.LastParameter).toShape()
                    edge = DraftGeomUtils.orientEdge(bsp.Edges[0], normal)
                    nobj.addGeometry(edge)
                    nobj.exposeInternalGeometry(nobj.GeometryCount - 1)
                ok = True
                # TODO: set coincident constraint for vertexes in multi-edge bezier curve

        elif tp == "Point":
            shape = obj.Shape.copy()
            if angle:
                shape.rotate(App.Base.Vector(0, 0, 0), axis, -1 * angle)
            point = Part.Point(shape.Point)
            nobj.addGeometry(point)
            ok = True

        elif tp == 'Shape' or hasattr(obj, 'Shape'):
            shape = obj if tp == 'Shape' else obj.Shape
            if not shape.Wires:
                for e in shape.Edges:
                    # unconnected edges
                    newedge = convertBezier(e)
                    nobj.addGeometry(
                        DraftGeomUtils.orientEdge(newedge,
                                                  normal,
                                                  make_arc=True))
                    addRadiusConstraint(newedge)

            if autoconstraints:
                for wire in shape.Wires:
                    last_count = nobj.GeometryCount
                    edges = wire.OrderedEdges
                    for edge in edges:
                        newedge = convertBezier(edge)
                        nobj.addGeometry(
                            DraftGeomUtils.orientEdge(newedge,
                                                      normal,
                                                      make_arc=True))
                        addRadiusConstraint(newedge)
                    for i, g in enumerate(nobj.Geometry[last_count:]):
                        if edges[i].Closed:
                            continue
                        seg = last_count + i

                        if DraftGeomUtils.isAligned(g, "x"):
                            constraints.append(Constraint("Vertical", seg))
                        elif DraftGeomUtils.isAligned(g, "y"):
                            constraints.append(Constraint("Horizontal", seg))

                        if seg == nobj.GeometryCount - 1:
                            if not wire.isClosed():
                                break
                            g2 = nobj.Geometry[last_count]
                            seg2 = last_count
                        else:
                            seg2 = seg + 1
                            g2 = nobj.Geometry[seg2]

                        end1 = g.value(g.LastParameter)
                        start2 = g2.value(g2.FirstParameter)
                        if DraftVecUtils.equals(end1, start2):
                            constraints.append(
                                Constraint("Coincident", seg, end_point, seg2,
                                           start_point))
                            continue
                        end2 = g2.value(g2.LastParameter)
                        start1 = g.value(g.FirstParameter)
                        if DraftVecUtils.equals(end2, start1):
                            constraints.append(
                                Constraint("Coincident", seg, start_point,
                                           seg2, end_point))
                        elif DraftVecUtils.equals(start1, start2):
                            constraints.append(
                                Constraint("Coincident", seg, start_point,
                                           seg2, start_point))
                        elif DraftVecUtils.equals(end1, end2):
                            constraints.append(
                                Constraint("Coincident", seg, end_point, seg2,
                                           end_point))
            else:
                for wire in shape.Wires:
                    for edge in wire.OrderedEdges:
                        newedge = convertBezier(edge)
                        nobj.addGeometry(
                            DraftGeomUtils.orientEdge(newedge,
                                                      normal,
                                                      make_arc=True))
            ok = True
        gui_utils.format_object(nobj, obj)
        if ok and delete and hasattr(obj, 'Shape'):
            doc = obj.Document

            def delObj(obj):
                if obj.InList:
                    App.Console.PrintWarning(
                        translate(
                            "draft", "Cannot delete object {} with dependency".
                            format(obj.Label)) + "\n")
                else:
                    doc.removeObject(obj.Name)

            try:
                if delete == 'all':
                    objs = [obj]
                    while objs:
                        obj = objs[0]
                        objs = objs[1:] + obj.OutList
                        delObj(obj)
                else:
                    delObj(obj)
            except Exception as ex:
                App.Console.PrintWarning(
                    translate(
                        "draft", "Failed to delete object {}: {}".format(
                            obj.Label, ex)) + "\n")

    nobj.Placement.Rotation = rotation
    nobj.addConstraint(constraints)

    return nobj
Example #22
0
	def runmode3(self,fp):

		fn=fp.source.Shape.Faces[fp.faceNumber-1]
		sf=fn.toNurbs().Face1.Surface

		if fp.ref == None: return

		(sob,subo)=fp.ref

		if len(subo)==1:
			subobj=getattr(sob.Shape,subo[0])
			try:
				p=subobj.CenterOfMass
			except:
				p=subobj.Point
		else:
			p=sob.Shape.CenterOfMass



		if fp.modeRef=='vertical':

			line=App.ActiveDocument.addObject("Part::Line","_tmp_Line")
			line.X1,line.Y1,line.Z1=p.x,p.y,10**4
			line.X2,line.Y2,line.Z2=p.x,p.y,-10**4

			a2=App.ActiveDocument.BePlane.Shape
			a3=line.Shape.section(a2.Face1)
			p2=a3.Vertexes[0].Point
			App.ActiveDocument.removeObject(line.Name)

		else:
			p2=sf.value(*sf.parameter(p))

		l=(p2-p).Length
		col=[]

		if fp.mode=="Circles1":
			for i in range(10):
				aa=Part.Sphere()
				aa.Radius=l+(i)*0.2*100
				a2=aa.toShape()
				a2.Placement.Base=p
				a3=fn.section(a2.Face1)
				col += [a3]

		if fp.mode=="Circles2":

			aa=App.ActiveDocument.addObject("Part::Cylinder","Cylinder")

			for i in range(10):	
				aa.Height=10000
				aa.Radius=0.2*i*100
				aa.Placement.Base=p
				aa.Placement.Rotation=FreeCAD.Rotation(FreeCAD.Vector(0,0,1),p2-p)
				fc=aa.Shape.Face1
				a3=fn.section(fc)
				col += [a3]

			App.ActiveDocument.removeObject(aa.Name)

		if len(col)==0:
			fp.Shape=Part.Point().toShape()
		else:
			fp.Shape=Part.Compound(col)

		(u,v) = sf.parameter(p2)
		[umi,uma,vmi,vma]=fn.toNurbs().Face1.ParameterRange
		fp.u=(u-umi)/(uma-umi)*fp.scale
		fp.v=(v-vmi)/(vma-vmi)*fp.scale
    def execute(self, selfobj):
        """ Doing a recomputation.
        """
        m_properties_list = [
            'Point',
            "Plane",
            "At",
            # "Show",
        ]
        for m_property in m_properties_list:
            if m_property not in selfobj.PropertiesList:
                return

        if M_DEBUG:
            print("running ProjectedPoint.execute !")

        # To be compatible with previous version > 2019
        if 'Parametric' in selfobj.PropertiesList:
            # Create the object the first time regardless
            # the parametric behavior
            if selfobj.Parametric == 'Not' and self.created:
                return
            if selfobj.Parametric == 'Interactive' and self.created:
                return

        try:
            vector_point = None
            if selfobj.Point is not None:
                # n = eval(selfobj.Point[1][0].lstrip('Vertex'))
                m_n = re.sub('[^0-9]', '', selfobj.Point1[1][0])
                m_n = int(m_n)
                if M_DEBUG:
                    print_msg(str(selfobj.Point1))
                    print_msg("m_n = " + str(m_n))

                point1 = selfobj.Point[0].Shape.Vertexes[m_n - 1].Point
                x = point1.x
                y = point1.y
                z = point1.z

                if selfobj.Plane is None:
                    # No selected plane so projection on one of MAIN planes
                    if selfobj.At == "XY plane":
                        vector_point = Base.Vector(x, y, 0.0)
                    elif selfobj.At == "YZ plane":
                        vector_point = Base.Vector(0.0, y, z)
                    elif selfobj.At == "XZ plane":
                        vector_point = Base.Vector(x, 0.0, z)
                    else:
                        printError_msg("Not valid plane option!",
                                       title=M_MACRO)
                else:
                    # A selected plane
                    pass


#                     p=App.Vector(1,1,1)
#                     p.projectToPlane(App.Vector(0,0,0),App.Vector(1,0,1))
# projectToPlane parameters are (point on plane,normal direction)

            if vector_point is not None:
                point = Part.Point(vector_point)
                selfobj.Shape = point.toShape()
                propertiesPoint(selfobj.Label, self.color)
                selfobj.X = float(vector_point.x)
                selfobj.Y = float(vector_point.y)
                selfobj.Z = float(vector_point.z)

                if M_DEBUG:
                    print("M_PROJ_LINE = " + str(M_PROJ_LINE))
                    print("M_NUMBER_SYM_POINTS = " + str(M_NUMBER_SYM_POINTS))

                if M_PROJ_LINE and not self.created:
                    point_1 = selfobj.Point
                    object_1 = selfobj
                    twoPL.buildFromOnePointAndOneObject(
                        point_1, object_1, M_GROUP)

                if M_NUMBER_SYM_POINTS > 0 and not self.created:
                    for m_i in range(M_NUMBER_SYM_POINTS):
                        index = m_i + 2
                        aLP.buildFromTwoPoints(point1, vector_point, index,
                                               object_1, M_GROUP)

                # To be compatible with previous version 2018
                if 'Parametric' in selfobj.PropertiesList:
                    self.created = True
        except AttributeError as err:
            print("AttributeError" + str(err))
        except Exception as err:
            printError_msg(err.args[0], title=M_MACRO)