Macro Spring: Difference between revisions

From FreeCAD Documentation
(add "Gui.updateGui()" of the code)
m (upgrade code)
 
(17 intermediate revisions by 5 users not shown)
Line 1: Line 1:
<languages/>
<translate>
<translate>
<!--T:1-->
<!--T:1-->
{{Macro
{{Macro|Icon=Text-x-python|Name=Spring Simul|Description=Spring simulation.|Author=Mario52}}
|Name=Spring Simul
|Icon=Macro_Spring.png
|Description=Simulates the compression and decompression of a spring.
|Author=Mario52
|Version=1.0
|Date=2014-09-29
|FCVersion=All
|Download=The file [http://forum.freecadweb.org/download/file.php?id=7679 Spring.FCStd]<br />[https://www.freecadweb.org/wiki/images/2/2d/Macro_Spring.png ToolBar Icon]
}}


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


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


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


<!--T:5-->
<!--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 or run the macro whit [[File:Macro-execute.svg]]
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 then press {{KEY|F6}} (debug macro) to run the macro or run the macro with [[File:Std_DlgMacroExecuteDirect.svg]]


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


</translate>
===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]
<translate>

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


</translate>
</translate>
ToolBar Icon [[Image:Macro_Spring.png]]
Spring.FCMacro

'''Spring.FCMacro'''


{{MacroCode|code=
<syntaxhighlight>
import FreeCAD, FreeCADGui, Draft, Part
import FreeCAD, FreeCADGui, Draft, Part
from FreeCAD import Base
from FreeCAD import Base
import time
import time


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


pas = 1
pas = 1
Line 55: Line 68:
App.Console.PrintMessage(str(ii2)+" " + str(ii)+" " + str(i)+" " + str(pas) +"\n")
App.Console.PrintMessage(str(ii2)+" " + str(ii)+" " + str(i)+" " + str(pas) +"\n")
Gui.updateGui()
Gui.updateGui()
time.sleep(0.1) # modify the time here
time.sleep(0.1)
#FreeCAD.getDocument("Spring").getObject("Helix001").Pitch = iib
}}
#FreeCAD.getDocument("Spring").getObject("Helix001").Height = ib


</syntaxhighlight>
<translate>
<translate>

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

Latest revision as of 09:23, 16 June 2020

Other languages:

Spring Simul

Description
Simulates the compression and decompression of a spring.

Macro version: 1.0
Last modified: 2014-09-29
FreeCAD version: All
Download: The file Spring.FCStd
ToolBar Icon
Author: Mario52
Author
Mario52
Download
The file Spring.FCStd
ToolBar Icon
Links
Macro Version
1.0
Date last modified
2014-09-29
FreeCAD Version(s)
All
Default shortcut
None
See also
None

Description

Simulates the compression and decompression 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 then press F6 (debug macro) to run the macro or run the macro with

The File

Spring.FCStd

Script

ToolBar Icon

Spring.FCMacro

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

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

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")
    Gui.updateGui()
    time.sleep(0.1)


Link

The forum discussion page: scripting animations