Scripted Parts: Ball Bearing - Part 2/it: Difference between revisions
(Updating to match new version of source page) |
Renatorivo (talk | contribs) (Created page with "===Flusso di lavoro=== Il flusso di lavoro è quasi identico a quello che si dovrebbe usare per creare la parte nell'ambiente PartDesign. Solo alcune piccole differenze. *Crea...") |
||
Line 18: | Line 18: | ||
=== |
===Flusso di lavoro=== |
||
Il flusso di lavoro è quasi identico a quello che si dovrebbe usare per creare la parte nell'ambiente PartDesign. |
|||
The workflow is more or less identical how you would create the part in part design workbench.<br /> |
|||
Solo alcune piccole differenze. |
|||
Just some small differences.<br /> |
|||
*Creare un nuovo documento vuoto e renderlo attivo |
|||
*Create a new empty document and make it the active document |
|||
*Disegnare la forma di base dell'anello esterno composta da quattro segmenti e quattro archi |
|||
*Draw the basic shape of the outer ring consisting of four straight lines and four arcs |
|||
[[Image:TutorialBallBearing_P2-Sketch.png|150px]] |
[[Image:TutorialBallBearing_P2-Sketch.png|150px]] |
||
*Collegare le linee e gli archi e promuoverli in un unico contorno |
|||
*Connect the lines and arcs and upgrade them to one single wire |
|||
*Promuovere il contorno in una faccia |
|||
*Upgrade the wire to a face |
|||
*Rivoluzionare la faccia per ottenere una forma |
|||
*Revolve the face to get a shape |
|||
*Disegnare un cerchio |
|||
*Draw a circle |
|||
*Promuovere il cerchio in un contorno |
|||
*Upgrade circle to wire |
|||
*Promovere il contorno in una faccia |
|||
*Upgrade wire to face |
|||
*Rivoluzionare la faccia e applicare un taglio booleano per ottenere la scanalatura dell'anello esterno |
|||
*Revolve face and apply boolean cut to obtain groove in outer ring |
|||
*Disegnare la forma di base dell'anello interno composta da quattro segmenti e quattro archi |
|||
*Draw the basic shape of the inner ring consisting of four straight lines and four arcs |
|||
*Collegare le linee e gli archi e promuoverli in un unico contorno |
|||
*Connect the lines and arcs and upgrade them to one single wire |
|||
*Promuovere il contorno in una faccia |
|||
*Upgrade the wire to a face |
|||
*Rivoluzionare la faccia per ottenere una forma |
|||
*Revolve the face to get a shape |
|||
*Disegnare un cerchio |
|||
*Draw a circle |
|||
*Promuovere il cerchio in un contorno |
|||
*Upgrade circle to wire |
|||
*Promovere il contorno in una faccia |
|||
*Upgrade wire to face |
|||
*Rivoluzionare la faccia e applicare un taglio booleano per ottenere la scanalatura dell'anello interno |
|||
*Revolve face and apply boolean cut to obtain groove in inner ring |
|||
*Inserire le sfere con lo stesso flusso di lavoro usato nella parte 1 del tutorial (dato che è efficace) |
|||
*Insert balls with same workflow as in part 1 (because of effectiveness) |
|||
*Impostare la vista assonometrica |
|||
*Set view to axometric |
|||
*Zoom per adattare la vista alla finestra |
|||
*Zoom to fit all |
|||
===Making the groove=== |
===Making the groove=== |
Revision as of 17:50, 1 November 2016
Tutorial |
Argomento |
---|
Parti con script - Cuscinetto a sfere - #2 |
Livello di difficoltà |
Base |
Tempo di esecuzione |
30 min |
Autori |
r-frank |
Versione di FreeCAD |
0.16.6706 |
Files di esempio |
Vedere anche |
Nessuno |
Introduzione
Questo tutorial si propone di introdurre i principianti alla creazione di parti con script python all'interno di FreeCAD.
Questo tutorial descrive come costruire un cuscinetto a sfere con un flusso di lavoro che consiste nel creare degli schizzi e rivoluzionarli.
Il codice produrrà un nuovo documento di FreeCAD con 12 forme (anello interno, anello esterno e 10 sfere).
Esso sarà simile a questo:
Flusso di lavoro
Il flusso di lavoro è quasi identico a quello che si dovrebbe usare per creare la parte nell'ambiente PartDesign. Solo alcune piccole differenze.
- Creare un nuovo documento vuoto e renderlo attivo
- Disegnare la forma di base dell'anello esterno composta da quattro segmenti e quattro archi
- Collegare le linee e gli archi e promuoverli in un unico contorno
- Promuovere il contorno in una faccia
- Rivoluzionare la faccia per ottenere una forma
- Disegnare un cerchio
- Promuovere il cerchio in un contorno
- Promovere il contorno in una faccia
- Rivoluzionare la faccia e applicare un taglio booleano per ottenere la scanalatura dell'anello esterno
- Disegnare la forma di base dell'anello interno composta da quattro segmenti e quattro archi
- Collegare le linee e gli archi e promuoverli in un unico contorno
- Promuovere il contorno in una faccia
- Rivoluzionare la faccia per ottenere una forma
- Disegnare un cerchio
- Promuovere il cerchio in un contorno
- Promovere il contorno in una faccia
- Rivoluzionare la faccia e applicare un taglio booleano per ottenere la scanalatura dell'anello interno
- Inserire le sfere con lo stesso flusso di lavoro usato nella parte 1 del tutorial (dato che è efficace)
- Impostare la vista assonometrica
- Zoom per adattare la vista alla finestra
Making the groove
Drawing an arc needs either three points or a start angle and an end angle.
In the sketcher we would use constraints to define the start point and the end point of the arc.
Since we can't do this in scripting, we draw a rounded rectangle and revolve it to get a basic "ring shape".
Then we draw a circle and revolve it to get the geometry of the groove.
Then we apply a boolean cut to the two revolved shapes and we have the complete shape of the inner/outer ring.
Inserting the balls
The correct sketcher-based workflow of inserting the balls would be:
- Draw an arc (semi-circle) with center being identical with the origin and draw a line closing the "open" side of the arc
- Convert the two elements to a wire, upgrade to a face, revolve around z-axis to get a ball shape
- Use "translate" command to move the ball into correct position
- Repeat the above steps nine times involving math function to create and position the other balls
- This repeat-operation could be programmed with a loop
Now this is not effective, inserting primitives and positioning them is easier and faster in this case.
So we use the same method as in "Scripted Parts: Ball Bearing - Part 1".
Link
Script di oggetti: La pagina wiki che spiega i principi fondamentali di scripting
Script di dati topologici: Un tutorial per fornire le basi di scripting
Parti con script: Cuscinetto a sfere - Parte 1: Costruirlo con primitive di Parte
Bearings from scripted sketches: Base per questo tutorial, grazie a JMG ...
Code
## Ball-bearing script
## 11.08.2016 by r-frank (BPLRFE/LearnFreeCAD on Youtube)
## based on ball bearing script by JMG
## (http://linuxforanengineer.blogspot.de/2013/12/bearings-from-scripted-sketches.html)
#
#needed for doing boolean operations
import Part
#needed for calculating the positions of the balls
import math
#needed for translation and rotation of objects
from FreeCAD import Base
#
#VALUES#
#(radius of shaft/inner radius of inner ring)
R1=15.0
#(outer radius of inner ring)
R2=25.0
#(inner radius of outer ring)
R3=30.0
#(outer radius of outer ring)
R4=40.0
#(thickness of bearing)
TH=15.0
#(number of balls)
NBall=10
#(radius of ball)
RBall=5.0
#(rounding radius for fillets)
RR=1
#first coordinate of center of ball
CBall=((R3-R2)/2)+R2
#second coordinate of center of ball
PBall=TH/2
#
#Create new document
App.newDocument("Unnamed")
App.setActiveDocument("Unnamed")
App.ActiveDocument=App.getDocument("Unnamed")
Gui.ActiveDocument=Gui.getDocument("Unnamed")
#
#Lines for basic shape of outer ring
L1o=Part.makeLine((R4,0,TH-RR),(R4,0,RR))
L2o=Part.makeLine((R4-RR,0,0),(R3+RR,0,0))
L3o=Part.makeLine((R3,0,RR),(R3,0,TH-RR))
L4o=Part.makeLine((R3+RR,0,TH),(R4-RR,0,TH))
#Corner rounding for basic shape of outer ring
A1o=Part.makeCircle(RR,Base.Vector(R4-RR,0,RR),Base.Vector(0,1,0),0,90)
A2o=Part.makeCircle(RR,Base.Vector(R3+RR,0,RR),Base.Vector(0,1,0),90,180)
A3o=Part.makeCircle(RR,Base.Vector(R3+RR,0,TH-RR),Base.Vector(0,1,0),180,270)
A4o=Part.makeCircle(RR,Base.Vector(R4-RR,0,TH-RR),Base.Vector(0,1,0),270,360)
#Connect Lines and arcs to make wire and upgrade to face, revolve and apply cut to obtain groove
OR=Part.Wire([L1o,A1o,L2o,A2o,L3o,A3o,L4o,A4o])
OR=Part.Face(OR)
OR=OR.revolve(Base.Vector(0,0,1),Base.Vector(0,0,360))
C1=Part.makeCircle(RBall,Base.Vector(R2+(R3-R2)/2,0,TH/2),Base.Vector(0,1,0),0,360)
GRo=Part.Wire([C1])
GRo=Part.Face(GRo)
GRo=GRo.revolve(Base.Vector(0,0,1),Base.Vector(0,0,360))
OR=OR.cut(GRo)
Part.show(OR)
#
#Lines for basic shape of inner ring
L1i=Part.makeLine((R2,0,TH-RR),(R2,0,RR))
L2i=Part.makeLine((R2-RR,0,0),(R1+RR,0,0))
L3i=Part.makeLine((R1,0,RR),(R1,0,TH-RR))
L4i=Part.makeLine((R1+RR,0,TH),(R2-RR,0,TH))
#Corner rounding for basic shape of inner ring
A1i=Part.makeCircle(RR,Base.Vector(R2-RR,0,RR),Base.Vector(0,1,0),0,90)
A2i=Part.makeCircle(RR,Base.Vector(R1+RR,0,RR),Base.Vector(0,1,0),90,180)
A3i=Part.makeCircle(RR,Base.Vector(R1+RR,0,TH-RR),Base.Vector(0,1,0),180,270)
A4i=Part.makeCircle(RR,Base.Vector(R2-RR,0,TH-RR),Base.Vector(0,1,0),270,360)
#Connect Lines and arcs to make wire and upgrade to face, revolve and apply cut to obtain groove
IR=Part.Wire([L1i,A1i,L2i,A2i,L3i,A3i,L4i,A4i])
IR=Part.Face(IR)
IR=IR.revolve(Base.Vector(0,0,1),Base.Vector(0,0,360))
C2=Part.makeCircle(RBall,Base.Vector(R2+(R3-R2)/2,0,TH/2),Base.Vector(0,1,0),0,360)
GRi=Part.Wire([C2])
GRi=Part.Face(GRi)
GRi=GRi.revolve(Base.Vector(0,0,1),Base.Vector(0,0,360))
IR=IR.cut(GRi)
Part.show(IR)
#
#Balls#
for i in range(NBall):
Ball=Part.makeSphere(RBall)
Alpha=(i*2*math.pi)/NBall
BV=(CBall*math.cos(Alpha),CBall*math.sin(Alpha),TH/2)
Ball.translate(BV)
Part.show(Ball)
#
#Make it pretty#
App.activeDocument().recompute()
Gui.activeDocument().activeView().viewAxometric()
Gui.SendMsgToActiveView("ViewFit")