FreeCAD-Doc/localwiki/Macro_crank_simul-fr.html
2018-07-19 18:47:02 -05:00

126 lines
5.8 KiB
HTML
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<html><head><title>Macro crank simul/fr</title><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><link type='text/css' href='wiki.css' rel='stylesheet'></head><body><h1>Macro crank simul/fr</h1></div>
<div id="mw-content-text" lang="fr" dir="ltr" class="mw-content-ltr"><hr/><div class="mw-parser-output"><table class="fcinfobox wikitable ct" width="100%" style="float: right; width: 230px; margin-left: 10px;">
<tr>
<td class="ctTitle">
<h3><span class="mw-headline" id="Simulation_manivelle"><a href="https://www.freecadweb.org/wiki/index.php?title=File:Text-x-python.png" class="image"><img alt="Text-x-python.png" src="32px-Text-x-python.png" width="32" height="32" srcset="/wiki/images/2/2c/Text-x-python.png 1.5x" /></a> Simulation manivelle</span></h3>
</td></tr>
<tr>
<th class="ctOdd">Description
</th></tr>
<tr>
<td class="ctEven left">Simulation d'une manivelle.
</td></tr>
<tr>
<th class="ctOdd">Auteur
</th></tr>
<tr>
<td class="ctEven"><a href="https://www.freecadweb.org/wiki/index.php?title=User:Kwahoo&amp;action=edit&amp;redlink=1" class="new" title="User:Kwahoo (page does not exist)">kwahoo</a>
</td></tr>
<tr>
<th class="ctOdd">Liens
</th></tr>
<tr>
<td class="ctEven"><a href="https://www.freecadweb.org/wiki/index.php?title=Macros_recipes/fr" title="Macros recipes/fr">Recettes macros</a><br /><a href="https://www.freecadweb.org/wiki/index.php?title=How_to_install_macros/fr" title="How to install macros/fr">Comment installer une macro</a><br /><a href="https://www.freecadweb.org/wiki/index.php?title=Customize_Toolbars/fr" title="Customize Toolbars/fr">Comment ajouter une barre d'outils</a>
</td></tr>
<tr>
<th class="ctOdd">Version
</th></tr>
<tr>
<td class="ctEven macro-version">1.0
</td></tr>
<tr>
<th class="ctOdd">Date dernière modification
</th></tr>
<tr>
<td class="ctEven macro-date">2014-06-13
</td></tr>
<tr>
<th class="ctOdd">
</th></tr>
<tr>
<td class="ctToc"><br /><div id="toc" class="toc"><div class="toctitle"><h2>Contents</h2></div>
<ul>
<li class="toclevel-1"><a href="#Simulation_manivelle"><span class="tocnumber">1</span> <span class="toctext">Simulation manivelle</span></a></li>
<li class="toclevel-1 tocsection-1"><a href="#Utilisation"><span class="tocnumber">2</span> <span class="toctext">Utilisation</span></a></li>
<li class="toclevel-1 tocsection-2"><a href="#Le_fichier"><span class="tocnumber">3</span> <span class="toctext">Le fichier</span></a></li>
<li class="toclevel-1 tocsection-3"><a href="#Script"><span class="tocnumber">4</span> <span class="toctext">Script</span></a></li>
<li class="toclevel-1 tocsection-4"><a href="#Liens"><span class="tocnumber">5</span> <span class="toctext">Liens</span></a></li>
</ul>
</div>
</td></tr>
</table>
<p><br />
</p><p>Cette animation simple utilise une esquisse et le solveur afin de déterminer la position et la rotation du piston et de la bielle.
</p><p><br />
</p>
<div class="floatleft"><a href="https://www.freecadweb.org/wiki/index.php?title=File:Crank_00.gif" class="image"><img alt="Crank 00.gif" src="Crank_00.gif" width="462" height="394" /></a></div><div style="clear:both"></div>
<p><br />
</p>
<h3><span class="mw-headline" id="Utilisation">Utilisation</span></h3>
<p>Pour tester l'animation :
</p><p>Télécharger les fichiers et copier le code dans la console Python de FreeCAD.
</p><p>1. Ouvrir le fichier joint
</p><p>Pour stopper l'animation, taper dans la console :
</p>
<pre>animation.stop() </pre>
<h3><span class="mw-headline" id="Le_fichier">Le fichier</span></h3>
<p><a rel="nofollow" class="external text" href="http://forum.freecadweb.org/download/file.php?id=5954">crank_simul.fcstd</a>
</p>
<h3><span class="mw-headline" id="Script">Script</span></h3>
<p>crank_simul.FCMacro
</p>
<pre>import FreeCAD as App, FreeCADGui as Gui, Part, time, sys, math, Draft, DraftGeomUtils
from PySide 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 &lt; (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() </pre>
<h3><span class="mw-headline" id="Liens">Liens</span></h3>
<p>La discussion sur le forum (en anglais) <a rel="nofollow" class="external text" href="http://forum.freecadweb.org/viewtopic.php?f=24&amp;t=6815&amp;hilit=animation#p55092">Inline-four engine animation</a>
</p><p>Le blogue <a rel="nofollow" class="external text" href="http://freecad-tutorial.blogspot.be/">freecad-tutorial.blogspot</a>
</p>
<div style="clear:both"></div>
</div>
</div>
</div><div class="printfooter">
Online version: "<a dir="ltr" href="https://www.freecadweb.org/wiki/index.php?title=Macro_crank_simul/fr&amp;oldid=239970">http://www.freecadweb.org/wiki/index.php?title=Macro_crank_simul/fr&amp;oldid=239970</a>"</div>
<div id="catlinks" class="catlinks" data-mw="interface"></div><div class="visualClear"></div>
</div>
</div>
<div id="mw-navigation">
<h2>Navigation menu</h2>
</body></html>