scripting animations?

Need help, or want to share a macro? Post here!
roegel
Posts: 73
Joined: Tue Aug 12, 2014 7:21 pm

scripting animations?

Postby roegel » Sat Aug 23, 2014 2:56 pm

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
Site Admin
Posts: 16841
Joined: Thu Feb 19, 2009 10:32 am

Re: scripting animations?

Postby wmayer » Sat Aug 23, 2014 3:14 pm

Hi Denis,

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

Re: scripting animations?

Postby mario52 » Wed Sep 10, 2014 3:03 pm

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

Re: scripting animations?

Postby mario52 » Wed Sep 10, 2014 6:19 pm

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 929 times
mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Topological_data_scripting, Dialog creation. My macros on Gist.github.