Feature: Restart FreeCAD programmatically

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Feature: Restart FreeCAD programmatically

Post by Kunda1 »

Image
Is there a way to do this but within FreeCAD ?

Ref: https://github.com/FreeCAD/FreeCAD-addons/issues/98
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
drmacro
Veteran
Posts: 8867
Joined: Sun Mar 02, 2014 4:35 pm

Re: Feature: Restart FreeCAD programmatically

Post by drmacro »

I know this is a necro bump...but, I figure it is the same question so here I am.

I see that there was a commit for this.

How does one use this in a macro or Python script?

Is it possible to enter a line in the Python console to do it by hand?
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."
User avatar
chennes
Veteran
Posts: 3880
Joined: Fri Dec 23, 2016 3:38 pm
Location: Norman, OK, USA
Contact:

Re: Feature: Restart FreeCAD programmatically

Post by chennes »

The Addon Manager does it- I am away from a computer right now, but check AddonManager.py and search for “restart” . Look for a function called after a one second timeout.
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
wmayer
Founder
Posts: 20243
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Feature: Restart FreeCAD programmatically

Post by wmayer »

Code: Select all

def restart_freecad():
    """Shuts down and restarts FreeCAD"""

    args = QtWidgets.QApplication.arguments()[1:]
    if FreeCADGui.getMainWindow().close():
        QtCore.QProcess.startDetached(
            QtWidgets.QApplication.applicationFilePath(), args
        )
https://github.com/FreeCAD/FreeCAD/blob ... es.py#L106
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: Feature: Restart FreeCAD programmatically

Post by Kunda1 »

Nice! Thanks wmayer!
We're getting another step closer to the original FR in https://forum.freecadweb.org/viewtopic. ... 69#p282469
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
mario52
Veteran
Posts: 4673
Joined: Wed May 16, 2012 2:13 pm

Re: Feature: Restart FreeCAD programmatically

Post by mario52 »

Hi

adding in wiki https://wiki.freecadweb.org/Code_snippe ... rt_FreeCAD

thanks wmayer

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.
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: Feature: Restart FreeCAD programmatically

Post by Kunda1 »

mario52 wrote: Fri Sep 30, 2022 7:24 pm adding in wiki https://wiki.freecadweb.org/Code_snippe ... rt_FreeCAD
Thanks @mario52!
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
Post Reply