To embed in Other Application

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!
hemuman
Posts: 13
Joined: Wed Mar 09, 2011 11:14 am
Contact:

To embed in Other Application

Post by hemuman »

I do not find the lib folder in stable release for FreeCAD.dll.
Please let me know if I am missing something here. :roll: :roll:
wmayer
Founder
Posts: 20319
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: To embed in Other Application

Post by wmayer »

Do you want to integrate FreeCAD over its C++ interface or via Python? For the latter one you can use FreeCAD.pyd and/or FreeCADGui.pyd or any of the modules' .pyd files.

However, if want to go for C++ then you have to build FreeCAD on your own to have all the .lib files because they're not deployed with the MSI installer.
hemuman
Posts: 13
Joined: Wed Mar 09, 2011 11:14 am
Contact:

Re: To embed in Other Application

Post by hemuman »

Thanks for quick reply!
I wanted to go for Python.....

Please let me know which of these path should work :?: :idea: :arrow: :

1). FREECADPATH = 'C:/Program Files (x86)/FreeCAD0.11/bin/'
or
2). FREECADPATH = 'C:/Program Files (x86)/FreeCAD0.11/bin/FreeCADGui.pyd'

sys.path.append(FREECADPATH)
import FreeCADGui


Thanks,
Manoj
wmayer
Founder
Posts: 20319
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: To embed in Other Application

Post by wmayer »

Code: Select all

import sys,os,platform
if platform.architecture()[0] == '32bit':
    # for 32-bit version
    sys.path.append(os.environ["PROGRAMFILES"]+"/FreeCAD0.11/bin")
elif platform.architecture()[0] == '64bit':
    # for 64-bit version
    sys.path.append(os.environ["ProgramW6432"]+"/FreeCAD0.11/bin")
else:
    raise Exception("Unsupported platform %s" % (platform.architecture()[0]))

import FreeCADGui
hemuman
Posts: 13
Joined: Wed Mar 09, 2011 11:14 am
Contact:

Re: To embed in Other Application

Post by hemuman »

Thanks :D :D !!

However when I added last line to this code and tried:

Code: Select all

import sys,os,platform
if platform.architecture()[0] == '32bit':
    # for 32-bit version
    sys.path.append(os.environ["PROGRAMFILES"]+"/FreeCAD0.11/bin")
elif platform.architecture()[0] == '64bit':
    # for 64-bit version
    sys.path.append(os.environ["ProgramW6432"]+"/FreeCAD0.11/bin")
else:
    raise Exception("Unsupported platform %s" % (platform.architecture()[0]))

import FreeCADGui
FreeCADGui.showMainWindow()
I do not see anything coming up, just the messages:

Code: Select all

FreeCAD 0.11, Libs 0.11r4206
Main Window Restored
Show Main Window
Toolbars Restored
and program terminates.

And I am not sure what to expect coming up on the screen.

Please let me know if I am moving in right direction :roll: :roll: .
wmayer
Founder
Posts: 20319
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: To embed in Other Application

Post by wmayer »

This works for me

Code: Select all

import FreeCADGui
FreeCADGui.showMainWindow()
FreeCADGui.exec_loop()
The last line is needed to run the event loop which is needed for all applications using FreeCADGui that isn't based on the GTK, wxWidgets, Win32 or MFC toolkit. If the target application is based on one of these toolkits Qt is able to create a hook to the host application and gets its events from there.

Note:
When running exec_loop() the host application might be blocked. In case this happens to you and you don't want try running the exec_loop() function from a thread.
hemuman
Posts: 13
Joined: Wed Mar 09, 2011 11:14 am
Contact:

Re: To embed in Other Application

Post by hemuman »

Thanks again!!!! :D :D :D

It worked!! of-course it had too :P

As I read through the tutorials, it is possible to embed the components into the wxWidgets(Python)...what I actually meant suppose I just want to pull the 3D parts only and hide all other components, even the File menu and the workbenches? Basically all the operations in background and show the Geometry only...much like an animation video...with custom controls realtime!

:) :) :)

Thanks,
Manoj
User avatar
jriegel
Founder
Posts: 3369
Joined: Sun Feb 15, 2009 5:29 pm
Location: Ulm, Germany
Contact:

Re: To embed in Other Application

Post by jriegel »

The best in this case is to make your own custom workbench in python. I this workbench you can remove all
menus and toolbars. This way you can have a complete empty FreeCAD.
Stop whining - start coding!
hemuman
Posts: 13
Joined: Wed Mar 09, 2011 11:14 am
Contact:

Re: To embed in Other Application

Post by hemuman »

Thanks for the Idea...I do not know to add new workbench either :)
.....actually I intend to add it to the wxWidgets..it is more like testing the flexibility of FreeCAD.

Thanks,
Manoj
wmayer
Founder
Posts: 20319
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: To embed in Other Application

Post by wmayer »

Create a new module directory under Mod and add a file InitGui.py with this content:

Code: Select all

class BlankWorkbench (Workbench):
	MenuText = "Blank"
	ToolTip = "Blank workbench"

	def getMainWindow(self):
		from PyQt4 import QtGui
		toplevel = QtGui.qApp.topLevelWidgets()
		for i in toplevel:
			if i.metaObject().className() == "Gui::MainWindow":
				return i
		raise Exception("No main window found")

	def Initialize(self):
		# Just a small test
		import FreeCAD
		FreeCAD.newDocument()
		return
	def GetClassName(self):
		return "Gui::NonekWorkbench"

	def Activated(self):
		from PyQt4 import QtGui
		mw = self.getMainWindow()
		dw = mw.findChildren(QtGui.QDockWidget)
		for i in dw:
			i.toggleViewAction().setVisible(False)
		mb = mw.findChildren(QtGui.QMenuBar)
		for i in mb:
			i.setVisible(False)
		mw.statusBar().setVisible(False)

	def Deactivated(self):
		from PyQt4 import QtGui
		mw = self.getMainWindow()
		mb = mw.findChildren(QtGui.QMenuBar)
		for i in mb:
			i.setVisible(True)
		mw.statusBar().setVisible(True)

Gui.addWorkbench(BlankWorkbench)
Post Reply