Macro Spring: Difference between revisions
No edit summary |
m (upgrade code) |
||
Line 45: | Line 45: | ||
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 68: | 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) |
time.sleep(0.1) |
||
⚫ | |||
#FreeCAD.getDocument("Spring").getObject("Helix001").Pitch = iib |
|||
#FreeCAD.getDocument("Spring").getObject("Helix001").Height = ib |
|||
}} |
}} |
||
'''Code for FreeCAD version 0.15''' |
|||
'''Spring_FC-0-15.FCMacro''' |
|||
{{MacroCode|code= |
|||
# For FreeCAD 0.15 |
|||
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: |
|||
print pas |
|||
if ii > iib-1: |
|||
pas = 1 |
|||
else: |
|||
ii += 1 |
|||
i = (ii * 10) |
|||
print i," ",ii," else1" |
|||
⚫ | |||
print pas |
|||
if ii < 2: |
|||
pas = 0 |
|||
else: |
|||
ii -= 1 |
|||
i = (ii * 10) |
|||
print i," ",ii," else2" |
|||
FreeCAD.getDocument("Spring").getObject("Helix001").Pitch.Value = ii |
|||
FreeCAD.getDocument("Spring").getObject("Helix001").Height.Value = i |
|||
# App.Console.PrintMessage(str(ii2)+" " + str(ii)+" " + str(i)+" " + str(pas) +"\n") |
|||
Gui.updateGui() |
|||
time.sleep(0.1) # modify the time here |
|||
#FreeCAD.getDocument("Spring").getObject("Helix001").Pitch.Value = iib |
|||
#FreeCAD.getDocument("Spring").getObject("Helix001").Height.Value = ib |
|||
}} |
|||
<translate> |
<translate> |
||
Latest revision as of 09:23, 16 June 2020
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 |
Macros recipes How to install macros How to customize toolbars |
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
Script
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