Macro FCSpring Helix Variable: Difference between revisions

From FreeCAD Documentation
mNo edit summary
No edit summary
 
(90 intermediate revisions by 7 users not shown)
Line 1: Line 1:
<languages/>
<translate>
<translate>
{{Macro|Icon=Text-x-python|Name=Macro FCSpring Helix Variable|Description=Creates a spring with helix variable.|Author=Mario52}}


<!--T:1-->
===Description===
{{Macro
This macro creates a spring with customizable, any turn may change the spring configuration can be saved in a file with the extension '''.FCSpring'''
|Name=Macro FCSpring Helix Variable
|Icon=FCSpring Helix Variable.png
|Description=This macro creates a spring with customizable, any turn may change the spring configuration can be saved in a file with the extension '''.FCSpring''' or coordinates '''.FCSpringCoor'''.<br />Are detected: Surface (Face direction), Cylinder (Radius), Ellipse (MinorRadius), Sphere (Radius), Toroid (Radius1), Plane (Direction), Line (follow the Direction ), Point (XYZ vertex position)<br />If no object is detected (not selection) the spring is created at the point XYZ 0., 0., 0.<br/>See the [https://www.freecadweb.org/wiki/Macro_FCSpring_Helix_Variable#Examples examples]<br/>
<br/>
Download [https://forum.freecadweb.org/download/file.php?id=80844 the Icons] in .zip file
|Author=Mario52
|Download=[https://wiki.freecad.org/images/6/69/FCSpring_Helix_Variable.png ToolBar Icon]
|Version=01.18c
|Date=2023/09/01
|FCVersion=0.19
}}

==Description== <!--T:63-->

<!--T:2-->
This macro creates a spring highly customizable. Any modification changing the spring configuration can be saved in a file with the extension .FCSpring or coordinates .FCSpringCoor<br />Are detected: Surface (Face direction), Cylinder (Radius), Ellipse (MinorRadius), Sphere (Radius), Toroid (Radius1), Plane (Direction), Line (follow the Direction ), Point (XYZ vertex position)<br />If no object is detected (not selection) the spring is created at the point XYZ 0., 0., 0.


</translate>
</translate>
{{Codeextralink|https://gist.githubusercontent.com/mario52a/68c81c32a0727a693d3a/raw/3f6e4df2768f36e88af4f56af669206ff0d33e0c/Macro_FCSpring_Helix_Variable.FCMacro}}
[[File:TruncateSpring00.png]]
{{clear}}
<translate>
<translate>

===Use===
</translate>
[[File:TruncateSpring00.png|400px]]
<translate>
<!--T:51-->
{{Caption|FCSpring Helix Variable}}

==Usage== <!--T:64-->

<!--T:3-->
This section is used to configuration the spring
This section is used to configuration the spring


<!--T:4-->
Schematic detail of spring configuration
Schematic detail of spring configuration


Line 18: Line 43:
{{clear}}
{{clear}}
<translate>
<translate>

=== '''Gui''' ===
==== Gui ==== <!--T:5-->

</translate>
</translate>
[[File:Macro FCSpring Helix Variable 01.png]]
[[File:Macro FCSpring Helix Variable 01.png]]
{{clear}}
{{clear}}
<translate>
<translate>

=== '''First section, spring configuration''' ===
====Configuration==== <!--T:65-->
* '''Number of coil''' : Total of coil to spring. (Default = 10)

* '''Radius of spring''' : Radius of spring. (Default = 20.0
<!--T:6-->
* '''Pitch of spring''' : Pitch of spring general (Default = 15.0)
* {{SpinBox|10 coils}} '''Number of coil''' : Total of coil to spring. Default = 10
* '''Precision of turn''' : Precision of turn the precision correspond the number of point for 1 turn the coil and is calculate : precision (number points) = (pitch / (360/precision)) (Default = 5)
* {{SpinBox|20,000 mm}} '''Radius of spring''' : Radius of spring. Default = 20.0
* {{SpinBox|15,000 mm}} '''Pitch of spring''' : Pitch of spring general. Default = 15.0
* {{SpinBox|5 ( 72 points )}} '''Precision of turn''' : Precision of turn the precision correspond the number of point for 1 turn the coil and is calculate : precision (number points) = (pitch / (360/precision)). Default = 5 (72 points)
* {{SpinBox|20,000 mm}} : Radius of large circle of the cone (check the {{CheckBox|TRUE|Spring conical}} for use)
* {{CheckBox|Spring conical}} : Give the large diameter of the cone that dimension will always be greater than the radius
* {{CheckBox|Angles}} : Check box choice for activate the function Begin and End angle of the coil unchecked by default.<br /> If the function is checked. The accuracy is automatically set "precision" is ordered {{SpinBox|1 ( 360 points )}} to 1 (360 points per turn 1 point = 1 degrees)
* {{SpinBox|0 deg}} '''Begin''' : Begin angle of the spring first coil.
* {{SpinBox|360 deg}} '''End''' : End angle of the spring last coil.


</translate>
</translate>
Line 33: Line 68:
{{clear}}
{{clear}}
<translate>
<translate>

=== '''Second section, type line''' ===
* '''BSpline''' : Type line BSpline
====Type line==== <!--T:66-->

* '''Wire''' : Type line Wire
<!--T:7-->
* {{RadioButton|TRUE|[[Image:Draft_BSpline.svg|24px]] Bspline}} '''BSpline''' : Type line BSpline.
* {{RadioButton|[[Image:Draft_Wire.svg|24px]] Wire}} '''Wire''' : Type line Wire.
* {{CheckBox|[[Image:Draft_Point.svg|24px]] Points}} '''Points''' : Check box point if the check box is activate one point is create of on each point.
* {{CheckBox|Reverse}} '''Reverse''' : Check box reverse if the check box is activate the spring changes direction

</translate>
</translate>
[[File:Macro FCSpring Helix Variable 03.png ]]
{{clear}}
<translate>


====Options==== <!--T:67-->
[[File:Macro FCSpring Helix Variable 03.png]]

<!--T:41-->
This section is displayed if on object is selected. The type object is displayed in the Text Editor

<!--T:42-->
The object can be line, 2 points, circle, wire ... one axis the length of the spring is automatically created

<!--T:43-->
Detection : Cylinder (radius), Sphere (radius), Toroid (radius) , Cone (little radius), Circle (radius), Arc (radius), Ellipse (little radius)

<!--T:44-->
* {{Button|Normal}} : If one circle is selected '''Normal''' not modify the radius of circle (Default)
** {{Button|Adapt Rad.}} : If the button {{Button|Normal}}' is pressed, the button change to {{Button|Adapt Rad.}} the spring is adapted to the detected radius (If a radius is detected )
* {{Button|Point Mouse}} : If the click mouse is on one face the spring is created on this point (Default)
** {{Button|Center Face}} : If the button {{Button|Point Mouse}} is pressed, the button change to {{Button|Center Face}}, the spring is created on the center face selected
* {{CheckBox|Position}} '''Position''' : If two object are selected (First axis, Second the spring (or other object)), this checkBox is enabled and you can modify the placement object 2 (spring) along the on object 1 (axis), if this {{CheckBox|TRUE|Position}} is checked the "Position" option is enabled for use
* {{Button|Circle}} : If three points click mouse are selected the {{Button|Circle}} button is enabled and it possible to create a circle which can serve as a base for a spring

</translate>
[[File:Macro FCSpring Helix Variable 02 1.png]]
{{clear}}
{{clear}}
<translate>
<translate>

=== Third section, coil special length ===
====Position (0)(xx)==== <!--T:68-->
* '''Numbering of coil''' : Numbering of coil to modify. (Defaut : none)

* '''Pitch of coil''' : Pitch of coil to modify. (Defaut : none)
<!--T:45-->
* {{KEY|Accept the value modified}} : Button to accept the modification after select the numbering of coil and modify the pitch of coil.
(0)(xx) : Number selection(s), length in mm of axis created x 10, equal number of points for shifting the spring of the axis
* '''Text edit''' : This window displayed all coil modified.

<!--T:46-->
* {{Button|Begin/End}} : Position the spring on begin, middle, end axis
* {{Button|Reverse Spr.}} : Reverse the spring of the axis
* {{SpinBox|0,1 mm}} : Shifting the spring with precision (0.1 mm) along its axis
* {{KEY|Reverse Count.}} : Reverse the counter ex: Begin 0 to 10.. or End 0 to 10..
* '''Slider''' : Position the spring on its axis

</translate>
</translate>
[[File:Macro FCSpring Helix Variable 02 2.png]]
{{clear}}
<translate>


====Coil special dimension==== <!--T:69-->

<!--T:8-->
* {{SpinBox|Num: 2}} '''Numbering of coil''' : Numbering of coil to modify. (Default : none)
* {{CheckBox|Smoothing}} '''Smoothing''' This checkBox discover one spinBox for determine the grade of smoothing the maximum value is the precision value -1 (this option is still at the prototype stage and the result can be satisfying or completely wrong)
* {{SpinBox|0,000 mm}} '''Pitch of coil''' : Pitch of coil to modify. (Default : none)
* {{Button|15.0 mm}} : If the button is pressed the value of the "Pitch of string" is affected of the "Pitch of coil" (This value is automatically aligned of the value Pitch of string)
* {{SpinBox|0,000 mm}} '''Radius of coil''' : Radius of coil to modify. (Default : none)
* {{Button|20.0 mm}} : If the button is pressed the value of the "Radius of string" is affected of the "Radius of coil" (This value is automatically aligned of the value Radius of string)
* {{Button|[[Image:FCSpring_Helix_Variable_Icon_01.png|16px]] Accept the value modified}} : Button to accept the modification after select the numbering of coil and modify the pitch of coil.
* '''Text edit''' : This window displayed all coil modified.
* {{Button|Clear}} : Clean the text editor
* {{Button|Zoom}} : Button "Zoom" enlarge the text-edit window

</translate>
[[File:Macro FCSpring Helix Variable 04.png]]
[[File:Macro FCSpring Helix Variable 04.png]]
{{clear}}
{{clear}}
<translate>
<translate>

=== Commands ===
==== Command ==== <!--T:70-->
* {{KEY|Read}} : The Read button open a dialogue box to read a file '''.FCSpring'''.

* {{KEY|Save}} : The Save button open a dialogue box to save a file '''.FCSpring''' with configuration spring modify or not.
<!--T:9-->
* {{KEY|Quit}} : Quit the macro.
* {{Button|[[Image:FCSpring_Helix_Variable_Icon_02.png|16px]] Load}} : The Lead button open a dialogue box to read a file '''.FCSpring'''.
* {{KEY|Reset}} : Reset the macro to default configuration.
* {{Button|[[Image:FCSpring_Helix_Variable_Icon_03.png|16px]] Save}} : The Save button open a dialogue box to save a file '''.FCSpring''' with configuration spring modify or not.
* {{KEY|Launch}} : Launch the macro and create the spring configured.
* {{Button|[[Image:FCSpring_Helix_Variable_Icon_02b.png|16px]] Load Coordinates}} : Open a dialogue box to read a file '''.FCSpringCoor''' (all coordinates of points of the spring).
* {{Button|[[Image:FCSpring_Helix_Variable_Icon_03b.png|16px]] Save Coordinates}} : Open a dialogue box to save a file '''.FCSpringCoor''' (all coordinates of points of the spring).
* {{Button|[[Image:FCSpring_Helix_Variable_Icon_04.png|16px]] Quit}} : Quit the macro.
* {{Button|[[Image:FCSpring_Helix_Variable_Icon_05.png|16px]] Reset}} : Reset the macro to default configuration.
* {{Button|[[Image:FCSpring_Helix_Variable_Icon_06.png|16px]] Launch}} : Launch the macro and create the spring configured.
* {{Button|Help}} : This button display the wiki page int the FreeCAD browser.


</translate>
</translate>
Line 62: Line 158:
{{clear}}
{{clear}}
<translate>
<translate>

=== Report view ===
== Report view == <!--T:71-->

<!--T:10-->
The window report view displayed all value modified.
The window report view displayed all value modified.


Line 69: Line 168:
{{clear}}
{{clear}}
<translate>
<translate>

=== Example spring ===
== Example spring == <!--T:72-->

<!--T:11-->
Example to spring modified
Example to spring modified


Line 76: Line 178:
{{clear}}
{{clear}}
<translate>
<translate>

=== Example Report view ===
== Example Report view == <!--T:73-->

<!--T:12-->
When the macro is launched full list of turns is displayed in tabular form.
When the macro is launched full list of turns is displayed in tabular form.


<!--T:13-->
Here the data of the spring above and displayed in the Report view
Here the data of the spring above and displayed in the Report view
[[File:Macro FCSpring Helix Variable 08.png]]


</translate>
</translate>
[[File:Macro FCSpring Helix Variable 08.png]]
{{clear}}
{{clear}}
<translate>
<translate>
===Script===
Macro_FCSpring_Helix_Variable.FCMacro
</translate>
<syntaxhighlight>
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
"""
***************************************************************************
* Copyright (c) 2014 <mario52> *
* *
* This file is a supplement to the FreeCAD CAx development system. *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License (LGPL) *
* as published by the Free Software Foundation; either version 2 of *
* the License, or (at your option) any later version. *
* for detail see the LICENCE text file. *
* *
* This software is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this macro; if not, write to the Free Software *
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
* USA *
***************************************************************************
* WARNING! All changes in this file will be lost and *
* may cause malfunction of the program *
***************************************************************************
"""
#
#OS: Windows Vista
#Word size: 32-bit
#Version: 0.14.3700 (Git)
#Branch: releases/FreeCAD-0-14
#Hash: 32f5aae0a64333ec8d5d160dbc46e690510c8fe1
#Python version: 2.6.2
#Qt version: 4.5.2
#Coin version: 3.1.0
#SoQt version: 1.4.1
#
__title__ = "Spring_Helix_Variable"
__author__ = "Mario52"
__url__ = "http://www.freecadweb.org/index-fr.html"
__version__ = "01.02"
__date__ = "17/11/2014"


==Icon== <!--T:74-->
try:
import PyQt4
from PyQt4 import QtGui ,QtCore
from PyQt4.QtGui import *
from PyQt4.QtCore import *
except Exception:
import PySide
from PySide import QtGui ,QtCore
from PySide.QtGui import *
from PySide.QtCore import *
import Draft, Part, FreeCAD, math, PartGui, FreeCADGui, FreeCAD
from math import sqrt, pi, sin, cos, asin
from FreeCAD import Base


<!--T:14-->
global path
Download the file image and copy in your macro repertory.
path = FreeCAD.ConfigGet("AppHomePath")
#path = FreeCAD.ConfigGet("UserAppData")


<!--T:15-->
global numberSpires ;numberSpires = 10 # number Spires of spring
Click the image, in the new window position the mouse over the image, click the right mouse and do "Save target as ..."
global rayon ;rayon = 20.0 # radius of spring
global pas ;pas = 15.0 # " ! float " (pas) pitch of spire
global precision ;precision = 5.0 # " ! float " 360/precision number points for 1 turn
global typeLine ;typeLine = 0 # typeLine 0=BSpline or 1=Wire
global helixS ;helixS = 0.0 # tableau
global numberSpiresModified;numberSpiresModified = 1 # number (pas) pitch to modify
global pasSpire ;pasSpire = 0.0 # (pas) pitch of spire to modify
global radiusS ;radiusS = 0.0 # radius to modify
global rayonSpire ;rayonSpire = 0.0 #


<!--T:37-->
try:
ToolBar button [[File:FCSpring Helix Variable.png|left|Button]]
_fromUtf8 = QtCore.QString.fromUtf8
{{clear}}
except AttributeError:
def _fromUtf8(s):
return s


<!--T:75-->
try:
Macro icons
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)


<!--T:16-->
def errorDialog(msg):
[[File:FCSpring_Helix_Variable_Icon_01.png]] [[File:FCSpring_Helix_Variable_Icon_02.png]] [[File:FCSpring_Helix_Variable_Icon_02b.png]] [[File:FCSpring_Helix_Variable_Icon_03.png]] [[File:FCSpring_Helix_Variable_Icon_03b.png]] [[File:FCSpring_Helix_Variable_Icon_04.png]] [[File:FCSpring_Helix_Variable_Icon_05.png]] [[File:FCSpring_Helix_Variable_Icon_06.png]]
diag = QtGui.QMessageBox(QtGui.QMessageBox.Critical,u"Error Message",msg )
{{clear}}
try:
diag.setWindowFlags(PyQt4.QtCore.Qt.WindowStaysOnTopHint) # PyQt4 # cette fonction met la fenêtre en avant
except Exception:
diag.setWindowFlags(PySide.QtCore.Qt.WindowStaysOnTopHint) # PySide #cette fonction met la fenêtre en avant
# diag.setWindowModality(QtCore.Qt.ApplicationModal) # la fonction a été désactivée pour favoriser "WindowStaysOnTopHint"
diag.exec_()


==Script== <!--T:76-->
class Ui_MainWindow(object):


<!--T:17-->
def setupUi(self, MainWindow):
'''Macro_FCSpring_Helix_Variable.FCMacro'''
global path
global numberSpires
global rayon
global pas
global precision
global typeLine
global helixS
global pasSpire
global radiusS


<!--T:38-->
self.window = MainWindow
Download the macro to Gist [https://gist.github.com/mario52a/68c81c32a0727a693d3a Macro_FCSpring_Helix_Variable]


==Installation== <!--T:77-->
MainWindow.setObjectName(_fromUtf8("MainWindow"))
MainWindow.resize(270, 530)
MainWindow.setMaximumSize(QtCore.QSize(270, 530))
MainWindow.setMinimumSize(QtCore.QSize(270, 530))
self.centralWidget = QtGui.QWidget(MainWindow)
self.centralWidget.setObjectName(_fromUtf8("centralWidget"))


<!--T:52-->
self.groupBox = QtGui.QGroupBox(self.centralWidget)
The above file is a macro in the form of GitHub code. Download the Zip on GitHub, and then follow the macros installation instructions for dummies shown at [https://wiki.opensourceecology.org/wiki/Installing_Macros_in_FreeCAD installing FreeCAD macros in Ubuntu].
self.groupBox.setGeometry(QtCore.QRect(10, 40, 251, 201))
self.groupBox.setToolTip(_fromUtf8(""))
self.groupBox.setFlat(False)
self.groupBox.setObjectName(_fromUtf8("groupBox"))


==Examples== <!--T:18-->
self.DS_Numb_Spires = QtGui.QSpinBox(self.groupBox)
self.DS_Numb_Spires.setGeometry(QtCore.QRect(20, 20, 91, 22))
self.DS_Numb_Spires.setToolTip(_fromUtf8("Number total of coil of the spring"))
self.DS_Numb_Spires.setMaximum(9999999)
self.DS_Numb_Spires.setValue(numberSpires)
self.DS_Numb_Spires.setObjectName(_fromUtf8("DS_Numb_Spires"))
self.DS_Numb_Spires.valueChanged.connect(self.on_DS_Numb_Spires) #connection doubleSpinBox


<!--T:19-->
self.DS_Radius_Sping = QtGui.QDoubleSpinBox(self.groupBox)
<center>
self.DS_Radius_Sping.setGeometry(QtCore.QRect(20, 50, 91, 22))
<gallery widths="400" heights="300">
self.DS_Radius_Sping.setToolTip(_fromUtf8("Radius of spring"))
File:Valves Assembly IN EX.png| Valves Assembly IN EX with permit and created by r.tec see [http://forum.freecadweb.org/viewtopic.php?f=24&t=14183 Inlet & Exhaust Valves Assembly] and [http://forum.freecadweb.org/viewtopic.php?f=13&t=14143 Spiralfeder] thanks r.tec
self.DS_Radius_Sping.setDecimals(3)
</gallery>
self.DS_Radius_Sping.setMaximum(9999999.99)
</center>
self.DS_Radius_Sping.setValue(rayon)
<br />
self.DS_Radius_Sping.setObjectName(_fromUtf8("DS_Radius_Sping"))
<center>
self.DS_Radius_Sping.valueChanged.connect(self.on_DS_Radius_Sping) #connection doubleSpinBox
<gallery widths="300" heights="200">
File:Macro FCSpring Helix Variable 12.png|
File:Macro FCSpring Helix Variable 13.png|
</gallery>
</center>
<br />
<center>
<gallery widths="300" heights="200">
File:Macro FCSpring Helix Variable 14.png|
File:Macro FCSpring Helix Variable 15.png|
</gallery>
</center>
<br />
<center>
<gallery widths="300" heights="200">
File:Macro FCSpring Helix Variable 16.png|
File:Macro FCSpring Helix Variable 17.png|
</gallery>
</center>
<br />
<center>
<gallery widths="300" heights="200">
File:Macro FCSpring Helix Variable 18.png|
</gallery>
</center>
<br />
<center>
<gallery widths="300" heights="200">
File:Macro FCSpring Helix Variable polygonalSpiral00.png|Example polygonal Spiral by 3 points
File:Macro FCSpring Helix Variable polygonalSpiral01.png|Example polygonal Spiral by 4 points
</gallery>
</center>
<br />
<center>
<gallery widths="600" heights="200">
File:Macro FCSpring Helix Variable 19.png|Difference between Smooth (here 71 with precision 5 (72 points)) and normal
</gallery>
</center>
<br />
<center>
<gallery widths="800" heights="800">
File:Macro FCSpring Helix Variable.gif|Example
</gallery>
</center>
<br />
<center>
<gallery widths="800" heights="800">
File:Macro FCSpringHelixVariable Example 02.gif|Example create conical spring
</gallery>
</center>
<br />


<!--T:57-->
self.DS_Pas_Spring = QtGui.QDoubleSpinBox(self.groupBox)
<br />
self.DS_Pas_Spring.setGeometry(QtCore.QRect(20, 80, 91, 22))
<center>
self.DS_Pas_Spring.setToolTip(_fromUtf8("Pitch of spring (distance between two vertices)"))
<gallery widths="800" heights="400">
self.DS_Pas_Spring.setDecimals(3)
File:Macro_FCSpringHelixVariable_Spring_On_Circle.gif|Example create spring on circle
self.DS_Pas_Spring.setMaximum(9999999.99)
File:Macro_FCSpringHelixVarable_Spring_Along_Axis.gif|Move along the axis
self.DS_Pas_Spring.setValue(pas)
</gallery>
self.DS_Pas_Spring.setObjectName(_fromUtf8("DS_Pas_Spring"))
</center>
self.DS_Pas_Spring.valueChanged.connect(self.on_DS_Pas_Spring) #connection doubleSpinBox
<br />


==Links== <!--T:78-->
self.DS_Precision_Turn = QtGui.QSpinBox(self.groupBox)
self.DS_Precision_Turn.setGeometry(QtCore.QRect(20, 110, 91, 22))
self.DS_Precision_Turn.setToolTip(_fromUtf8("Precision for the line (points = (360/precision))"))
self.DS_Precision_Turn.setMinimum(1)
self.DS_Precision_Turn.setMaximum(360)
self.DS_Precision_Turn.setValue(precision)
self.DS_Precision_Turn.setObjectName(_fromUtf8("DS_Precision_Turn"))
self.DS_Precision_Turn.valueChanged.connect(self.on_DS_Precision_Turn) #connection doubleSpinBox


<!--T:20-->
self.label_2 = QtGui.QLabel(self.groupBox)
The forum discussion [http://forum.freecadweb.org/viewtopic.php?f=3&t=8313&p=68161#p68161 Try to do a Spring]
self.label_2.setGeometry(QtCore.QRect(120, 20, 111, 16))
self.label_2.setToolTip(_fromUtf8("Number total of coil of the spring"))
self.label_2.setObjectName(_fromUtf8("label_2"))


==Project== <!--T:21-->
self.label_3 = QtGui.QLabel(self.groupBox)
self.label_3.setGeometry(QtCore.QRect(120, 50, 111, 16))
self.label_3.setToolTip(_fromUtf8("Radius of spring"))
self.label_3.setText(_fromUtf8("Radius of spring"))
self.label_3.setObjectName(_fromUtf8("label_3"))


<!--T:47-->
self.label_4 = QtGui.QLabel(self.groupBox)
spring solid truncated
self.label_4.setGeometry(QtCore.QRect(120, 80, 111, 16))
self.label_4.setToolTip(_fromUtf8(""))
self.label_4.setText(_fromUtf8("Pas of spring"))
self.label_4.setObjectName(_fromUtf8("label_4"))


<!--T:48-->
self.label_5 = QtGui.QLabel(self.groupBox)
soften fittings :done
self.label_5.setGeometry(QtCore.QRect(120, 110, 131, 16))
self.label_5.setToolTip(_fromUtf8(""))
self.label_5.setText(_fromUtf8("Precision of turn"))
self.label_5.setObjectName(_fromUtf8("label_5"))


<!--T:22-->
self.groupBox_3 = QtGui.QGroupBox(self.groupBox)
modify diameter to any coil :done
self.groupBox_3.setGeometry(QtCore.QRect(10, 140, 231, 51))
self.groupBox_3.setObjectName(_fromUtf8("groupBox_3"))


==Version== <!--T:23-->
self.RA_Wire = QtGui.QRadioButton(self.groupBox_3)
self.RA_Wire.setGeometry(QtCore.QRect(120, 20, 95, 20))
self.RA_Wire.setToolTip(_fromUtf8("Type line BSpline"))
self.RA_Wire.setText(_fromUtf8("Wire"))
# self.RA_Wire.setChecked(True)
self.RA_Wire.setObjectName(_fromUtf8("RA_Wire"))
self.RA_Wire.clicked.connect(self.on_RA_Wire) #connection radioButton


<!--T:61-->
self.RA_BSpline = QtGui.QRadioButton(self.groupBox_3)
2023/09/01 Version 0.18c adding '''FreeCAD.activeDocument().recompute(None,True,True)'''''Texte en italique'' "bug" fixed by '''Syres''' thanks
self.RA_BSpline.setGeometry(QtCore.QRect(10, 20, 95, 20))
[https://forum.freecad.org/viewtopic.php?p=703568#p703568 How to draw polygonal spirals in Freecad?]
self.RA_BSpline.setToolTip(_fromUtf8("Type line BSpline"))
self.RA_BSpline.setText(_fromUtf8("BSpline"))
self.RA_BSpline.setChecked(True)
self.RA_BSpline.setObjectName(_fromUtf8("RA_BSpline"))
self.RA_BSpline.clicked.connect(self.on_RA_BSpline) #connection radioButton


<!--T:62-->
self.groupBox_2 = QtGui.QGroupBox(self.centralWidget)
2023/09/01 Version 0.18b correct (adapt) the code :
self.groupBox_2.setGeometry(QtCore.QRect(10, 250, 251, 201))
self.groupBox_2.setToolTip(_fromUtf8("This section allows you to adjust the distance from the coil named. EX: 1 spire = 2 mm"))
self.groupBox_2.setCheckable(False)
self.groupBox_2.setChecked(False)
self.groupBox_2.setObjectName(_fromUtf8("groupBox_2"))


</translate>
self.S_Numbering_Spire = QtGui.QSpinBox(self.groupBox_2)
{{Code|code=
self.S_Numbering_Spire.setGeometry(QtCore.QRect(20, 20, 91, 22))
self.PB_Adapt_Radius.setStyleSheet("background-color: QPalette.Base")
self.S_Numbering_Spire.setToolTip(_fromUtf8("Numbering of coil for 1 to max = Number of coil ("+str(numberSpires)+")"))
}}
self.S_Numbering_Spire.setMinimum(1)
to
self.S_Numbering_Spire.setMaximum(numberSpires)
{{Code|code=
self.S_Numbering_Spire.setObjectName(_fromUtf8("S_Nmbering_Spire"))
self.PB_Adapt_Radius.setStyleSheet("QPushButton {background-color: QPalette.Base}")
self.S_Numbering_Spire.valueChanged.connect(self.on_S_Numbering_Spire) #connection SpinBox
}}

<translate>
self.DS_Pas_Spire = QtGui.QDoubleSpinBox(self.groupBox_2)
self.DS_Pas_Spire.setGeometry(QtCore.QRect(20, 50, 91, 22))
self.DS_Pas_Spire.setToolTip(_fromUtf8("Pitch of the coil (The pitch is the distance betwen 2 vertices)"))
self.DS_Pas_Spire.setDecimals(3)
self.DS_Pas_Spire.setMaximum(9999999.99)
self.DS_Pas_Spire.setObjectName(_fromUtf8("DS_Pas_Spire"))
self.DS_Pas_Spire.valueChanged.connect(self.on_DS_Pas_Spire) #connection doubleSpinBox

self.label_6 = QtGui.QLabel(self.groupBox_2)
self.label_6.setGeometry(QtCore.QRect(120, 20, 121, 16))
self.label_6.setToolTip(_fromUtf8("Numbering of coil for 1 to max = Number of coil"))
self.label_6.setText(_fromUtf8("Numbering of coil"))
self.label_6.setObjectName(_fromUtf8("label_6"))

self.label_7 = QtGui.QLabel(self.groupBox_2)
self.label_7.setGeometry(QtCore.QRect(120, 50, 121, 16))
self.label_7.setToolTip(_fromUtf8("Pitch of the coil (The pitch is the distance betwen 2 vertices)"))
self.label_7.setObjectName(_fromUtf8("label_7"))

self.PU_Accept_Value = QtGui.QPushButton(self.groupBox_2)
self.PU_Accept_Value.setGeometry(QtCore.QRect(20, 110, 211, 21))
self.PU_Accept_Value.setToolTip(_fromUtf8("Accept the value for the coil "))
self.PU_Accept_Value.setObjectName(_fromUtf8("PU_Accept_Value"))
self.PU_Accept_Value.clicked.connect(self.on_PU_Accept_Value)

self.textEdit = QtGui.QTextEdit(self.groupBox_2)
self.textEdit.setGeometry(QtCore.QRect(20, 140, 211, 55))
self.textEdit.setToolTip(_fromUtf8("List alls modification of coil "))
self.textEdit.setObjectName(_fromUtf8("textEdit"))
self.textEdit.setTextInteractionFlags(QtCore.Qt.TextSelectableByMouse)

# self.DS_Radius_Spire = QtGui.QDoubleSpinBox(self.groupBox_2)
# self.DS_Radius_Spire.setGeometry(QtCore.QRect(20, 80, 91, 22))
# self.DS_Radius_Spire.setToolTip(_fromUtf8("Radiuf of coil "))
# self.DS_Radius_Spire.setDecimals(3)
# self.DS_Radius_Spire.setMaximum(9999999.99)
# self.DS_Radius_Spire.setObjectName(_fromUtf8("DS_Radius_Spire"))

# self.label_8 = QtGui.QLabel(self.groupBox_2)
# self.label_8.setGeometry(QtCore.QRect(120, 80, 121, 16))
# self.label_8.setToolTip(_fromUtf8("Radiuf of coil "))
# self.label_8.setText(_fromUtf8("Radius of coil"))
# self.label_8.setObjectName(_fromUtf8("label_8"))

self.PU_Quit = QtGui.QPushButton(self.centralWidget)
self.PU_Quit.setGeometry(QtCore.QRect(10, 490, 81, 28))
self.PU_Quit.setToolTip(_fromUtf8("Quit the macro"))
self.PU_Quit.setText(_fromUtf8("Quit"))
self.PU_Quit.setObjectName(_fromUtf8("PU_Quit"))
self.PU_Quit.clicked.connect(self.on_PU_Quit)

self.PU_Launch = QtGui.QPushButton(self.centralWidget)
self.PU_Launch.setGeometry(QtCore.QRect(170, 490, 93, 28))
self.PU_Launch.setToolTip(_fromUtf8("launch the macro and create the spring"))
self.PU_Launch.setText(_fromUtf8("Launch "))
self.PU_Launch.setObjectName(_fromUtf8("PU_Launch"))
self.PU_Launch.clicked.connect(self.on_PU_Launch)

self.label = QtGui.QLabel(self.centralWidget)
self.label.setGeometry(QtCore.QRect(23, 0, 280, 31))
font = QtGui.QFont()
font.setPointSize(12)
font.setBold(True)
font.setItalic(True)
font.setUnderline(True)
font.setWeight(75)
self.label.setFont(font)
self.label.setText(_fromUtf8(" Spring Helix Variable "))
self.label.setObjectName(_fromUtf8("label"))
MainWindow.setCentralWidget(self.centralWidget)

self.PU_Reset = QtGui.QPushButton(self.centralWidget)
self.PU_Reset.setGeometry(QtCore.QRect(100, 490, 61, 28))
self.PU_Reset.setToolTip(_fromUtf8("Reset the data "))
self.PU_Reset.setObjectName(_fromUtf8("PU_Reset"))
self.PU_Reset.clicked.connect(self.on_PU_Reset)

self.PU_Read = QtGui.QPushButton(self.centralWidget)
self.PU_Read.setGeometry(QtCore.QRect(10, 460, 121, 28))
self.PU_Read.setToolTip(_fromUtf8("Read the file "))
self.PU_Read.setText(_fromUtf8("Read"))
self.PU_Read.setObjectName(_fromUtf8("on_PU_Read"))
self.PU_Read.clicked.connect(self.on_PU_Read)

self.PU_Save = QtGui.QPushButton(self.centralWidget)
self.PU_Save.setGeometry(QtCore.QRect(140, 460, 121, 28))
self.PU_Save.setToolTip(_fromUtf8("Save the file"))
self.PU_Save.setText(_fromUtf8("Save"))
self.PU_Save.setObjectName(_fromUtf8("on_PU_Save"))
self.PU_Save.clicked.connect(self.on_PU_Save)

MainWindow.setCentralWidget(self.centralWidget)

self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)

def retranslateUi(self, MainWindow):
try:
MainWindow.setWindowFlags(PyQt4.QtCore.Qt.WindowStaysOnTopHint) # PyQt4 cette fonction met la fenêtre en avant
except Exception:
MainWindow.setWindowFlags(PySide.QtCore.Qt.WindowStaysOnTopHint) # PySide cette fonction met la fenêtre en avant

MainWindow.setWindowTitle("Spring Helix Variable")
self.groupBox.setTitle("Configure")
self.label_2.setText("Number of coil")
self.groupBox_3.setTitle("Type line BSpline")
self.RA_Wire.setToolTip("Type line Wire")
self.groupBox_2.setTitle( "Coil special length")
self.label_7.setText("Pitch of coil")
self.PU_Accept_Value.setText("Accept the value modified")
self.textEdit.setText("")
self.PU_Reset.setText("Reset")

def on_DS_Numb_Spires(self,value): # nombre de spire total
global pas
global numberSpires
global helixS
global radiusS
numberSpires = value
helixS = []
del helixS[:]
helixS = numberSpires*[pas]
radiusS = []
del radiusS[:]
radiusS = numberSpires*[rayon]
self.S_Numbering_Spire.setToolTip(_fromUtf8("Numbering of coil for 1 to max = Number of spires ("+str(numberSpires)+")"))
# App.Console.PrintMessage(str("on_DS_Numb_Spires ")+str(numberSpires)+"\n")


<!--T:60-->
def on_DS_Radius_Sping(self,value): # rayon axial du ressort
2022/03/16 Version 0.18 : adding scrollBar, possibility docking Left or Right, restore the chrono ''(time.time())'', memorise the last FilePath
global rayon
rayon = value
# App.Console.PrintMessage(str("on_DS_Radius_Sping ")+str(rayon)+"\n")


</translate>
def on_DS_Pas_Spring(self,value): # pas (pitch) du ressort
{{Code|code=
global pas
####chrono################
global numberSpires
import time
global helixS
global depart ; depart = 0.0
global numberSpiresModified
global arrivee; arrivee = 0.0
global pasSpire
def chrono(switch): # 0=depart autre=stop
global radiusS
#time.strftime('%X %x %Z')#'15:44:07 12/14/19 Paris, Madrid'
pas = value
global depart
numberSpiresModified = 0
global arrivee
self.S_Numbering_Spire.setValue(numberSpiresModified)
try:
pasSpire = 0.0
if switch == 0:
self.DS_Pas_Spire.setValue(pasSpire)
helixS = []
depart = time.time()#time.clock()
App.Console.PrintMessage("Chrono begin : "+str(time.strftime('%X'))+"\n")
del helixS[:]
helixS = numberSpires*[pas]
radiusS = []
del radiusS[:]
radiusS = numberSpires*[rayon]
# App.Console.PrintMessage(str("on_DS_Pas_Spring ")+str(pas)+"\n")

def on_DS_Precision_Turn(self,value): # " ! float " 360/precision number points for 1 turn
global precision
precision = value
self.label_5.setText(_fromUtf8("Precision = " + str(360/precision) + " points"))
# App.Console.PrintMessage(str("on_DS_Precision_Turn ")+str(precision)+"\n")

def on_RA_Wire(self): #
global typeLine
typeLine = 1
# App.Console.PrintMessage(str("on_RA_Wire ")+str(typeLine)+"\n")

def on_RA_BSpline(self): #
global typeLine
typeLine = 0
# App.Console.PrintMessage(str("on_RA_BSpline ")+str(typeLine)+"\n")

def on_S_Numbering_Spire(self,value): # numero de la spire a modifier
global numberSpires
global numberSpiresModified
self.S_Numbering_Spire.setMaximum(numberSpires)
numberSpiresModified = value
# App.Console.PrintMessage(str("on_S_Nubering_Spire ")+str(numberSpiresModified)+"\n")

def on_DS_Pas_Spire(self,value): # pas (pitch) de la spire a modifier
global pasSpire
pasSpire = value
# App.Console.PrintMessage(str("on_DS_Pas_Spire ")+str(pasSpire)+"\n")

def on_PU_Accept_Value(self): # accepter la modification de la spire
global numberSpiresModified
global pasSpire
global rayonSpire
global helixS
global radiusS
if numberSpiresModified == 1:
helixS[0] = pasSpire
radiusS[0]= rayonSpire
self.textEdit.append("Coil number " + str(numberSpiresModified) + " = " + str(helixS[0]) + " " + str(radiusS[0]))
App.Console.PrintMessage("Coil number " + str(numberSpiresModified) + " = " + str(helixS[0]) + " " + str(radiusS[0])+"\n")
else:
else:
helixS[numberSpiresModified-1] = pasSpire
arrivee = time.time()#time.clock()
App.Console.PrintMessage("Chrono end : "+str(time.strftime('%X'))+"\n")
radiusS[numberSpiresModified-1]= rayonSpire
parcouru = ((arrivee - depart)/60.0)
self.textEdit.append("Coil number " + str(numberSpiresModified) + " = " + str(helixS[numberSpiresModified-1]) + " " + str(radiusS[numberSpiresModified-1]))
App.Console.PrintMessage("Coil number " + str(numberSpiresModified) + " = " + str(helixS[numberSpiresModified-1]) + " " + str(radiusS[numberSpiresModified-1])+"\n")
App.Console.PrintError("Time execution : "+str("%.3f" % parcouru)+" min"+"\n\n")
return parcouru
# App.Console.PrintMessage(str("on_PU_Accept_Value ")+"\n")
FreeCADGui.updateGui()
except Exception: None
####chrono################
}}
<translate>


<!--T:59-->
def on_PU_Quit(self): # Quit
2020/11/12 Version=01.17 : suppress the timer chrono !!
App.Console.PrintMessage("\n"+"Fin FCSpring_Helix_Variable"+"\n"+"___________________________"+"\n")
self.window.hide()
# App.Console.PrintMessage(str(" ")+str()+"\n")


<!--T:58-->
def on_PU_Reset(self): # Reset
2020/10/18 Ver 00.16b : i suppress the test on FC 18 line 56, i suppress the timer chrono and i wait one little
global numberSpires
global rayon
global pas
global precision
global typeLine
global helixS
global numberSpiresModified
global pasSpire
global radiusS
numberSpires = 10
rayon = 20.0
pas = 15.0
precision = 5.0
typeLine = 0
helixS = 0.0
numberSpiresModified = 1
pasSpire = 0.0


<!--T:56-->
self.DS_Numb_Spires.setValue(numberSpires)
2020/05/01 Ver 00.16: correction error file (save and load) cause "label_11_Name" suppressed...
self.DS_Radius_Sping.setValue(rayon)
self.DS_Pas_Spring.setValue(pas)
self.DS_Precision_Turn.setValue(precision)
self.RA_BSpline.setChecked(True)
self.S_Numbering_Spire.setValue(numberSpiresModified)
self.DS_Pas_Spire.setValue(pasSpire)
self.textEdit.setText("")
self.textEdit.clear()
helixS = []
del helixS[:]
helixS = numberSpires*[pas]
radiusS = []
del radiusS[:]
radiusS = numberSpires*[rayon]
# App.Console.PrintMessage(str("on_PU_Reset ")+"\n")


<!--T:55-->
def on_PU_Read(self): # lecture
2020/04/11 Ver 01.15: layout and little presentation
global path
global numberSpires
global rayon
global pas
global precision
global typeLine
global helixS
global radiusS


<!--T:54-->
OpenName = ""
2019/05/03 Ver 01.14: compatible FreeCAD 0.19.16523 (Git)
try:
OpenName = QFileDialog.getOpenFileName(None,QString.fromLocal8Bit("Read a file FCSpring"),path,"*.FCSpring") # PyQt4
except Exception:
OpenName, Filter = PySide.QtGui.QFileDialog.getOpenFileName(None, "Read a file FCSpring", path, "*.FCSpring")#PySide
try:
if OpenName != "":
try:
helixS = []
radiusS = []
del helixS[:]
del radiusS[:]
file = open(OpenName, "r") #
Header = file.readline().rstrip('\n\r')
if Header == "FCString":
self.textEdit.clear()
App.Console.PrintMessage(str(Header)+"\n")
numberSpires = file.readline().rstrip('\n\r')
numberSpires = int(numberSpires)
self.DS_Numb_Spires.setValue(numberSpires)
App.Console.PrintMessage(str(numberSpires)+"\n")


<!--T:50-->
rayon = file.readline().rstrip('\n\r')
2019/04/08 Ver 01.13: compatible FreeCAD 0.18.16093 (Git) /Python version: 3.6.6 /Qt version: 5.6.2
rayon = float(rayon)
radiusS = numberSpires*[rayon]
self.DS_Radius_Sping.setValue(rayon)
App.Console.PrintMessage(str(rayon)+"\n")


<!--T:53-->
pas = file.readline().rstrip('\n\r')
03/04/2017: ver 01.12: correction bug line 2314 add "global ui"
pas = float(pas)
helixS = numberSpires*[pas]
self.DS_Pas_Spring.setValue(pas)
App.Console.PrintMessage(str(pas)+"\n")


<!--T:49-->
precision = file.readline().rstrip('\n\r')
11/12/2016: ver 01.11: Adding Position of the spring on a selected object
precision = float(precision)
self.DS_Precision_Turn.setValue(precision)
App.Console.PrintMessage(str(precision)+"\n")


<!--T:39-->
typeLine = file.readline().rstrip('\n\r') # typeLine 0=BSpline or 1=Wire
10/09/2016: ver 01.10: Adding Button "Zoom" enlarge the textedit window
typeLine = int(typeLine)
if typeLine == 0:
self.RA_BSpline.setChecked(True)
else:
self.RA_Wire.setChecked(True)


<!--T:40-->
dummy = file.readline().rstrip('\n\r')
04/09/2016: ver 01.09: add smoothing
i = 0
for ligne in file:
a , b = ligne.rstrip('\n\r').split(" ")
helixS[i] = float(a)
radiusS[i] = float(b)
App.Console.PrintMessage(str(i+1)+" "+str(helixS[i])+" "+str(radiusS[i])+"\n")
self.textEdit.append("Coil number " + str(i+1) + " = " + str(helixS[i]) + " " + str(radiusS[i]))
i += 1
else:
App.Console.PrintMessage("Error file not FCSpring "+"\n")
errorDialog("Error file not FCSpring "+OpenName)
finally:
file.close()
except Exception:
App.Console.PrintMessage("Error in reading the file "+OpenName+"\n")
errorDialog("Error in reading the file "+OpenName)


<!--T:36-->
def on_PU_Save(self): # enregistrement
16/03/2016: ver 01.08 : correct and add "int()" to debutAngle and finAngle (read file)
global path
global numberSpires
global rayon
global pas
global precision
global typeLine
global helixS
global radiusS


<!--T:35-->
SaveName = ""
02/03/2016: ver 01.07 : add option reverse spring
try:
SaveName = QFileDialog.getSaveFileName(None,QString.fromLocal8Bit("Save a file FCSpring"),path,"*.FCSpring") # PyQt4
except Exception:
SaveName, Filter = PySide.QtGui.QFileDialog.getSaveFileName(None, "Save a file FCSpring", path, "*.FCSpring") # PySide
if SaveName == "":
App.Console.PrintMessage("Process aborted"+"\n")
errorDialog("Process aborted")
else:
App.Console.PrintMessage("Registration of "+SaveName+"\n")
try:
file = open(SaveName, 'w') # write
try:
file.write("FCString"+"\n")
file.write(str(numberSpires)+"\n")
file.write(str(rayon)+"\n")
file.write(str(pas)+"\n")
file.write(str(precision)+"\n")
file.write(str(typeLine)+"\n")
file.write("\n")
for i in range(numberSpires):
file.write(str(helixS[i])+" "+str(radiusS[i])+"\n")
finally:
file.close()
except Exception:
App.Console.PrintMessage("Error Registration file "+SaveName+"\n")
errorDialog("Error Registration file "+SaveName)


<!--T:34-->
def on_PU_Launch(self): # Execute
08/02/2016: ver 01.06 : correct bug angle cause "modifyAngle = int(file.readline().rstrip('\n\r')) # 9" modifyAngle is int() not char
global numberSpires
global rayon
global pas
global precision
global typeLine
global helixS
global pasSpire
global radiusS


<!--T:24-->
doc = FreeCAD.ActiveDocument
07/01/2015: ver 01.05 : adding "Try ...Except" (data cone) for compatibility with old version
if doc == None:
doc = FreeCAD.newDocument()


<!--T:25-->
vecligne=[FreeCAD.Vector(0,0,0),FreeCAD.Vector(rayon ,0.0,0.0)]
07/01/2015: ver 01.04 : adding spring conical and modify the path to "UserAppData" and adding the icone.
ligne = Draft.makeWire(vecligne,closed=False,face=False,support=None) #creation de la ligne de base
coor_X = coor_Y = coor_Z = 0.0
angleTr = 0
points = []
del points[:]
pas2 = 0.0
App.Console.PrintMessage("List " + str(helixS)+"\n")
App.Console.PrintMessage("___________________________"+"\n")
for spir in range(numberSpires): # number spires Helix
pas2 = helixS[spir]
for angleTr in range(0,360,int(precision)): #boucle for 1 turn
ligne.Placement = FreeCAD.ActiveDocument.Line.Placement=App.Placement(App.Vector(0.0,0.0,0.0), App.Rotation(App.Vector(0,0,1),angleTr), App.Vector(0,0,0))
a = ligne.Shape.Edges[0].Vertexes[1] #fin de ligne
coor_X = (a.Point.x)
coor_Y = (a.Point.y)
points += [FreeCAD.Vector(coor_X,coor_Y,coor_Z)] # coordinates makeBSpline
coor_Z += (pas2 / (360/precision)) # pas of spring
# point = Draft.makePoint(coor_X,coor_Y,coor_Z) # create point repere for test
App.ActiveDocument.removeObject(ligne.Name) # remove ligne de base directrice


<!--T:26-->
if typeLine == 1:
07/12/2014: ver 01.03 : new version with radius coil adjustable
ressort = Draft.makeWire(points,closed=False,face=False,support=None)# creation spring makeWire
else:
ressort = Draft.makeBSpline(points,closed=False) # creation spring makeBSpline
FreeCAD.ActiveDocument.recompute()
helixS = []
del helixS[:]
helixS = numberSpires*[pas]
radiusS = []
del radiusS[:]
radiusS = numberSpires*[rayon]

MainWindow = QtGui.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()

</syntaxhighlight>
<translate>

===Links===
The forum discussion [http://forum.freecadweb.org/viewtopic.php?f=3&t=8313&p=68161#p68161 Try to do a Spring]

===Project===
modify diameter to any coil


<!--T:27-->
===Version===
17/11/2014: ver 1.2 : new version with GUI and modification any coil and save or load the data to disk.
17/11/2014: ver 1.02 : new version with GUI and modification any coil and save or load the data to disk.


<!--T:28-->
10/11/2014: (23h20) correction of the modification
10/11/2014: (23h20) correction of the modification
</translate>
</translate>
{{Code|code=
<syntaxhighlight>
ligne.Placement = App.Placement(App.Vector(0.0,0.0,0.0), App.Rotation(App.Vector(0,0,1),angleTr), App.Vector(0,0,0))
ligne.Placement = App.Placement(App.Vector(0.0,0.0,0.0), App.Rotation(App.Vector(0,0,1),angleTr), App.Vector(0,0,0))
}}
</syntaxhighlight>
<translate>
<translate>
<!--T:29-->
10/11/2014: modify line 44 :
10/11/2014: modify line 44 :
</translate>
</translate>
{{Code|code=
<syntaxhighlight>
a = FreeCAD.ActiveDocument.Line.Placement=App.Placement(App.Vector(0.0,0.0,0.0), App.Rotation(App.Vector(0,0,1),angleTr), App.Vector(0,0,0))
a = FreeCAD.ActiveDocument.Line.Placement=App.Placement(App.Vector(0.0,0.0,0.0), App.Rotation(App.Vector(0,0,1),angleTr), App.Vector(0,0,0))
}}
</syntaxhighlight>
<translate>
<translate>
<!--T:30-->
to
to
</translate>
</translate>
{{Code|code=
<syntaxhighlight>
ligne = FreeCAD.ActiveDocument.Line.Placement=App.Placement(App.Vector(0.0,0.0,0.0), App.Rotation(App.Vector(0,0,1),angleTr), App.Vector(0,0,0))
ligne = FreeCAD.ActiveDocument.Line.Placement=App.Placement(App.Vector(0.0,0.0,0.0), App.Rotation(App.Vector(0,0,1),angleTr), App.Vector(0,0,0))
}}
</syntaxhighlight>
<translate>
<translate>
<!--T:31-->
6/11/2014 : adding "makeBSpline" and configuration
6/11/2014 : adding "makeBSpline" and configuration


<!--T:32-->
===Limitations===
==Limitations==
During sweep tests here are the mistakes I have obtained !
During sweep tests here are the mistakes I have obtained !


<!--T:33-->
<center>
<center>
<gallery widths="400" heights="100">
<gallery widths="400" heights="200">
File:Macro FCSpring Helix Variable 20.png|For the moment the macro is not adapted for the square, rectangle... <br />Only circle work well
</gallery>
</center>
<br />
<center>
<gallery widths="300" heights="100">
File:Macro FCSpring Helix Variable 09.png|ACCESS VIOLATION
File:Macro FCSpring Helix Variable 09.png|ACCESS VIOLATION
File:Macro FCSpring Helix Variable 10.png|TCollection_IndexedDataMap
File:Macro FCSpring Helix Variable 10.png|TCollection_IndexedDataMap
</gallery>
</gallery>
</center>
</center>
<br>
<br />
<center>
<center>
<gallery widths="400" heights="100">
<gallery widths="300" heights="100">
File:Macro FCSpring Helix Variable 11.png|Wrong usage of punctual sections
File:Macro FCSpring Helix Variable 11.png|Wrong usage of punctual sections
</gallery>
</gallery>
</center>
</center>
<br>
<br />
</translate>
</translate>
{{clear}}
{{clear}}
<languages/>

Latest revision as of 11:52, 29 December 2023

Other languages:

Macro FCSpring Helix Variable

Description
This macro creates a spring with customizable, any turn may change the spring configuration can be saved in a file with the extension .FCSpring or coordinates .FCSpringCoor.
Are detected: Surface (Face direction), Cylinder (Radius), Ellipse (MinorRadius), Sphere (Radius), Toroid (Radius1), Plane (Direction), Line (follow the Direction ), Point (XYZ vertex position)
If no object is detected (not selection) the spring is created at the point XYZ 0., 0., 0.
See the examples


Download the Icons in .zip file

Macro version: 01.18c
Last modified: 2023/09/01
FreeCAD version: 0.19
Download: ToolBar Icon
Author: Mario52

Author
Mario52
Download
ToolBar Icon
Links
Macro Version
01.18c
Date last modified
2023/09/01
FreeCAD Version(s)
0.19
Default shortcut
None
See also
None

Description

This macro creates a spring highly customizable. Any modification changing the spring configuration can be saved in a file with the extension .FCSpring or coordinates .FCSpringCoor
Are detected: Surface (Face direction), Cylinder (Radius), Ellipse (MinorRadius), Sphere (Radius), Toroid (Radius1), Plane (Direction), Line (follow the Direction ), Point (XYZ vertex position)
If no object is detected (not selection) the spring is created at the point XYZ 0., 0., 0.

Temporary code for external macro link. Do not use this code. This code is used exclusively by Addon Manager. Link for optional manual installation: Macro


# This code is copied instead of the original macro code
# to guide the user to the online download page.
# Use it if the code of the macro is larger than 64 KB and cannot be included in the wiki
# or if the RAW code URL is somewhere else in the wiki.

from PySide import QtGui, QtCore

diag = QtGui.QMessageBox(QtGui.QMessageBox.Information,
    "Information",
    "This macro must be downloaded from this link\n"
    "\n"
    "https://gist.githubusercontent.com/mario52a/68c81c32a0727a693d3a/raw/3f6e4df2768f36e88af4f56af669206ff0d33e0c/Macro_FCSpring_Helix_Variable.FCMacro" + "\n"
    "\n"
    "Quit this window to access the download page")

diag.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
diag.setWindowModality(QtCore.Qt.ApplicationModal)
diag.exec_()

import webbrowser 
webbrowser.open("https://gist.githubusercontent.com/mario52a/68c81c32a0727a693d3a/raw/3f6e4df2768f36e88af4f56af669206ff0d33e0c/Macro_FCSpring_Helix_Variable.FCMacro")


FCSpring Helix Variable

Usage

This section is used to configuration the spring

Schematic detail of spring configuration

Gui

Configuration

  • 10 coils Number of coil : Total of coil to spring. Default = 10
  • 20,000 mm Radius of spring : Radius of spring. Default = 20.0
  • 15,000 mm Pitch of spring : Pitch of spring general. Default = 15.0
  • 5 ( 72 points ) Precision of turn : Precision of turn the precision correspond the number of point for 1 turn the coil and is calculate : precision (number points) = (pitch / (360/precision)). Default = 5 (72 points)
  • 20,000 mm  : Radius of large circle of the cone (check the Spring conical for use)
  • Spring conical : Give the large diameter of the cone that dimension will always be greater than the radius
  • Angles : Check box choice for activate the function Begin and End angle of the coil unchecked by default.
    If the function is checked. The accuracy is automatically set "precision" is ordered 1 ( 360 points ) to 1 (360 points per turn 1 point = 1 degrees)
  • 0 deg Begin : Begin angle of the spring first coil.
  • 360 deg End : End angle of the spring last coil.

Type line

  • Bspline BSpline : Type line BSpline.
  • Wire Wire : Type line Wire.
  • Points Points : Check box point if the check box is activate one point is create of on each point.
  • Reverse Reverse : Check box reverse if the check box is activate the spring changes direction

Options

This section is displayed if on object is selected. The type object is displayed in the Text Editor

The object can be line, 2 points, circle, wire ... one axis the length of the spring is automatically created

Detection : Cylinder (radius), Sphere (radius), Toroid (radius) , Cone (little radius), Circle (radius), Arc (radius), Ellipse (little radius)

  • Normal : If one circle is selected Normal not modify the radius of circle (Default)
    • Adapt Rad. : If the button Normal' is pressed, the button change to Adapt Rad. the spring is adapted to the detected radius (If a radius is detected )
  • Point Mouse : If the click mouse is on one face the spring is created on this point (Default)
    • Center Face : If the button Point Mouse is pressed, the button change to Center Face, the spring is created on the center face selected
  • Position Position : If two object are selected (First axis, Second the spring (or other object)), this checkBox is enabled and you can modify the placement object 2 (spring) along the on object 1 (axis), if this Position is checked the "Position" option is enabled for use
  • Circle : If three points click mouse are selected the Circle button is enabled and it possible to create a circle which can serve as a base for a spring

Position (0)(xx)

(0)(xx) : Number selection(s), length in mm of axis created x 10, equal number of points for shifting the spring of the axis

  • Begin/End : Position the spring on begin, middle, end axis
  • Reverse Spr. : Reverse the spring of the axis
  • 0,1 mm  : Shifting the spring with precision (0.1 mm) along its axis
  • Reverse Count. : Reverse the counter ex: Begin 0 to 10.. or End 0 to 10..
  • Slider : Position the spring on its axis

Coil special dimension

  • Num: 2 Numbering of coil : Numbering of coil to modify. (Default : none)
  • Smoothing Smoothing This checkBox discover one spinBox for determine the grade of smoothing the maximum value is the precision value -1 (this option is still at the prototype stage and the result can be satisfying or completely wrong)
  • 0,000 mm Pitch of coil : Pitch of coil to modify. (Default : none)
  • 15.0 mm : If the button is pressed the value of the "Pitch of string" is affected of the "Pitch of coil" (This value is automatically aligned of the value Pitch of string)
  • 0,000 mm Radius of coil : Radius of coil to modify. (Default : none)
  • 20.0 mm : If the button is pressed the value of the "Radius of string" is affected of the "Radius of coil" (This value is automatically aligned of the value Radius of string)
  • Accept the value modified : Button to accept the modification after select the numbering of coil and modify the pitch of coil.
  • Text edit : This window displayed all coil modified.
  • Clear : Clean the text editor
  • Zoom : Button "Zoom" enlarge the text-edit window

Command

  • Load : The Lead button open a dialogue box to read a file .FCSpring.
  • Save : The Save button open a dialogue box to save a file .FCSpring with configuration spring modify or not.
  • Load Coordinates : Open a dialogue box to read a file .FCSpringCoor (all coordinates of points of the spring).
  • Save Coordinates : Open a dialogue box to save a file .FCSpringCoor (all coordinates of points of the spring).
  • Quit : Quit the macro.
  • Reset : Reset the macro to default configuration.
  • Launch : Launch the macro and create the spring configured.
  • Help : This button display the wiki page int the FreeCAD browser.

Report view

The window report view displayed all value modified.

Example spring

Example to spring modified

Example Report view

When the macro is launched full list of turns is displayed in tabular form.

Here the data of the spring above and displayed in the Report view

Icon

Download the file image and copy in your macro repertory.

Click the image, in the new window position the mouse over the image, click the right mouse and do "Save target as ..."

ToolBar button

Button
Button

Macro icons

Script

Macro_FCSpring_Helix_Variable.FCMacro

Download the macro to Gist Macro_FCSpring_Helix_Variable

Installation

The above file is a macro in the form of GitHub code. Download the Zip on GitHub, and then follow the macros installation instructions for dummies shown at installing FreeCAD macros in Ubuntu.

Examples












Links

The forum discussion Try to do a Spring

Project

spring solid truncated

soften fittings :done

modify diameter to any coil :done

Version

2023/09/01 Version 0.18c adding FreeCAD.activeDocument().recompute(None,True,True)Texte en italique "bug" fixed by Syres thanks How to draw polygonal spirals in Freecad?

2023/09/01 Version 0.18b correct (adapt) the code :

self.PB_Adapt_Radius.setStyleSheet("background-color: QPalette.Base")

to

self.PB_Adapt_Radius.setStyleSheet("QPushButton {background-color: QPalette.Base}")

2022/03/16 Version 0.18 : adding scrollBar, possibility docking Left or Right, restore the chrono (time.time()), memorise the last FilePath

####chrono################
import time
global depart ; depart  = 0.0
global arrivee; arrivee = 0.0
def chrono(switch):    # 0=depart autre=stop
#time.strftime('%X %x %Z')#'15:44:07 12/14/19 Paris, Madrid'
    global depart
    global arrivee
    try:
        if switch == 0:
            depart = time.time()#time.clock()
            App.Console.PrintMessage("Chrono begin   : "+str(time.strftime('%X'))+"\n")
        else:
            arrivee = time.time()#time.clock()
            App.Console.PrintMessage("Chrono end     : "+str(time.strftime('%X'))+"\n")
            parcouru = ((arrivee - depart)/60.0)
            App.Console.PrintError("Time execution : "+str("%.3f" % parcouru)+" min"+"\n\n")
        return parcouru
        FreeCADGui.updateGui()    
    except Exception: None
####chrono################

2020/11/12 Version=01.17 : suppress the timer chrono !!

2020/10/18 Ver 00.16b : i suppress the test on FC 18 line 56, i suppress the timer chrono and i wait one little

2020/05/01 Ver 00.16: correction error file (save and load) cause "label_11_Name" suppressed...

2020/04/11 Ver 01.15: layout and little presentation

2019/05/03 Ver 01.14: compatible FreeCAD 0.19.16523 (Git)

2019/04/08 Ver 01.13: compatible FreeCAD 0.18.16093 (Git) /Python version: 3.6.6 /Qt version: 5.6.2

03/04/2017: ver 01.12: correction bug line 2314 add "global ui"

11/12/2016: ver 01.11: Adding Position of the spring on a selected object

10/09/2016: ver 01.10: Adding Button "Zoom" enlarge the textedit window

04/09/2016: ver 01.09: add smoothing

16/03/2016: ver 01.08 : correct and add "int()" to debutAngle and finAngle (read file)

02/03/2016: ver 01.07 : add option reverse spring

08/02/2016: ver 01.06 : correct bug angle cause "modifyAngle = int(file.readline().rstrip('\n\r')) # 9" modifyAngle is int() not char

07/01/2015: ver 01.05 : adding "Try ...Except" (data cone) for compatibility with old version

07/01/2015: ver 01.04 : adding spring conical and modify the path to "UserAppData" and adding the icone.

07/12/2014: ver 01.03 : new version with radius coil adjustable

17/11/2014: ver 1.02 : new version with GUI and modification any coil and save or load the data to disk.

10/11/2014: (23h20) correction of the modification

ligne.Placement = App.Placement(App.Vector(0.0,0.0,0.0), App.Rotation(App.Vector(0,0,1),angleTr), App.Vector(0,0,0))

10/11/2014: modify line 44 :

a = FreeCAD.ActiveDocument.Line.Placement=App.Placement(App.Vector(0.0,0.0,0.0), App.Rotation(App.Vector(0,0,1),angleTr), App.Vector(0,0,0))

to

ligne = FreeCAD.ActiveDocument.Line.Placement=App.Placement(App.Vector(0.0,0.0,0.0), App.Rotation(App.Vector(0,0,1),angleTr), App.Vector(0,0,0))

6/11/2014 : adding "makeBSpline" and configuration

Limitations

During sweep tests here are the mistakes I have obtained !