Der A2plus Arbeitsbereich ist ein externer Arbeitsbereich, zum Zusammenbau verschiedener Teile in FreeCAD.
Diese Dokumentation beschreibt die A2plus-Version 0.4.56 oder neuer.
Der A2plus Arbeitsbereich ist eine Erweiterung zu FreeCAD. Er kann einfach mit Hilfe des FreeCAD Erweiterungsverwalters aus dem Werkzeuge → Erweiterungsverwalter Menü installiert werden. A2plus wird aktiv weiterentwickelt und erhält häufig neue Funktionen. Deshalb solltest Du ihn regelmäßig aktualisieren, ebenfalls mittels des Menüs Werkzeuge → Erweiterungsverwalter. Der A2plus Code wird bereitgestellt und weiterentwickelt auf GitHub und kann auch manuell durch kopieren in das FreeCAD Mod Verzeichnis installiert werden.
Wechsle zuerst in die A2plus Werkzeugleiste in FreeCAD. Um eine Baugruppe zu erstellen, erzeuge eine neue Datei in FreeCAD an. Diese Datei muss zuerst gespeichert werden. Es wird empfohlen (aber nicht notwendig), sie im gleichen Ordner zu speichern wie die Teile, die du zusammenbauen willst.
Jetzt können Teile durch Verwendung der Werkzeugleisten Schaltfläche oder zur Baugruppe hinzugefügt werden. Die Schaltfläche fügt alle Körper in der ausgewählten Datei als ein einzelnes Teil ein. Wenn Du die Schaltfläche benutzt, kannst Du wählen, welches Teil aus einer Datei zum Teil importiert werden soll. Auf diese Weise kann man z.B. nur eine Skizze importieren, um weitere Teile zu montieren, indem man die Skizze zur Bestimmung der Teilepositionen verwendet.
Das zuerst hinzugefügte Teil bekommt standardmäßig eine fixe Position. (Du kannst dies später über die Teil Eigenschaft Datenfixed Position ändern.)
Teile, die sich bereits in der Baugruppe befinden, können mit der Schaltfläche in der Werkzeugleiste geklont werden.
Um ein Teil aus der Baugruppe zu bearbeiten, wähle es im Modellbaum aus und verwende die Werkzeugleistenschaltfläche . Dies öffnet das Bauteil in einem neuen Reiter in FreeCAD oder wechselt zu seinem Reiter, wenn die Datei bereits geöffnet ist.
Zum Aktualisieren veränderter Teile klicke auf die Schaltfläche . Die Schaltfläche importiert Teile ebenfalls, jedoch rekursiv über mögliche Subassemblies. Wenn Du eines oder mehrere Teile in FreeCAD's Modellbaum auswählst, dann wird A2plus nachfragen, nur die ausgewählten Teile zu aktualisieren.
Importierte Teile behalten ihre externen Abhängigkeiten und können bearbeitet werden. Für genau definierte Teile wie Schrauben ist es hingegen nützlich, dass ihre Form nicht verändert werden kann. Dies kann erreicht werden mit der Schaltfläche , welche das ausgewählte Teil in eine statische Kopie des Originals konvertiert.
Um das Assembly zu speichern und danach zu schließen kann die Schaltfläche verwendet werden.
Durch Umschalten der Symbolleisten-Schaltfläche wird die Art festgelegt, wie mehrere Kanten, Flächen usw. ausgewählt werden können: Entweder mit einem einzelnen Klick oder durch Ctrl + Klick.
Der Zusammenbau von Teilen erfolgt durch Hinzufügen von Beschränkungen zwischen den Teilen. Nach einer Beschränkung wird A2plus die Teile nach Möglichkeit entsprechend der Beschränkung verschieben.
Um eine Beschränkung zwischen Teilen zu erstellen, halte die Strg Taste gedrückt und wähle jeweils eine Kante oder Fläche von zwei Teilen aus. Klicke dann auf die Werkzeugleisten Schaltfläche der gewünschten Beschränkung. Ein Dialogfeld wird aufgeklappt, das in Abschnitt Beschränkungen beschrieben wird. Die Beschränkung wird in den Modellbaum eingefügt, der an die betroffenen Teile angehängt ist.
Bei komplexen Beschränkungen zwischen Teilen kann A2plus die Beschränkungen möglicherweise nicht lösen. Schau dir daher auch Abschnitt Fehlerbehebung für Strategien zur Lösung solcher Fälle an.
Je mehr Teile du hinzufügst, desto wichtiger ist es, den Überblick zu behalten. A2plus bietet daher diese Werkzeuge zum Verschieben und Anzeigen von Teilen:
Bei der Erstellung einer Beschränkung wird ein solches Dialogfeld angezeigt, nachdem du eine Schaltfläche in der Beschränkungswerkzeugleiste gedrückt hast:
Oben: Der A2plus Beschränkungseigenschaftsdialog
Bei bestimmten Beschränkungen erlaubt es dir, die Richtung der Beschränkung zu ändern. Mit der Schaltfläche Solve kannst du vorab prüfen, ob diese neue Randbedingung von A2plus gelöst werden kann. Falls nicht, wirf einen Blick auf Abschnitt Fehlerbehebung.
Beschränkungen können durch Ändern der Sichtbarkeit deaktiviert werden. Wähle dazu die Beschränkung in der Baumansicht aus und drücke Space. Dadurch wird die Eigenschaft DatenSuppressed umgeschaltet. Eine unterdrückte Beschränkung wird bei der Lösung der Baugruppe nicht berücksichtigt.
A2plus bietet die folgenden Beschränkungen:
Wähle entweder einen Knoten (Punkt), Kreis oder Kugel auf jedem Teil. Wenn ein Kreis oder eine Kugel ausgewählt wurde, wird dessen Mittelpunkt für die Beschränkung verwendet. Die Werkzeugleistenschaltfläche fügt die Beschränkung pointIdentity hinzu, die die Knoten deckungsgleich werden lässt.
Wähle einen Knoten (Punkt), oder kreisförmig Kante (wählt seinen Mittelpunkt aus), oder eine sphärische Fläche (wählt auch seinen Mittelpunkt) auf der einen Seite und ein Kante auf dem anderen Teil. Die Werkzeugleistenschaltfläche fügt die Beschränkung pointOnLine hinzu. Dadurch wird der Knoten auf die Kante gesetzt.
Wähle einen Knoten (Punkt), oder kreisförmige Kante (wählt seinen Mittelpunkt aus), oder eine sphärische Fläche (wählt auch seinen Mittelpunkt) auf einem Teil und eine Ebene auf dem anderen Teil. Die Werkzeugleistenschaltfläche fügt die Beschränkung pointOnPlane hinzu. Im Dialogfeld Beschränkung kannst du einen Versatz zwischen dem Punkt und der Ebene angeben. Dieser Versatz kann auch zwischen beiden Seiten der Ebene umgedreht werden. Wenn der Versatz gleich Null ist, setzt die Beschränkung den Knoten auf die Ebene.
Wähle entweder eine kugelförmige Fläche oder einen Knoten (Punkt) auf beiden Teilen. Die Werkzeugleistenschaltfläche fügt die Beschränkung KugelMitteIdent hinzu. Sie bewirkt, dass entweder das Zentrum der Kugeln, das Zentrum der Kugel und der Knoten oder die Knoten deckungsgleich werden.
Wähle eine kreisförmige Kante bei beiden Teilen aus. Die Schaltfläche fügt die Beschränkung circularEdge hinzu. Der Beschränkungs-Dialog erlaubt Dir einen Versatz zwischen beiden Kanten anzugeben. Der Versatz kann auch umgedreht werden. Du kannst außerdem die Richtung der Beschränkung bestimmen und die Verdrehung der Teile sperren. Wenn der Versatz gleich Null ist, wird die Beschränkung die Kanten konzentrisch in derselben Ebene anordnen.
Wähle entweder eine zylindrische Fläche oder eine lineare Kante auf beiden Teilen. Die Werkzeugleistenschaltfläche fügt die Beschränkung AchseDeckungsgleich hinzu. Der Dialog Beschränkung erlaubt dir die Achsenrichtung anzugeben. Der Dialog ermöglicht es dir außerdem, die Drehung der Teile zu sperren. Durch die Beschränkung werden die Achsen oder Linien deckungsgleich.
Wähle bei beiden Teilen jeweils entweder eine zylindrische Fläche oder eine lineare Kante aus. Die Schaltfläche fügt die Beschränkung Achsparallel hinzu. Der Dialog dieser Beschränkung erlaubt Dir die Achsrichtung anzugeben. Die Beschränkung setzt die Achsen oder Linien zueinander parallel.
Wähle entweder ein zylindrisches Fläche oder eine lineare Kante auf einem Teil und eine Ebene auf dem anderen Teil. Die Werkzeugleistenschaltfläche fügt die Beschränkung AchseEbeneParallel hinzu. Die Beschränkung macht die Achse oder Linie parallel zur Ebene.
Wähle entweder ein zylindrisches Fläche oder eine lineare Kante auf einem Teil und eine Ebene auf dem anderen Teil. Die Werkzeugleistenschaltfläche fügt die Beschränkung AchseEbeneNormal hinzu. Durch die Beschränkung wird die Achse oder Linie normal zur Ebene gemacht.
Wähle entweder eine zylindrische Fläche oder eine lineare Kante auf einem Teil und eine Ebene auf dem anderen Teil.Mit der Werkzeugleistenschaltfläche wird die Beschränkung AchseEbeneWinkel hinzugefügt. Die Beschränkung macht die Achse zunächst parallel zur Ebene. Dann kannst du den Winkel für die Achse im erscheinenden Dialogfeld für die Beschränkungseinstellungen anpassen.
Wähle eine Ebene auf beiden Teilen aus. Die Werkzeugleistenschaltfläche fügt die Beschränkung EbenenParallel hinzu. Im Dialogfeld Beschränkung kannst du die Richtung der Beschränkung angeben. Durch die Beschränkung werden die Ebenen parallel gemacht.
Wähle eine Ebene auf beiden Teilen aus. Die Werkzeugleistenschaltfläche fügt die Beschränkung EbeneDeckungsgleich hinzu. Im Dialogfeld Beschränkung kannst du eine Beschränkungsrichtung und einen Versatz zwischen den Ebenen angeben. Dieser Versatz kann auch umgedreht werden. Wenn der Versatz gleich Null ist, bewirkt die Beschränkung, dass die Ebenen zusammenfallen.
Wähle eine Ebene auf beiden Teilen aus. Die Werkzeugleistenschaltfläche fügt die Beschränkung winkligeEbenen hinzu. Im Dialogfeld Beschränkung kannst du einen Winkel zwischen den Ebenen angeben. Durch die Beschränkung werden die Ebenen zunächst parallel, und der angegebene Winkel wird festgelegt.
Wähle entweder eine geschlossene Kante oder eine Ebene auf beiden Teilen. Die Werkzeugleistenschaltfläche fügt die Beschränkung Massenschwerpunkt hinzu. Im Dialogfeld Beschränkung kannst du einen Versatz zwischen den Kanten oder Ebenen angeben. Dieser Versatz kann auch umgedreht werden. Außerdem kannst du die Beschränkungsrichtung festlegen und die Drehung der Teile sperren. Wenn der Versatz gleich Null ist, setzt die Beschränkung die Kanten oder Ebenen auf dieselbe Ebene.
Eine Baugruppe kann andere Baugruppen enthalten. Sie werden wie Teile hinzugefügt, durch drücken der Werkzeugleistenschaltfläche und Wahl einer *.FCStd Datei, die eine Baugruppe enthält. Solche Unterbaugruppen können auch wie Teile bearbeitet werden, indem die Werkzeugleisteschaltfläche verwendet wird. Bitte stelle bei höheren Baugruppenstufen sicher, dass du die Baugruppe rekursiv über die Werkzeugleistenschaltfläche aktualisierst, wenn es Änderungen gab.
Mögliche Beschränkungen für eine Auswahl werden in der Werkzeugleiste und im Dialogfeld Beschränkungswerkzeuge angezeigt, durch aktivieren der entsprechenden Schaltflächen. Der Beschränkungswerkzeuge Dialog wird über die Werkzeugleistenschaltfläche geöffnet. Es ist beabsichtigt, offen zu bleiben, um der Baugruppe schnell mehrere Beschränkungen hinzufügen zu können.
Vorhandene Beschränkungen können bearbeitet werden, indem sie im Modellbaum ausgewählt und dann entweder doppelt angeklickt oder mit der Werkzeugleistenschaltfläche bearbeitet werden. Dadurch wird das Dialogfeld Beschränkungseigenschaften geöffnet.
Beschränkungen können vorübergehend unterdrückt werden, indem man sie im Modellbaum auswählt und die Baumelementeigenschaft Daten-EigenschaftUnterdrückt ändert.
Beschränkungen können entweder durch Auswahl im Modellbaum und Drücken von Entf oder durch Auswahl eines Teils mit Beschränkungen im Modellbaum und Verwendung der Werkzeugleistenschaltfläche gelöscht werden.
Alle Beschränkungen können jederzeit mit der Werkzeugleistenschaltfläche aufgelöst werden. Wenn die Werkzeugleistenschaltfläche aktiviert ist, wird nach jeder Bearbeitung einer Beschränkung automatisch eine Auflösung durchgeführt.
Die Werkzeugleistenschaltfläche wirkt sich auf die zuletzt hinzugefügte Beschränkung aus. Sie kehrt die Richtung der Beschränkung um.
With the tool, it is possible the show and inspect existing constraints. After clicking it a dialog pops up. Then either select a part in the tree and click the button Import from part to get all constraints of this part, or select one or more constraints in the tree and click the button Import from Tree. As result you get all info about the constraints. By clicking in the column Suppress a single constraint can be suppressed. For more features, follow the tooltips of the other dialog buttons.
Um Stücklisten von Baugruppen zu erstellen, müssen die verschiedenen Teile der Baugruppe Teilinformationen erhalten, die von A2plus gelesen werden können. Dies geschieht durch Bearbeiten des Teils mit Hilfe der Werkzeugleistenschaltfläche . Drücke im geöffneten Teil die Werkzeugleistenschaltfläche und ein Tabellenblatt mit dem Namen #PARTINFO# wird erstellt.
Die Struktur des Tabellenblatts ist wie folgt:
Fülle die grauen Felder mit den Informationen aus, die du hast und in der endgültigen Stückliste haben möchtest.
Verwende in der Baugruppe oder Unterbaugruppe die Werkzeugleistenschaltfläche . Du wirst gefragt, ob du rekursiv über alle Unterbaugruppen iterieren möchtest. Klicke auf Ja. Dadurch wird ein neues Arbeitsblatt mit dem Namen #PARTSLIST# erstellt. Sie enthält die Informationen aus den verschiedenen #PARTSINFO#-Tabellenblättern der Teile in einer Liste wie dieser:
The position (POS) is automatically set according to the appearance of the parts in the model tree. The top level part will get POS 1.
The quantity (QTY) is automatically calculated from the assembly. If a parts is twice in the assembly it will get QTY 2.
If you have updated a part info you can refresh the parts list by pressing the toolbar button again.
For subassemblies you can also create an info spreadsheet using the toolbar button . When you create or update the parts list of the main assembly this info will be used if you click on No for the question if you want to iterate recursively over all subassemblies. Then the different parts are not in the parts list but only the subassemblies.
The toolbar button creates an HTML file with the structure of your assembly. The file will by default be created in the folder of your assembly file. The structure looks like this:
The button labels every part of the assembly with its degrees of freedom. Furthermore it outputs a list with all parts and their dependencies. The list is output into FreeCAD's widget Report view. If this widget is currently not visible, it can either be shown by right-clicking into an empty part of the FreeCAD toolbar area and then choosing it in the appearing context menu or with the menu View → Panels → Report view.
The degrees of freedom labels can be removed by clicking the button again.
The button labels every part of the assembly in the 3D view with its name. The part labels can be removed by clicking the button again
Sometimes it is necessary to have the whole assembly combined as one shape. This shape can then for example be used for 3D printing in the Mesh workbench or for drawings in the TechDraw workbench. It is created using the toolbar button . The shape is by default not made visible. Use the same toolbar button to update the shape in case of changes in the assembly.
With the menu A2plus → Misc → Convert absolute paths of imported parts to relative ones you can convert absolute paths of imported parts to relative ones.
The a2plus preferences can be accessed via FreeCAD's menu Edit → Preferences and there in the section A2plus. You can set the following options:
Sooner or later you will get the problem that A2plus cannot solve the constraints you set. To overcome this, there are different strategies:
This is the safest method when you have several constraints because this tool attempts to solve one constraint after another until it finds the conflicting constraint. Then you can go on with the other strategies to resolve the identified constraint. The tool is called using the toolbar button .
Sometimes constraints seem to be consistently defined but they can nevertheless not be solved. An example: Assume you have a planesParallel constraint set for two planes. Now you want to set for the same planes the planeCoincident constraint and A2plus cannot solve this. Then the constraint directions of planesParallel and planeCoincident are different. Use the same direction for both constraints to fix this.
A2plus offers to automatically check the right direction for all constraints of the assembly using the toolbar button .
Most cases of unsolvable constraints occur directly when adding a new constraint. The solution is then to delete the constraint you added last. A2plus will propose this, too.
Sometimes the deletion strategy is the only one, for example when you edited a part in FreeCAD so that faces or edges connected to constraints are missing. You should then delete one constraint that is connected to the changed part at a time. Use the toolbar button after every deletion to see if you reached a solvable state.
When you got an assembly that can be solved, add step by step the constraints you need.
In some cases the solver only needs better start values to solve the constraints. Take for example the case that you have an axle part and a wheel part. You add a axisCoincident constraint and get no info that the solver failed but the parts are not moved accordingly and in the Report view widget of FreeCAD you see "REACHED POS-ACCURACY :0.0". A solution for this is to move the parts closer to that position you like to get by the constraint.
Note: Assure that at least one part of the constraint has the property Datenfixed Position set to false.
If you miss some features of your part after the import to an A2plus assembly, check the property DatenTip.
A2plus imports bodies of parts with all their features up to the tip feature. This is sensible because setting the tip to a certain feature means that all features behind the tip should not appear in the final part. So if you miss a part feature in A2plus, open the part via the toolbar button , then select a body and look at its property DatenTip. If the tip is not at the feature where you want it, right-click on the feature where the tip should be and choose Set tip. Finally save the part and reload the assembly using the toolbar button .
If you cannot see a clear reason why some constraints cannot be resolved, you can try to use the toolbar button . This will resolve all constraints and re-group then again under the different parts.
Assemblies created with A2plus older than March 2019 do not show the correct icons for imported parts and have obsolete properties. These assemblies can be migrated to A2plus version 0.4.35 and newer using the menu A2plus → Misc → Migrate proxies of imported parts. After doing this, you must save and reopen your assembly file.
Diese Strategie ist für Windows nicht erforderlich.
On some operating systems you can get problems if the file names or the file paths of parts or the assembly contain accented characters. Therefore avoid such characters and also special characters in general.
This strategy is no longer necessary for assemblies created with A2plus 0.3.11 or newer because A2plus issues now a warning for missing fixed positions.
When you set a constraint between two parts and no part has the property Datenfixed Position set to true or is connected by a constraint to a part with Datenfixed Position set to true, the constraint cannot be solved. The same happens if both parts of the constraint have Datenfixed Position set to true.
Then A2plus outputs the info about the failed solution, but sometimes you only see that the parts are not moved accordingly and in the Report view widget of FreeCAD you see "REACHED POS-ACCURACY :0.0". This means the solver finished without errors but it could actually not solve the constraints.
Therefore check that at least one of your parts in the assembly has Datenfixed Position set to true. Then assure that you only set constraints to a part which is somehow connected to the fixed part. To visualise these dependencies, see section Assembly Structure.
This strategy is no longer necessary for assemblies created with A2plus 0.4.0 or newer because A2plus rotates the parts now automatically a bit in the background to get a sufficient start angle for the solver.
The solver often fails for the constraint angledPlanes if the two selected planes have currently an angle of 0° or 180°. (The parts are not moved accordingly and in the Report view widget of FreeCAD you see "REACHED POS-ACCURACY :0.0".) A solution for this is to rotate one part by a few degrees using FreeCAD's transform feature (right-click on the part in the model tree and select in the context menu Transform).
Note: Assure that at least one part of the constraint has the property Datenfixed Position set to false.
A2plus offers animations via dragging and via Python scripts.
Dragging animations are interactive since you trigger it by dragging a part of the assembly. To get these kind of animations:
Here is an example assembly to try out the dragging animation: A2p_example-for-dragging-animation.FCStd
Above: The dragging animation using the example assembly
Despite the dragging mode offers nice interactive animations, they are sometimes not precise enough for screencasts or videos. Scripted animations have the advantage that they animate movements and rotations in a defined way. You can for example rotate a part by exactly 10° back and forth. The following examples use an assembly where a part should be rotated. If you try to animate this using the dragging mode, you will see how hard it is to get a back and forth rotation that you can e.g. show your boss in a presentation. With the interactive example script, however, this is an easy task.
A scripted animation works usually this way:
It is also possible to change instead of a placement parameter a constraint, for example the distance between 2 planes.
The simplest way to script an animation is a non-interactive animation that follows a defined movement. Here is an example: First download this assembly file: A2p_animated-example.FCStd and also this Python script: A2p_animation-example-script.py.
This is the content of the script and the lines beginning with a '#' describe what the different script lines do:
# import libraries
import time, math, PySide
import A2plus.a2p_solversystem as a2p_solver
# we use steps of 1 degree
step = 1
# wait 1 ms between every step
timeout = 0.001
# initial angle is 0 degree
angle = 0
# we take the currently opened document
document = FreeCAD.activeDocument()
# we want later change the rotation angle of the part "star_wheel_001"
starWheel = document.getObject("star_wheel_001")
# define a progress dialog running from 0 to 360
progressDialog = PySide.QtGui.QProgressDialog(u"Animation progress", u"Stop", 0, 360)
# the while block is the main loop to change the angle and solve
# the assembly constraints subsequently
while angle < 360: # run this loop until we have one full turn (360 degrees)
# increase the rotation angle
angle += step
# set the new angle to the progress dialog
progressDialog.setValue(angle)
# change the rotation angle of the part "star_wheel_001"
starWheel.Placement.Rotation.Angle = math.radians(angle)
# solve the constraints
a2p_solver.solveConstraints(document, useTransaction=True)
# update the view after the solving ('Gui' stands for 'graphical user interface')
FreeCADGui.updateGui()
# bring the progress dialog to front
PySide.QtGui.QWidget.raise_(progressDialog)
# if 'Stop' was pressed in the dialog, exit the loop
if progressDialog.wasCanceled():
angle = 360
# wait some time before performing the next step
time.sleep(timeout)
To use the script to perform the animation, we must
To practice, just change something in the script and execute it afterwards. For example increase step to 5.
This is the result of the example animation:
The first script example demonstrated how to create an animation without any user feedback. For most applications you need to interact with the animation. For example the interesting issue in the example is to see how the driving pins cross the center groove of the wheel. To have a closer look you might present this detail to your colleagues or boss. Therefore you need an interactive solution.
This can be done by using a custom animation dialog with a slider. By moving the slider you can set the rotation angle and therefore rotate back and forth at interesting position.
We use the same assembly file: A2p_animated-example.FCStd and this Python script: A2p_animation-example-script.py.
This is the content of the script to get the interactive animation dialog:
# import libraries
import time, math, PySide, sys
import FreeCAD.A2plus.a2p_solversystem as a2p_solver
from FreeCAD import Units
from PySide import QtCore, QtGui
# wait 1 ms after every calculation
timeout = 0.001
# we take the currently opened document
document = FreeCAD.activeDocument()
# we want later change the rotation angle of the part "star_wheel_001"
starWheel = document.getObject("star_wheel_001")
class AnimationDlg(QtGui.QWidget): # the animation dialog
def __init__(self): # to initialize the dialog
super(AnimationDlg, self).__init__()
self.initUI()
def initUI(self): # the definition of the dialog components
self.setMinimumSize(self.minimumSizeHint()) # set the minimal dialog size to minimum
self.setWindowTitle('Animation Dialog')
# use a grid layout for the whole form
self.mainLayout = QtGui.QGridLayout()
self.lineNo = 0 # first dialog grid line
# add description label
DescriptionLabel = QtGui.QLabel(self)
DescriptionLabel.setText("Change slider to change rotation angle")
self.mainLayout.addWidget(DescriptionLabel,self.lineNo,0,1,4)
# next dialog grid line
self.lineNo += 1
# add a label; there is no need for the "self." prefix because we don't want to change the label later
LabelMin = QtGui.QLabel(self)
LabelMin.setText("Min")
LabelMin.setFixedHeight(32)
self.mainLayout.addWidget(LabelMin,self.lineNo,0)
# add a spin edit to define the slider minimum
self.MinEdit = QtGui.QSpinBox(self)
# get the angle unit as string
self.MinEdit.setSuffix(" " + str(FreeCAD.Units.Quantity(1, FreeCAD.Units.Angle))[2:])
self.MinEdit.setMaximum(999)
self.MinEdit.setMinimum(0)
self.MinEdit.setSingleStep(10)
self.MinEdit.setValue(0)
self.MinEdit.setFixedHeight(32)
self.MinEdit.setToolTip("Minimal angle for the slider")
QtCore.QObject.connect(self.MinEdit, QtCore.SIGNAL("valueChanged(int)"), self.setMinEdit)
self.mainLayout.addWidget(self.MinEdit,self.lineNo,1)
# add the slider
self.slider = QtGui.QSlider(QtCore.Qt.Horizontal, self)
self.slider.setRange(0, 360)
self.slider.setValue(0)
self.slider.setFixedHeight(32)
self.slider.setToolTip("Move the slider to change the rotation angle")
QtCore.QObject.connect(self.slider, QtCore.SIGNAL("sliderMoved(int)"), self.handleSliderValue)
self.mainLayout.addWidget(self.slider,self.lineNo,2)
# add a label
LabelMax = QtGui.QLabel(self)
LabelMax.setText("Max")
LabelMax.setFixedHeight(32)
self.mainLayout.addWidget(LabelMax,self.lineNo,3)
# add a spin edit to define the slider maximum
self.MaxEdit = QtGui.QSpinBox(self)
# get the angle unit as string
self.MaxEdit.setSuffix(" " + str(FreeCAD.Units.Quantity(1, FreeCAD.Units.Angle))[2:])
self.MaxEdit.setMaximum(999)
self.MaxEdit.setMinimum(1)
self.MaxEdit.setSingleStep(10)
self.MaxEdit.setValue(360)
self.MaxEdit.setFixedHeight(32)
self.MaxEdit.setToolTip("Maximal angle for the slider")
QtCore.QObject.connect(self.MaxEdit, QtCore.SIGNAL("valueChanged(int)"), self.setMaxEdit)
self.mainLayout.addWidget(self.MaxEdit,self.lineNo,4)
# next dialog grid line
self.lineNo += 1
# add a spacer
self.mainLayout.addItem(QtGui.QSpacerItem(10,10), 0, 0)
# add a label
LabelCurrent = QtGui.QLabel(self)
LabelCurrent.setText("Current angle:")
LabelCurrent.setFixedHeight(32)
self.mainLayout.addWidget(LabelCurrent,self.lineNo,1)
# output the current angle
self.CurrentAngle = QtGui.QLineEdit(self)
self.CurrentAngle.setText(str(0))
self.CurrentAngle.setFixedHeight(32)
self.CurrentAngle.setToolTip("Current rotation angle")
self.CurrentAngle.isReadOnly()
self.mainLayout.addWidget(self.CurrentAngle,self.lineNo,2)
# add label for the unit
LabelUnit = QtGui.QLabel(self)
LabelUnit.setText("deg")
LabelUnit.setFixedHeight(32)
self.mainLayout.addWidget(LabelUnit,self.lineNo,3)
# button to close the dialog
self.Close = QtGui.QPushButton(self)
self.Close.setText("Close")
self.Close.setFixedHeight(32)
self.Close.setToolTip("Closes the dialog")
QtCore.QObject.connect(self.Close, QtCore.SIGNAL("clicked()"), self.CloseClicked)
self.mainLayout.addWidget(self.Close,self.lineNo,4)
# place the defined grid layout to the dialog
self.setLayout(self.mainLayout)
self.update()
def handleSliderValue(self):
# set slider value as angle
starWheel.Placement.Rotation.Angle = math.radians(self.slider.value())
# output current angle
self.CurrentAngle.setText(str(self.slider.value()))
# solve the constraints
a2p_solver.solveConstraints(document)
# update the view after the solving ('Gui' stands for 'graphical user interface')
FreeCADGui.updateGui()
# wait some time, important to give time to perform calculations
time.sleep(timeout)
def setMinEdit(self):
# assure that the minimum is samller than the maximum
if self.MinEdit.value() >= self.MaxEdit.value():
self.MaxEdit.setValue(self.MinEdit.value() + 1)
self.slider.setRange(self.MinEdit.value(), self.MaxEdit.value())
def setMaxEdit(self):
# assure that the minimum is samller than the maximum
if self.MinEdit.value() >= self.MaxEdit.value():
self.MinEdit.setValue(self.MaxEdit.value() - 1)
self.slider.setRange(self.MinEdit.value(), self.MaxEdit.value())
def CloseClicked(self):
AnimationDialog.close()
# create and show the defined dialog
AnimationDialog = AnimationDlg()
AnimationDialog.show()
# run this loop when the dialog is visible
while AnimationDialog.isVisible():
# update the view; important to give the OS feedback the dialog is alive
FreeCADGui.updateGui()
# bring the dialog to front, so that the dialog is always visible
QtGui.QWidget.raise_(AnimationDialog)
# output slider value here too because during the calculation the slider might have been moved
AnimationDialog.CurrentAngle.setText(str(AnimationDialog.slider.value()))
The dialog defined in the script looks like this:
To understand the script syntax better, here is some command info:
starWheel.Placement.Rotation.Angle = math.radians(angle)
Here we change the placement property Rotation.Angle
of the part get got previously as starWheel
. This property gets the angle as radian. The function radians()
from the library math
converts the angle from degree to radian.
The property Rotation.Angle
uses the current placement axis of the part (in our example the X-axis). To rotate the part e.g. around the Z-axis one can set the rotation axis (before calling the rotation command) using the command:
starWheel.Placement.Rotation.Axis = FreeCAD.Vector(0,0,1)
Instead of rotating, parts can also be moved. To change for example the placement in Y-direction of the wheel, the command would be:
starWheel.Placement.Base.y = PositionShift
In this case we would not define the variable angle
but PositionShift
that we change on every loop run.
There are different ways to set the placement of a part. Some are documented here. Unfortunately there is no list (yet) with all possible placement commands.
a2p_solver.solveConstraints(document, useTransaction=False/True)
This is an A2plus-specific command. It solves the assembly constraints of the assembly we previously got as document
. The option useTransaction
specifies if FreeCAD should store every change in the undo/redo stack. For large animations you might therefore set it to false
.