Skip to content

Instantly share code, notes, and snippets.

@kwahoo2
Created February 4, 2023 12:54
Show Gist options
  • Save kwahoo2/1b304ee054395f1e7ec0422418af896f to your computer and use it in GitHub Desktop.
Save kwahoo2/1b304ee054395f1e7ec0422418af896f to your computer and use it in GitHub Desktop.
This script animates "Box" attached to an curve with MapPathParameter # It can be used for animation of indexing conveyor (start/stop)
# This script animates "Box" attached to an curve with MapPathParameter
# It can be used for animation of indexing conveyor (start/stop)
import FreeCAD as App, FreeCADGui as Gui, Part, time
from PySide2 import QtGui,QtCore
class Animation(object):
def __init__(self):
App.Console.PrintMessage('Animation has started\n')
App.ActiveDocument.recompute()
self.timer = QtCore.QTimer()
QtCore.QObject.connect(self.timer, QtCore.SIGNAL("timeout()"), self.my_update)
self.step_time = 100 # step every 0.05s (50 ms)
self.wait_time = 1000 # wait 1s on every stop step
self.timer.start(self.step_time)
self.val = 0 # start
self.step = 10 # step value
self.stop_step = 70 # pause evey 70, distance beetween "conveyor" stop position
self.end = 2100 # end value, "conveyor" lenght
def my_update(self):
valf = 1.0 / self.end * self.val # MapPathParameter can vary from 0 to 1
App.ActiveDocument.getObject('Box').MapPathParameter = valf #move the box on the path
self.val = self.val + self.step
App.ActiveDocument.recompute()
if (self.val % self.stop_step):
self.timer.start(self.step_time)
else:
self.timer.start(self.wait_time)
if self.val > self.end:
# self.timer.stop() #uncomment to stop animation after reaching end value
self.val = 0.0
def stop(self):
self.timer.stop()
App.Console.PrintMessage('Animation stopped\n')
animation = Animation()
#to stop type animation.stop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment