Kunda1 wrote: ↑Tue Nov 19, 2019 12:52 pmReason: users aren't aware it's possible to animate assemblies. See https://forum.freecadweb.org/viewtopic. ... 11#p348308
The script is pretty simpledcapeletti wrote: ↑Mon May 20, 2019 11:37 pmI made an engine and assembly with some parts and a script to run the animation. You can see the gif and the repository of the project.
https://gitlab.com/dcapeletti/ejercicio ... A2Plus.gif
https://gitlab.com/dcapeletti/ejercicio ... %20tiempos
Code: Select all
from a2p_solversystem import SolverSystem import time import FreeCADGui class Motor(): def __init__(self): self.angulo = 0 self.solver = SolverSystem() def iniciar_animacion(self): for val in range(0, 90): self.angulo = val*4 FreeCAD.ActiveDocument.b_Ciguenal_001_.Placement = App.Placement(App.Vector(0,0,0),App.Rotation(App.Vector(0,0,1),self.angulo)) self.solver.solveSystem(App.ActiveDocument) FreeCADGui.updateGui() time.sleep(0.01) def stop(self): self.angulo = 0 FreeCAD.ActiveDocument.b_Ciguenal_001_.Placement = App.Placement(App.Vector(0,0,0),App.Rotation(App.Vector(0,0,1),0)) self.solver.solveSystem(App.ActiveDocument) motor = Motor() motor.iniciar_animacion() # It stops after a while or can be stopped with a method as well motor.stop()
These are the steps
- It creates a class to encapsulate everything. In this class it creates an instance of A2plus's SolverSystem.
- Then a method is defined to cycle a few times. In this cycle the placement of the body is changed; the change could be in the base placement, in the rotation, or both. In this example it's the angle of rotation the only thing that changes.
- After the change in placement, it solves the system again with solver.solveSytem(App.ActiveDocument).
- Then it updates the graphical interface with FreeCADGui.updateGui()
- Finally, to finish the cycle it makes a tiny pause of 0.01 seconds. This can be changed to control the rate of update of the frames in the animation.
- The animation will stop itself after the number of cycles is completed. However, a method is defined to stop the animation at any time, by resetting the angle of rotation, and solving the system again only once.