Hi @Kunda1, sorry for letting you wait.Kunda1 wrote: ↑Tue Nov 19, 2019 12:52 pm Bump.
Reason: users aren't aware it's possible to animate assemblies. See https://forum.freecadweb.org/viewtopic. ... 11#p348308
As @vocx told in post above, there is not much space for scripting activities within A2plus except animation.
For most other operations as inserting parts and defining constraints user interaction is assumed as necessary.
Doing animations, only one command related to A2plus is needed to be known (additional to general freecad scripting knowledge):
Code: Select all
FreeCADGui.runCommand('a2p_SolverCommand',0) # this solves all constraints of the active document
FreeCADGui.updateGui() # make results visible at once, not only at the end of a script
Variants:
(1) user changes the placement of a "driving" object: (example)
Code: Select all
import FreeCAD as App
import FreeCADGui as Gui
import time
doc = App.activeDocument()
drivingObject = doc.getObjectsByLabel("crankshaft")[0] # for example a crankshaft of a motor, called by it's label
deltaAngle = 1.0
startAngle = 0.0
drivingObject.Placement.Rotation.Angle = startAngle
for i in range(0,360):
drivingObject.Placement.Rotation.Angle = startAngle + i*deltaAngle # change placement of "driving" object
App.runCommand("a2p_SolverCommand",0) # solve the constraints, move piston e.g.
Gui.updateGui() # show the result immediatly and do not wait for finishing the script
time.sleep(0.01) # delay the frame rate to your requirements
drivingObject.Placement.Rotation.Angle = startAngle # wind back to start
App.runCommand("a2p_SolverCommand",0) # solve last time
Gui.updateGui()
(2) user modifies a constraint and changes for example the offset of it:
Code: Select all
import FreeCAD as App
import FreeCADGui as Gui
import time
doc = App.activeDocument()
drivingConstraint = doc.getObjectsByLabel("<labelOfConstraint>")[0] # place the label of your constraint within " "
deltaOffset = 1.0
startOffset = 0.0
for i in range(0,100):
drivingConstraint.offset = startOffset +i*deltaOffset # change offset of "driving" constraint
App.runCommand("a2p_SolverCommand",0) # solve the constraints, move depending objects
Gui.updateGui() # show the result immediatly and do not wait for finishing the script
time.sleep(0.01) # delay the frame rate to your requirements
drivingConstraint.offset = startOffset # wind back to start
App.runCommand("a2p_SolverCommand",0) # solve last time
Gui.updateGui()
Please can you help with some little documentation in A2plus scripting section ? Thank you.uwestoehr wrote: ping
I can provide working examples.