Freecad collision detection

Post here for help on using FreeCAD's graphical user interface (GUI).
Forum rules
and Helpful information
IMPORTANT: Please click here and read this first, before asking for help

Also, be nice to others! Read the FreeCAD code of conduct!
User avatar
bambuko
Veteran
Posts: 2165
Joined: Thu Oct 24, 2019 12:53 pm
Location: UK, England, North Devon

Re: Freecad collision detection

Post by bambuko »

kwahoo wrote: Fri Dec 03, 2021 4:43 pm ...If this can be useful for anyone...
That's very interesting.
Is your gif running in a loop? if so how do you control it?
Which element/part/constraint of your assembly did you animate?
I am using Link branch and Assembly3
you can also download ... and try it here
excellent Assembly3 tutorials here
User avatar
kwahoo
Posts: 680
Joined: Fri Nov 29, 2013 3:09 pm
Contact:

Re: Freecad collision detection

Post by kwahoo »

chrisb wrote: Fri Dec 03, 2021 4:46 pm Looks indeed very good. Can you provide the ffmpeg parameters?
There is a comment in the last line of the script:

Code: Select all

ffmpeg -framerate 25 -i %00d.png -c:v libx264 -profile:v high -crf 20 -pix_fmt yuv420p output.mp4
bambuko wrote: Fri Dec 03, 2021 5:25 pm Is your gif running in a loop? if so how do you control it?
Which element/part/constraint of your assembly did you animate?
The script loops the animation, until I type

Code: Select all

animation.stop()
but you can add if statement to stop animation after defined number of frames.

The script changes a single cell in the Spreadsheet

Code: Select all

App.getDocument("fixedgear").Spreadsheet.set("A2", str(self.an))
and the Spreadsheet drives a Sketch in one of the parts. Other parts are constrained to that Sketch.
Image
chrisb
Veteran
Posts: 53933
Joined: Tue Mar 17, 2015 9:14 am

Re: Freecad collision detection

Post by chrisb »

Thanks!
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
User avatar
bambuko
Veteran
Posts: 2165
Joined: Thu Oct 24, 2019 12:53 pm
Location: UK, England, North Devon

Re: Freecad collision detection

Post by bambuko »

kwahoo wrote: Fri Dec 03, 2021 7:19 pm ...but you can add if statement to stop animation after defined number of frames...
Thank you,
So I guess you define the step, number of steps and stop it afterwards?
This way (as long as number of steps x step = 360 deg) you can create .gif that can run (smoothly) in a continuos loop.
I am using Link branch and Assembly3
you can also download ... and try it here
excellent Assembly3 tutorials here
User avatar
kwahoo
Posts: 680
Joined: Fri Nov 29, 2013 3:09 pm
Contact:

Re: Freecad collision detection

Post by kwahoo »

bambuko wrote: Sat Dec 04, 2021 8:36 am So I guess you define the step, number of steps and stop it afterwards?
This way (as long as number of steps x step = 360 deg) you can create .gif that can run (smoothly) in a continuos loop.
Number of steps or some other value that increments every step. I posted an example in this thread https://forum.freecadweb.org/viewtopic. ... 01#p541101
Reposting it here

Code: Select all

import FreeCAD as App, FreeCADGui as Gui, Part, time
from PySide2 import QtGui,QtCore

class Animation(object):
    def __init__(self):
        App.Console.PrintMessage('Animation started\n')

        App.ActiveDocument.recompute()

        self.timer = QtCore.QTimer()
        QtCore.QObject.connect(self.timer, QtCore.SIGNAL("timeout()"), self.my_update)
        self.timer.start(100) #a step every 0.1s (100 ms)
        self.val = 0.0 #start value
        self.step = 1.0 #step value
        self.end = 360.0 #end value

    def my_update(self):
        App.ActiveDocument.Spreadsheet.set("A2", str(self.val)) #write value to A2 cell
        self.val = self.val + self.step #next value will be incremented by the step
        App.ActiveDocument.recompute()
        if self.val > self.end: #stop updating after 360
            self.timer.stop()
            App.Console.PrintMessage('Animation ended\n')

    def stop(self):
        self.timer.stop()
        App.Console.PrintMessage('Animation stopped\n')


animation = Animation()
User avatar
bambuko
Veteran
Posts: 2165
Joined: Thu Oct 24, 2019 12:53 pm
Location: UK, England, North Devon

Re: Freecad collision detection

Post by bambuko »

kwahoo wrote: Sat Dec 04, 2021 8:56 am ....I posted an example in this thread https://forum.freecadweb.org/viewtopic. ... 01#p541101...
Thank you! That looks very useful.
I guess it can be used to drive anything (that could be useful to me) not just a cell value in a spreadsheet?

will have to experiment with it.... ;)

PS with apologies to OP for hijacking his post ;)
I am using Link branch and Assembly3
you can also download ... and try it here
excellent Assembly3 tutorials here
User avatar
kwahoo
Posts: 680
Joined: Fri Nov 29, 2013 3:09 pm
Contact:

Re: Freecad collision detection

Post by kwahoo »

bambuko wrote: Sat Dec 04, 2021 11:51 am I guess it can be used to drive anything (that could be useful to me) not just a cell value in a spreadsheet?
You can do what you want with these values: change dims in sketches, constraints values in an assembly, dimensions of objects, transparency, colors, manipulate camera position...
TheMarkster
Veteran
Posts: 5505
Joined: Thu Apr 05, 2018 1:53 am

Re: Freecad collision detection

Post by TheMarkster »

Have a look at Animator macro, too.
User avatar
bambuko
Veteran
Posts: 2165
Joined: Thu Oct 24, 2019 12:53 pm
Location: UK, England, North Devon

Re: Freecad collision detection

Post by bambuko »

TheMarkster wrote: Sat Dec 04, 2021 5:26 pm ...Animator macro...
Thank you,
I animate my assemblies by changing placement angle of one single part/body along selected axis (the rest of the assembly is constrained to this particular part/body) .
How would it handle the "solve constraints" command needed after every single step in my assembly?
I will try your macro on one of my test models.
I am using Link branch and Assembly3
you can also download ... and try it here
excellent Assembly3 tutorials here
User avatar
bambuko
Veteran
Posts: 2165
Joined: Thu Oct 24, 2019 12:53 pm
Location: UK, England, North Devon

Re: Freecad collision detection

Post by bambuko »

kwahoo wrote: Sat Dec 04, 2021 3:26 pm ...You can do what you want with these values...
How would it handle the "solve constraints" command needed after every single step in my assembly?
I guess I would have to add it?
I am using Link branch and Assembly3
you can also download ... and try it here
excellent Assembly3 tutorials here
Post Reply