Get Active FreeCAD from external console(solved)

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
loban_iv
Posts: 12
Joined: Wed Jan 13, 2021 11:24 am

Get Active FreeCAD from external console(solved)

Post by loban_iv »

Hi
Is it Possible to get acttive FreeCAD App from extrenal Python consol?

I understand if i run something like this

Code: Select all

import FreeCAD
doc = FreeCAD.open(filename)
I open a file in new FreeCAD session in console mode
Can i acces to allready open FreeCAD?
Thank You!
Last edited by loban_iv on Thu Jan 28, 2021 10:46 am, edited 1 time in total.
openBrain
Veteran
Posts: 9041
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Get Active FreeCAD from external console

Post by openBrain »

I would say No, except if you code a communication system by yourself.
loban_iv
Posts: 12
Joined: Wed Jan 13, 2021 11:24 am

Re: Get Active FreeCAD from external console

Post by loban_iv »

openBrain wrote: Fri Jan 22, 2021 2:46 pm I would say No, except if you code a communication system by yourself.
ThankYou
suzanne.soy
Posts: 54
Joined: Sat Dec 19, 2020 11:55 pm

Re: Get Active FreeCAD from external console

Post by suzanne.soy »

Code: Select all

freecad --single-instance /tmp/please_open_this.FCStd
# Opens the file in a new tab

Code: Select all

cat /tmp/please_run_this_script.py
print("hello nice to meet you Mrs FreeCAD instance!")
freecad --single-instance /tmp/please_run_this_script.py
# The report view of the existing instance shows "hello nice to meet you Mrs FreeCAD instance!"
8-)
:?: Please mark your posts as [solved] :!:
:idea: If the answer you got is a good fit for the wiki, you can edit it!
FreeCAD modelling & coding workbenches+macros: twitch GitHub
loban_iv
Posts: 12
Joined: Wed Jan 13, 2021 11:24 am

Re: Get Active FreeCAD from external console

Post by loban_iv »

Thanks it works for me
keithsloan52
Veteran
Posts: 2764
Joined: Mon Feb 27, 2012 5:31 pm

Re: Get Active FreeCAD from external console

Post by keithsloan52 »

openBrain wrote: Fri Jan 22, 2021 2:46 pm I would say No, except if you code a communication system by yourself.
Sorry you are not correct.

You can start FreeCAD with freecad -c from a command prompt.

You can also do things like

Code: Select all

import sys
# add folder containing FreeCAD.pyd, FreeCADGui.pyd to sys.path
#sys.path.append("C:/Program Files/FreeCAD 0.18/bin") # example for Windows
sys.path.append("/usr/lib/freecad-daily/lib") # example for Linux
sys.path.append("/usr/lib/freecad-daily/Mod") # example for Linux
#sys.path.append("/usr/lib/freecad/lib") # example for Linux
import FreeCAD
import FreeCADGui
import Part
import Draft
import Import


if len(sys.argv)<3:
  print ("Usage: sys.argv[0] <in_file> <out_file>")
  sys.exit(1)

iname=sys.argv[1]
oname=sys.argv[2]

print('Importing : '+iname)
FreeCAD.loadFile(iname)

# iterate through all objects
for o in App.ActiveDocument.Objects:
  # find root object and export the shape
  #print(dir(o))
  #print(o.Name)
  if o.TypeId == 'App::Part' :
     #print(o.TypeId) 
     print('Exporting STEP file : '+oname)
     print('This can be a very slow process')
     print('for large files Please be patient')
     #Import.export([o],"/tmp/test4.step")
     Import.export([o],oname)
     sys.exit(0)

sys.exit(0)

openBrain
Veteran
Posts: 9041
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Get Active FreeCAD from external console

Post by openBrain »

keithsloan52 wrote: Thu Jan 28, 2021 7:53 pm Sorry you are not correct.

You can start FreeCAD with freecad -c from a command prompt.

You can also do things like
:roll: :roll: :roll:
The OP's question is 'Is it possible to get access to an existing running FreeCAD instance from another external Python console?'
Please tell me how what you wrote is a solution.
keithsloan52
Veteran
Posts: 2764
Joined: Mon Feb 27, 2012 5:31 pm

Re: Get Active FreeCAD from external console

Post by keithsloan52 »

openBrain wrote: Thu Jan 28, 2021 8:16 pm
keithsloan52 wrote: Thu Jan 28, 2021 7:53 pm Sorry you are not correct.

You can start FreeCAD with freecad -c from a command prompt.

You can also do things like
:roll: :roll: :roll:
The OP's question is 'Is it possible to get access to an existing running FreeCAD instance from another external Python console?'
Please tell me how what you wrote is a solution.
Your right. I just read the first line "Is it Possible to get acttive FreeCAD App from extrenal Python consol?"
which I don't think is very clear, I read it as he wanted to activate FreeCAD from the console.
openBrain
Veteran
Posts: 9041
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Get Active FreeCAD from external console

Post by openBrain »

keithsloan52 wrote: Thu Jan 28, 2021 8:29 pm Your right. I just read the first line "Is it Possible to get acttive FreeCAD App from extrenal Python consol?"
which I don't think is very clear, I read it as he wanted to activate FreeCAD from the console.
This said, reply from @suzanne.soy above doesn't answer the original question too. But OP said it works for him/her. So maybe I'm just blind guessing the question behind the question. :)
Post Reply