scripting animations?

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
roegel
Posts: 73
Joined: Tue Aug 12, 2014 7:21 pm

scripting animations?

Post by roegel »

Hi,

I'd like to animate some object in freecad, but can this be specified in the script alone?
Is there a small example somewhere? Basically, I am just looking for some time variable,
and something that will update the view at regular intervals based on the time variable.

Thanks,

Denis
wmayer
Founder
Posts: 20243
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: scripting animations?

Post by wmayer »

Hi Denis,

have a look at this script for a basic idea: viewtopic.php?f=24&t=6815&p=55072#p55092
mario52
Veteran
Posts: 4673
Joined: Wed May 16, 2012 2:13 pm

Re: scripting animations?

Post by mario52 »

hi
here an example extremely easy.
mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Topological_data_scripting.
My macros on Gist.github here complete macros Wiki and forum.
mario52
Veteran
Posts: 4673
Joined: Wed May 16, 2012 2:13 pm

Re: scripting animations?

Post by mario52 »

hi
with the same principle, a spring
Open the 2 files (Spring.FCMacro and Spring.FCStd) in FreeCAD with 2 screens, then (Menu > Windows > tile menu) and click in the window and the macro and F6 (debug macro)

Spring.FCMacro

Code: Select all

import FreeCAD, FreeCADGui, Draft, Part
from FreeCAD import Base
import time

ii = iib = FreeCAD.getDocument("Spring").getObject("Helix001").Pitch
i = ib = FreeCAD.getDocument("Spring").getObject("Helix001").Height

pas = 1

for ii2 in range(int(60)):
    if pas == 0:
        if ii > iib-1:
            pas = 1
        else:
            ii += 1
            i = (ii * 10)
    else:
        if ii < 2:
            pas = 0
        else:
            ii -= 1
            i = (ii * 10)
   
    FreeCAD.getDocument("Spring").getObject("Helix001").Pitch = ii
    FreeCAD.getDocument("Spring").getObject("Helix001").Height = i
    App.Console.PrintMessage(str(ii2)+"  " + str(ii)+"  " + str(i)+"  " + str(pas) +"\n")
    time.sleep(0.1) # modify the time here
#FreeCAD.getDocument("Spring").getObject("Helix001").Pitch = iib
#FreeCAD.getDocument("Spring").getObject("Helix001").Height = ib
Spring.FCStd
Spring.FCStd
(9.75 KiB) Downloaded 1233 times
mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Topological_data_scripting.
My macros on Gist.github here complete macros Wiki and forum.
Post Reply