Macro Spring: Difference between revisions

From FreeCAD Documentation
No edit summary
(Marked this version for translation)
Line 1: Line 1:
<translate>
<translate>
<!--T:1-->
{{Macro|Icon=Text-x-python|Name=Spring Simul|Description=Spring simulation.|Author=Mario52}}
{{Macro|Icon=Text-x-python|Name=Spring Simul|Description=Spring simulation.|Author=Mario52}}


<!--T:2-->
Simulates the compression and relaxation of a spring.
Simulates the compression and relaxation of a spring.


<!--T:3-->
[[File:Spring_00.gif|left]]{{clear}}
[[File:Spring_00.gif|left]]{{clear}}


===Uses===
===Uses=== <!--T:4-->


<!--T:5-->
Open the 2 files below (Spring.FCMacro and Spring.FCStd) in FreeCAD with 2 screens (Menu: Windows > Tile) and click in the window and the macro and click F6 (debug macro) to run the macro
Open the 2 files below (Spring.FCMacro and Spring.FCStd) in FreeCAD with 2 screens (Menu: Windows > Tile) and click in the window and the macro and click F6 (debug macro) to run the macro


<!--T:6-->
[[File:Spring_02.png|left|300px]]{{clear}}
[[File:Spring_02.png|left|300px]]{{clear}}


===The File===
===The File=== <!--T:7-->


<!--T:8-->
[http://forum.freecadweb.org/download/file.php?id=7679 Spring.FCStd]
[http://forum.freecadweb.org/download/file.php?id=7679 Spring.FCStd]


===Script===
===Script=== <!--T:9-->


</translate>
</translate>
Line 54: Line 60:
</syntaxhighlight>
</syntaxhighlight>
<translate>
<translate>
===Link===
===Link=== <!--T:10-->
The discussion page: [http://forum.freecadweb.org/viewtopic.php?f=22&t=7449#p62193 scripting animations]
The discussion page: [http://forum.freecadweb.org/viewtopic.php?f=22&t=7449#p62193 scripting animations]
</translate>
</translate>

Revision as of 21:44, 29 September 2014

File:Text-x-python Spring Simul

Description
Spring simulation.

Author: Mario52
Author
Mario52
Download
None
Links
Macro Version
1.0
Date last modified
None
FreeCAD Version(s)
None
Default shortcut
None
See also
None

Simulates the compression and relaxation of a spring.

Uses

Open the 2 files below (Spring.FCMacro and Spring.FCStd) in FreeCAD with 2 screens (Menu: Windows > Tile) and click in the window and the macro and click F6 (debug macro) to run the macro

The File

Spring.FCStd

Script

Spring.FCMacro

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

Link

The discussion page: scripting animations

Other languages: