Macro crank simul/fr: Difference between revisions

From FreeCAD Documentation
(Created page with "Macro crank simul")
 
(Created page with "{{Macro/fr|Icon=Text-x-python|Name=Crank Simul|Name/fr=Crank Simul|Description=Crank simulation.|Author=kwahoo}}")
Line 1: Line 1:
{{Macro|Icon=Text-x-python|Name=Crank Simul|Description=Crank simulation.|Author=kwahoo}}
{{Macro/fr|Icon=Text-x-python|Name=Crank Simul|Name/fr=Crank Simul|Description=Crank simulation.|Author=kwahoo}}


My simple animation uses sketch and sketcher solver to determine piston position and conrod position/rotation.
My simple animation uses sketch and sketcher solver to determine piston position and conrod position/rotation.

Revision as of 19:19, 1 January 2015

File:Text-x-python Crank Simul

Description
Crank simulation.

Auteur: kwahoo
Auteur
kwahoo
Téléchargement
None
Liens
Version Macro
1.0
Dernière modification
None
Version(s) FreeCAD
None
Raccourci clavier
None
Voir aussi
None

My simple animation uses sketch and sketcher solver to determine piston position and conrod position/rotation.

Uses

To test the animation:

Download the files copy the code in the Python console FreeCAD.

1. Open the attached file

To stop animation type :

animation.stop()

The File

crank_simul.fcstd

Script

crank_simul.FCMacro

import FreeCAD as App, FreeCADGui as Gui, Part, time, sys, math, Draft, DraftGeomUtils
from PyQt4 import QtGui,QtCore

class Animation(object):
    def __init__(self):
        App.Console.PrintMessage('init')

        App.ActiveDocument.recompute()

        self.timer = QtCore.QTimer()
        QtCore.QObject.connect(self.timer, QtCore.SIGNAL("timeout()"), self.my_update)
        self.timer.start(50)

        self.an = 0.1

    def my_update(self):
        string = '{0}'.format(self.an)
        self.an = self.an + 0.01 if self.an < (2 * math.pi) else 0.0

        angle = math.degrees(self.an)
        App.ActiveDocument.Sketch.setDatum(5,App.Units.Quantity(str(angle)+' deg'))
        App.ActiveDocument.recompute()
        p1 = App.ActiveDocument.Sketch.Shape.Vertexes[0].Point
        p2 = App.ActiveDocument.Sketch.Shape.Vertexes[1].Point
        conrodangle = math.degrees(Draft.DraftVecUtils.angle(App.Vector(1,0,0),(p1-p2))) - 90
        App.ActiveDocument.getObject("Cylinder").Placement = App.Placement(p1,App.Rotation(App.Vector(1,0,0),-90))
        App.ActiveDocument.getObject("Sketch001").Placement = App.Placement(p1,App.Rotation(App.Vector(0,0,1),conrodangle))

    def stop(self):
        self.timer.stop()
         

animation = Animation()

Link

The page discussion Inline-four engine animation

The blog freecad-tutorial.blogspot

Other languages: