edwilliams16 wrote: ↑Tue May 18, 2021 6:39 pm
Your original macro will only work if the initial angle is near zero...
Yes, it was only meant as a simple animation macro to rotate full 360 deg from zero
I was trying to use it beyond it's original design brief.
edwilliams16 wrote: ↑Tue May 18, 2021 6:39 pm...Plus it is slow and won't do fractional degree settings..
Yes, these were indeed it's limitations.
edwilliams16 wrote: ↑Tue May 18, 2021 6:39 pm This one will do a rotation to any angle from any angle...
and... it does it admirably indeed (including fractional degrees)
More than I could have ever dreamed of
Thank you.
The only thing that caught me unawares, was the polarity of:
final_angle = 10
One has to be conscious of that when specifying this angle
I was used to specifying angle and direction of rotation separately.
Here this is combined in one "final_angle".
So when specifying 270deg I ended up with model at 90deg,
because by default
model rotates "backwards" only?
edwilliams16 wrote: ↑Tue May 18, 2021 6:39 pm
...My test model has only this one constraint, so there's only one possible solution - so the fact that the solver doesn't find it is definitely a BUG.
Not quite sure whether you mean the bug in FreeCAD, or in macro, or in my design?
Even with just one constraint, for CAD systems there is often more than one geometrically correct solution,
hence sketches "flipping" or animations "unable to solve".
I have experienced it in other CAD systems (not just FreeCAD).
Unfortunately, when used with a big, complicated model, any
rotation beyond 180 deg also caused problems with the solver
1)This seems to be making some difference?:
Gui.runCommand(
'asm3CmdSolve',
0)
instead of, originally used:
Gui.runCommand(
'asm3CmdQuickSolve',
0)
not entirely sure of the differences between the two commands (need to do more searching/reading)
2)Is it possible to "slow down" the macro?
I have changed the macro to:
nsteps = int(abs(final_angle_360 - angle)//
2) +
1
FINAL edit:
with 1) and 2) things seem to be 100% reliable
So it looks like (unfortunately) one has to give the solver time to work things out...
and... that doesn't surprise me, based on all my past CAD experience
I happily give up speed for reliability
Final version of your macro that I am using and testing.
I also changed location of:
FreeCADGui.updateGui()
to make changes as happening, visible on the screen.
(previously the only thing I could see was things just jumping to new location, without indication of direction of rotation)
Code: Select all
final_angle = 75.3
constraint_name = "Constraint014"
angle = FreeCAD.ActiveDocument.getObject(constraint_name).Angle
#print(f'Initial angle is {angle} degrees')
#print(f'final angle is {final_angle} in degrees')
angle = angle%360 #limit range to 0 to 360
final_angle_360 = final_angle%360 #limit range to 0 to 360
nsteps = int(abs(final_angle_360 - angle)//2) + 1
steps = [angle + m*(final_angle_360 -angle)/nsteps for m in list(range(1,nsteps+1))]
for ang in steps:
FreeCAD.ActiveDocument.getObject(constraint_name).Angle = ang
Gui.runCommand('asm3CmdSolve',0)
FreeCADGui.updateGui()