Another approach to assembly solver (A2plus)

Discussion about the development of the Assembly workbench.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
kbwbe
Veteran
Posts: 1052
Joined: Tue Apr 10, 2018 3:12 pm
Location: Germany, near Köln (Cologne)

Re: Another approach to assembly solver (A2plus)

Post by kbwbe »

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
Hi @Kunda1, sorry for letting you wait.

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
The rest depends on the users strategy how to implement an animation.
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()
So the needed knowledge about scripting A2plus is calling the solver command. Everything else depends on general FreeCAD scripting experience.
uwestoehr wrote: ping
Please can you help with some little documentation in A2plus scripting section ? Thank you.
I can provide working examples.
KBWBE

https://github.com/kbwbe/A2plus
latest release: v0.4.56, installable via FreeCAD's addon manager
Tutorial: gripper assembly https://www.youtube.com/watch?v=QMxcQ5tssWk
Documentation: https://www.freecadweb.org/wiki/A2plus_Workbench
User avatar
uwestoehr
Veteran
Posts: 4961
Joined: Sun Jan 27, 2019 3:21 am
Location: Germany
Contact:

Re: Another approach to assembly solver (A2plus)

Post by uwestoehr »

kbwbe wrote: Tue Nov 19, 2019 11:00 pm Please can you help with some little documentation in A2plus scripting section ? Thank you.
I can provide working examples.
Hi Klaus. Yes, I will do so. The question is what scripting is useful to be described. I think a good example of an animation would be nice. This way the user see how scripting is done in genral. If you have such an example, please send me one by private mail that I can experiment with it.
User avatar
uwestoehr
Veteran
Posts: 4961
Joined: Sun Jan 27, 2019 3:21 am
Location: Germany
Contact:

Re: Another approach to assembly solver (A2plus)

Post by uwestoehr »

uwestoehr wrote: Sun Nov 24, 2019 12:16 am Yes, I will do so.
Here is a basic scripting description: https://www.freecadweb.org/wiki/A2plus_ ... #Animation

Can you please have a look at the questions I sent you by mail that I can remove the ''??'' in the Wiki page?
Attachments
A2p_animation-advanced-script.py
advanced animation
(6.35 KiB) Downloaded 1169 times
A2p_animation-example-script.py
animation example script
(1.43 KiB) Downloaded 1857 times
A2p_animated-example.FCStd
animation example assembly
(26.58 KiB) Downloaded 2140 times
Last edited by uwestoehr on Mon Dec 09, 2019 1:32 am, edited 5 times in total.
catman
Posts: 412
Joined: Fri Jan 11, 2019 10:42 pm

Re: Another approach to assembly solver (A2plus)

Post by catman »

When I have a file with 3 PartDesign bodies
  • partname
    • Body1, visible
      Body2, invisible
      Body3, visible
and import this file into a new empty A2+ Assembly file I observe that all bodies are visible. I would have expected I only would see Body1 and Body3 visible. I tried other combinations. Visibility works find on full assemblies, e.g. if each body would be a separate file.

Is that intended behaviour of A2+ or a technical limitation?

Tested in V0.19 17505(Git)


PS: my actual problem behind this is that I need to have a constraint to a face of Body3 which covered by the other bodies. Without being able to make some of them invisible, I can not select that face. Maybe there is another workaround for that...
kbwbe
Veteran
Posts: 1052
Joined: Tue Apr 10, 2018 3:12 pm
Location: Germany, near Köln (Cologne)

Re: Another approach to assembly solver (A2plus)

Post by kbwbe »

catman wrote: Tue Dec 03, 2019 4:48 pm and import this file into a new empty A2+ Assembly file I observe that all bodies are visible. I would have expected I only would see Body1 and Body3 visible. I tried other combinations. Visibility works find on full assemblies, e.g. if each body would be a separate file.
Hi,
you have to activate the option "do not import invisible parts" in A2p preferences.
This should work.
KBWBE

https://github.com/kbwbe/A2plus
latest release: v0.4.56, installable via FreeCAD's addon manager
Tutorial: gripper assembly https://www.youtube.com/watch?v=QMxcQ5tssWk
Documentation: https://www.freecadweb.org/wiki/A2plus_Workbench
kbwbe
Veteran
Posts: 1052
Joined: Tue Apr 10, 2018 3:12 pm
Location: Germany, near Köln (Cologne)

Re: Another approach to assembly solver (A2plus)

Post by kbwbe »

uwestoehr wrote: Tue Dec 03, 2019 1:32 am Can you please have a look at the questions I sent you by mail that I can remove the ''??'' in the Wiki page?
Hi Uwe,
thank you for your good documentation. I have send you an email.
KBWBE

https://github.com/kbwbe/A2plus
latest release: v0.4.56, installable via FreeCAD's addon manager
Tutorial: gripper assembly https://www.youtube.com/watch?v=QMxcQ5tssWk
Documentation: https://www.freecadweb.org/wiki/A2plus_Workbench
catman
Posts: 412
Joined: Fri Jan 11, 2019 10:42 pm

Re: Another approach to assembly solver (A2plus)

Post by catman »

kbwbe wrote: Tue Dec 03, 2019 4:59 pm you have to activate the option "do not import invisible parts" in A2p preferences.
This should work.
Great, thanks it does.

Does the warning that links referring to invisible geometry might break imply that without that option checked this does not happen? I observed that visibility settings are passed from added parts (there is another option on by default) do break the links when parts are toggled to visible/invisible.
Is there technically a difference between those cases?
User avatar
uwestoehr
Veteran
Posts: 4961
Joined: Sun Jan 27, 2019 3:21 am
Location: Germany
Contact:

Re: Another approach to assembly solver (A2plus)

Post by uwestoehr »

kbwbe wrote: Tue Dec 03, 2019 6:39 pm thank you for your good documentation.
I have now improved the documentation: https://www.freecadweb.org/wiki/A2plus_ ... #Animation
The animation has now a progress bar and a button to stop the animation.
User avatar
uwestoehr
Veteran
Posts: 4961
Joined: Sun Jan 27, 2019 3:21 am
Location: Germany
Contact:

Re: Another approach to assembly solver (A2plus)

Post by uwestoehr »

uwestoehr wrote: Tue Dec 03, 2019 11:24 pm I have now improved the documentation: https://www.freecadweb.org/wiki/A2plus_ ... #Animation
The animation has now a progress bar and a button to stop the animation.
I provided now also an interactive example: https://www.freecadweb.org/wiki/A2plus_ ... ve_Example
Turro75
Posts: 179
Joined: Mon Aug 15, 2016 10:23 pm

Re: Another approach to assembly solver (A2plus)

Post by Turro75 »

Hi @Kbwbe!

I'm facing a quite slower importing of complex shapes, I wonder if multithreading the conversion from shape to shell could speed up that process or, as alternative approach, the rewriting of those functions as C code.
What do You think about?

Valerio
Post Reply