Bonsoir
ça a l'air de bien fonctionner
rotationX permet de faire la rotation d'une autre spire autour du fil selectionner pour obtenir:
le bémol: il travaille sur un fil d'une pièce, ou 1 segment à la fois
- CableElectrique00.png (19.53 KiB) Viewed 2096 times
- CableElectrique01.png (32.99 KiB) Viewed 2096 times
Code: Select all
######Convert the following code to English and optimized: by Syres
## https://forum.freecad.org/viewtopic.php?p=703590#p703590
## How to draw polygonal spirals in Freecad?
#################### Section object selected for follow Begin ####################################################
##Macro_D_Un_Jour_Rotation_D_Un_Fil_Sur_Un_Fil
##20/01/2020, 1/09/2023
##Mario52
##https://forum.freecadweb.org/viewtopic.php?f=12&t=52069&start=40
##Portion FCSpring_Helix_Variable
##
import PySide2.QtCore
import PySide2.QtWidgets
from PySide2 import (QtWidgets, QtCore, QtGui)
from PySide2.QtWidgets import (QWidget, QVBoxLayout, QStyle, QDockWidget, QToolBar, QDialog)
#from PySide2.QtGui import (QColor, QIcon)
from PySide2.QtCore import QSize
import Draft, Part, FreeCADGui
global numberSpires
global rayon
global pas
global precision
global typeLine
global helixS
global pasSpire
global radiusS
global affPoint
global debutAngle
global finAngle
global modifyAngle
global radius_2_Cone
global spireConeUne
global spireConeComp
global spireReverse
global lissageSpire
global lissageS
global points ; points = []
#global nomF
global ressort #global Spring
precision = 360/5 # = 72 points per turn
rayon = 5.0 # spring radius on selected wire mm
pas = 12.0 # pitch mm
epaisseurRessort = 1 # wire radius if wire = 0 then no sweep & keep small say 10-40% of rayon = radius
rotationX = 0 # rotation on the X axis for rotation around the wire selects case several springs
rotationY = 0 # rotation on the Y axis for rotation around the selected wire
rotationZ = 0 # rotation on the Z axis for rotation around the selected thread
#pitch = spring thickness * 2.0 # contiguous turns
#################### Section object selected for follow Begin ####################################################
if rayon != 0:
doc = App.ActiveDocument
if doc == None:
doc = FreeCAD.newDocument()
# #### Chrono begin ##################################
# depart = time.clock() # chrono begin ##
# ####################################################
ressort = "" #ressort = spring
## follow the path
switchFollowThePath = 1
compFollowThePath = -1
followThePath = []
rotationXTR = 180 # Line of work, 0 is default Try 180
typeLine = 0
if switchFollowThePath == 1:
sel = FreeCADGui.Selection.getSelectionEx() #0# Select an object or sub object
subObjet = sel[0].SubObjects[0]
#selobject = FreeCADGui.Selection.getSelection() # Select an object
longueurWire = subObjet.Length
pasTravail = (pas / precision)
followThePath = subObjet.discretize(Distance = pasTravail)
#### estimation
print("Rayon : ", rayon)
print("Pas : ", pas)
print("Pas Travail : ", pasTravail)
print("LongueurWire : ", longueurWire)
print("NombrePoints : ", len(followThePath))
print("Epaisseur : ", epaisseurRessort)
print("________________")
Gui.updateGui() # refresh the screen
#### estimation
coor_X = coor_Y = coor_Z = 0
plDirection = App.Placement(App.Vector(0, 0, 0), App.Rotation(App.Vector(0, 0, 0), 0), App.Vector(0, 0, 0))
vecligne=[App.Vector(0, 0, 0),FreeCAD.Vector(rayon , 0.0, 0.0)]
ligne = Draft.makeWire(vecligne,closed=False,face=False,support=None) #baseline creation
# print(ligne.Length)
# FreeCAD.activeDocument().recompute(None,True,True)
for i in range(len(followThePath)): # line path loop
compFollowThePath += 1 # FollowThePath followThePath[compFollowThePath]
####
try:
direction = followThePath[i+1].sub(followThePath[i])
except Exception: None
r=App.Rotation(App.Vector(0,0,1),direction)
plDirection=App.Placement()
plDirection.Rotation.Q = r.Q
plDirection.Base = followThePath[i]
####
rotationXTR += 360/precision
if rotationXTR >= 360:
rotationXTR = 0
ligne.Placement = plDirection
plDirectionT = ligne.Placement.multiply(App.Placement(App.Vector(0, 0, 0), App.Rotation(rotationXTR + rotationX, rotationY, rotationZ), App.Vector(0, 0, 0)))
ligne.Placement = plDirectionT
FreeCAD.activeDocument().recompute()
a = ligne.End # end of line
points.append(FreeCAD.Vector(a)) # append the coordinates
# Draft.makePoint(a)
App.ActiveDocument.removeObject(ligne.Name)
if typeLine == 1:
ressort = Draft.makeWire(points,closed=False,face=False,support=None)# creation spring makeWire
else:
ressort = Draft.makeBSpline(points,closed=False) # creation spring Draft " makeBSpline " handed over for ease with axles
ressort.ViewObject.LineColor = (1.0,0.0,0.0) # give line LineColor
FreeCAD.ActiveDocument.recompute()
if epaisseurRessort != 0: #Spring thickness
followThePath = []
followThePath = ressort.Shape.Edge1.discretize(Distance = 0.2)
####
try:
direction = followThePath[1].sub(followThePath[0])
except Exception: None
r=App.Rotation(App.Vector(0,0,1),direction)
plDirection=FreeCAD.Placement()
plDirection.Rotation.Q = r.Q
plDirection.Base = followThePath[0]
####
cercle = Draft.makeCircle(radius=epaisseurRessort, placement=plDirection, face=False, support=None)
####Sweep############
mySweep = App.ActiveDocument.addObject('Part::Sweep','mySweepTest')
mySweep.Sections = [cercle]
mySweep.Spine = ressort
mySweep.Solid = True
mySweep.Frenet = True
#mySweep.Transition = 1 #1=angle right 2=courbe #curve
mySweep.Label = "Ressort"
#FreeCAD.ActiveDocument.recompute()
FreeCAD.activeDocument().recompute(None,True,True)
##################### Section object selected for follow End ####################################################
bon amusement chez les Anglais
EDIT 01/09/2023 20h45 Paris : code converti en anglais et optimisé par
syres How to draw polygonal spirals in Freecad?
(l'original semble ne pas fonctionner dans certaines configurations cause : manque de
FreeCAD.activeDocument().recompute(None,True,True))
mario