All you need to do is to Widgets
> Save Notbook Widget State
and then get the HTML code with Widgets
> Embed Widgets
. Then you have to paste the results into the header of the HTML you get via File
> Download as
> HTML
. This can be developed further in the future, providing a standard set of features like these so you can embed interactive FreeCAD views on your web sites.
import sys, os
JUPYTER_REPO_PATH = "/opt/jupyter_freecad/"
sys.path.append("/opt/freecad/freecad_build/lib")
sys.path.append(JUPYTER_REPO_PATH + "IPythonFreeCADViewer")
import FreeCAD, FreeCADGui
from freecadviewer import RendererConfig, get_document_renderer
FreeCADGui.setupWithoutGUI()
from ipywidgets import jslink, Checkbox
renderer_config_ = RendererConfig()
renderer_config_.show_edges = False
# workaround since it becomes hard to identify the objects in
# the scene group since all lines and meshes are in the
# same group. Fixing this is a TODO
doc_stat = FreeCAD.newDocument()
doc_stat.addObject("Part::Box","Box")
doc_stat.addObject("Part::Cylinder","Cylinder")
doc_stat.addObject("Part::Sphere","Sphere")
doc_stat.addObject("Part::Torus","Torus")
doc_stat.recompute()
renderer, html = get_document_renderer(doc_stat, renderer_config_)
checkboxes = [Checkbox(description="Box"), Checkbox(description="Cylinder"), Checkbox(description="Sphere"), Checkbox(description="Torus"), ]
for i, obj in enumerate(renderer.scene.children[3].children):
jslink((checkboxes[i], "value"), (obj, "visible"))
checkboxes[0].value = True
checkboxes.extend([renderer, html])
display(*checkboxes)