rotating Assy 3 model to a desired angle and back to 0deg (solved)
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
rotating Assy 3 model to a desired angle and back to 0deg (solved)
I have an excellent macro (created by someone else - I am useless ) to animate Assy 3 model of steam loco.
It happily rotates full 360 deg, making a great animation:
but... animation, whilst nice (and I am sure impressive) doesn't do much for my design process.
I would like to be able to rotate it to a desired angle, do what I need to do at this angle, and re-set back to original.
This macro, kind of allows me to rotate to a specific desired angle (by editing macro values).
It doesn't do very well re-setting back to (what I consider) 0deg (or starting position).
Trouble is that if the rotation is less than 45deg resetting works fine, more than that and if I reset constraint angle to 0deg,
model springs back to the nearest (vertical or horizontal) axis.
This is, of course, no criticism of the current macro - it is really meant to simply animate the model,
whereas I want it to do something different...), hence the question:
Is there a better way of doing what I am trying to do, please?
macro, I am using at the moment:
It happily rotates full 360 deg, making a great animation:
but... animation, whilst nice (and I am sure impressive) doesn't do much for my design process.
I would like to be able to rotate it to a desired angle, do what I need to do at this angle, and re-set back to original.
This macro, kind of allows me to rotate to a specific desired angle (by editing macro values).
It doesn't do very well re-setting back to (what I consider) 0deg (or starting position).
Trouble is that if the rotation is less than 45deg resetting works fine, more than that and if I reset constraint angle to 0deg,
model springs back to the nearest (vertical or horizontal) axis.
This is, of course, no criticism of the current macro - it is really meant to simply animate the model,
whereas I want it to do something different...), hence the question:
Is there a better way of doing what I am trying to do, please?
macro, I am using at the moment:
Last edited by bambuko on Tue Jun 08, 2021 8:45 am, edited 3 times in total.
Re: rotating Assy 3 model to a desired angle and back to 0deg
An image of the macro doesn't help as much as the macro itself.
You can create a new macro with lines 19, 20, 22 where you set the desired angle.
You can create a new macro with lines 19, 20, 22 where you set the desired angle.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
Re: rotating Assy 3 model to a desired angle and back to 0deg
sorry, having difficulty attaching anything right now, so hopefully this is OK?:
Code: Select all
import FreeCAD
import time
angle = 0
for i in range(361):
FreeCAD.ActiveDocument.getObject("Constraint016").Angle = angle
Gui.runCommand('asm3CmdQuickSolve',0)
angle -= 1
FreeCADGui.updateGui()
time.sleep(0.001)
# Macro End: +++++++++++++++++++++++++++++++++++++++++++++++++
Setting desired angle is the least of my problems
(although not exactly clear how you suggest to do it..)
I do it at the moment using line 18.
Defining what 0deg is and being able to re-set back to it after any change is the main challenge...
-
- Veteran
- Posts: 3111
- Joined: Thu Sep 24, 2020 10:31 pm
- Location: Hawaii
- Contact:
Re: rotating Assy 3 model to a desired angle and back to 0deg
Code: Select all
FreeCAD.ActiveDocument.getObject("Constraint016").Angle = 0
Re: rotating Assy 3 model to a desired angle and back to 0deg
No, as I explained in my post, it snaps it to the nearest axis.
So, for example, if I move it to 120deg and want to re-set it to 0deg, it actually ends up at 90deg.
It works fine if the rotation is less than 45deg from 0deg(origin).
Re: rotating Assy 3 model to a desired angle and back to 0deg
hi bambuko
you have time the you have this beautiful macro Macro_Rotate_To_Point
principe : all manually rotation and translation step by step mm by mm degrees by degrees
the macro create one macro with all coordinate Placement and use this macro with different options
Q to Quit
D to Decrease speed
P to Pause/Continue or key RETURN or ESCAPE
S to Step by Step
R to Reverse
M for this message
example
the macro file created and the FCStd file associated Animation Pleuel-Stangen AWB
other example
enjoy with your beautiful tchouff tchouff
mario
you have time the you have this beautiful macro Macro_Rotate_To_Point
principe : all manually rotation and translation step by step mm by mm degrees by degrees
the macro create one macro with all coordinate Placement and use this macro with different options
Q to Quit
D to Decrease speed
P to Pause/Continue or key RETURN or ESCAPE
S to Step by Step
R to Reverse
M for this message
example
the macro file created and the FCStd file associated Animation Pleuel-Stangen AWB
other example
enjoy with your beautiful tchouff tchouff
mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Topological_data_scripting.
My macros on Gist.github here complete macros Wiki and forum.
My macros on Gist.github here complete macros Wiki and forum.
Re: rotating Assy 3 model to a desired angle and back to 0deg
Thank you mario52
I will explore your macro and if it works with my Assembly 3 model - it is precisely what I need
-
- Veteran
- Posts: 3111
- Joined: Thu Sep 24, 2020 10:31 pm
- Location: Hawaii
- Contact:
Re: rotating Assy 3 model to a desired angle and back to 0deg
Without a file to test on, I'm working totally blind, but the following should get past what looks to be a "flipping root" problem, by rotating one degree at a time:
If this works we can likely speed it up by rotating in bigger chunks.
Code: Select all
angle = int(FreeCAD.ActiveDocument.getObject("Constraint016").Angle)
while angle != 0:
angle = angle - sign(angle)
FreeCAD.ActiveDocument.getObject("Constraint016").Angle = angle
Gui.runCommand('asm3CmdQuickSolve',0)
FreeCADGui.updateGui()
Re: rotating Assy 3 model to a desired angle and back to 0deg
Thank you edwilliams16
Used original macro to rotate things to a certain angle, and then tried your macro to rotate things back to 0deg.
(I have assumed that this was the intention? apologies if I got it wrong )
I am getting the following error message:
angle = angle - sign(angle)
<class 'NameError'>: name 'sign' is not defined
If you are interested and fancy a challenge I would be more than happy to put the file into some dropbox.edwilliams16 wrote: ↑Fri May 14, 2021 9:25 pm Without a file to test on, I'm working totally blind..
Used original macro to rotate things to a certain angle, and then tried your macro to rotate things back to 0deg.
(I have assumed that this was the intention? apologies if I got it wrong )
I am getting the following error message:
angle = angle - sign(angle)
<class 'NameError'>: name 'sign' is not defined
-
- Veteran
- Posts: 3111
- Joined: Thu Sep 24, 2020 10:31 pm
- Location: Hawaii
- Contact:
Re: rotating Assy 3 model to a desired angle and back to 0deg
Oops, sign is a numpy function, not bare python
Replace that line of code with
Yes this code is to zero the angle, starting anywhere. We can go the dropbox route if this doesn’t do it.
Replace that line of code with
Code: Select all
angle = angle - cmp(angle, 0)