kryptokommunist / Jupyter_FreeCAD

GSOC 2020 - A better IPython and Jupyter Notebook Integration for FreeCAD
15 stars 4 forks source link

Trying to adapt RealThunders notebook to work here #22

Open KeithSloan opened 3 years ago

KeithSloan commented 3 years ago

ln[1] : `import sys, os

JUPYTER_REPO_PATH = "/opt/jupyter_freecad/"

JUPYTER_REPO_PATH = "/Users/keithsloan/Jupyter_FreeCAD"

sys.path.append("/opt/freecad/freecad_build/lib")

sys.path.append("/Applications/FreeCAD_0.19-E.app/Contents/Resources/lib/python3.8/site-packages") sys.path.append(JUPYTER_REPO_PATH + "IPythonFreeCADViewer")

import FreeCAD, FreeCADGui from pivy import coin from freecadviewer import render_document, get_document_renderer

FreeCADGui.setupWithoutGUI() `

ln[2] : `scadstr=''' module example_intersection() { intersection() { difference() { union() { cube([30, 30, 30], center = true); translate([0, 0, -25]) cube([15, 15, 50], center = true); } union() { cube([50, 10, 10], center = true); cube([10, 50, 10], center = true); cube([10, 10, 50], center = true); } } translate([0, 0, 5]) cylinder(h = 50, r1 = 20, r2 = 5, center = true); } }

example_intersection(); ''' import OpenSCADUtils, importCSG doc=FreeCAD.activeDocument() or FreeCAD.newDocument() obj = doc.getObject('OpenSCADPart') if obj: for o in App.getDependentObjects(obj.Group, 1): doc.removeObject(o.Name) doc.removeObject(obj.Name)

covert the above OpenSCAD script into CSG script

tmpfilename=OpenSCADUtils.callopenscadstring(scadstr,'csg') try:

remember the existing objects

objset = set(doc.Objects)
# import CSG file
importCSG.insert(tmpfilename, doc.Name)
# find all new objects
objs = [obj for obj in doc.Objects if obj not in objset]
# create a part contain to hold new objects
group = doc.addObject('App::Part', 'OpenSCADPart')
group.Group = objs
# recompute and adjust the view to include the newly created objects
doc.recompute()
Gui.Selection.addSelection(group)
Gui.runCommand('Std_ViewSelectionExtend')
Gui.Selection.clearSelection()

finally: os.unlink(tmpfilename)`

Gives error `ModuleNotFoundError Traceback (most recent call last)

in 22 example_intersection(); 23 ''' ---> 24 import OpenSCADUtils, importCSG 25 doc=FreeCAD.activeDocument() or FreeCAD.newDocument() 26 obj = doc.getObject('OpenSCADPart') ~/Library/Preferences/FreeCAD/Mod/OpenSCAD_Alt_Import/OpenSCADUtils.py in 31 32 try: ---> 33 from PySide import QtGui 34 _encoding = QtGui.QApplication.UnicodeUTF8 35 def translate(context, text): /Applications/FreeCAD_0.19-E.app/Contents/Resources/Ext/PySide/__init__.py in 1 # PySide wrapper ----> 2 from PySide2 import __version__ 3 from PySide2 import __version_info__ /Applications/FreeCAD_0.19-E.app/Contents/Resources/lib/python3.8/site-packages/PySide2/__init__.py in 49 os.environ['PATH'] = path 50 ---> 51 _setupQtDirectories() /Applications/FreeCAD_0.19-E.app/Contents/Resources/lib/python3.8/site-packages/PySide2/__init__.py in _setupQtDirectories() 19 # loads the libraries into the process memory beforehand, and 20 # thus takes care of it for us. ---> 21 import shiboken2 22 # Trigger signature initialization. 23 type.__signature__ /Applications/FreeCAD_0.19-E.app/Contents/Resources/lib/python3.8/site-packages/shiboken2/__init__.py in 25 import typing 26 ---> 27 from .shiboken2 import * 28 29 # Trigger signature initialization. ModuleNotFoundError: No module named 'shiboken2.shiboken2' `
KeithSloan commented 3 years ago

changing initial block of code to add path to shiboken2 does not seem to fix i.e. `import sys, os

JUPYTER_REPO_PATH = "/opt/jupyter_freecad/"

JUPYTER_REPO_PATH = "/Users/keithsloan/Jupyter_FreeCAD"

sys.path.append("/opt/freecad/freecad_build/lib")

sys.path.append("/Applications/FreeCAD_0.19-E.app/Contents/Resources/lib") sys.path.append("/Applications/FreeCAD_0.19-E.app/Contents/Resources/lib/python3.8/site-packages") sys.path.append("/Applications/FreeCAD_0.19-E.app/Contents/Resources/lib/python3.8/site-packages/shiboken2") sys.path.append(JUPYTER_REPO_PATH + "IPythonFreeCADViewer")

import FreeCAD, FreeCADGui from pivy import coin from freecadviewer import render_document, get_document_renderer

FreeCADGui.setupWithoutGUI()`