I think it can be done if you are willing to make a few changes to the vpython.py file in your installation of the vpython package.
My idea is to pass a parameter to the vpython canvas() object to indicate if the scene should be visualized like in this sample program.
from vpython import *
scene = canvas(visualize=False)
b = box()
If visualize is False then the scene is not visualized, if it is true then it is visualized.
The first thing to do is to add a class variable called "visualize" to the baseObj class with a default value of True at line 179 in the vpython.py file
class baseObj(object):
glow = None
visualize = True
objCnt = 0
All vpython classes inherit from baseObj. Then update the baseObj class methods appendcmd, addmethod, addattr at around line 273 in the file to check if visualize is True otherwise do nothing if visualize is False. These methods send data to the javascript front end so if you block the data from being sent then the front end will not receive any commands to process.
def appendcmd(self,cmd):
if(self.visualize):
# The following code makes sure that constructors are sent to the front end first.
cmd['idx'] = self.idx
while not baseObj.sent: # baseObj.sent is always True in the notebook case
time.sleep(0.001)
baseObj.updates['cmds'].append(cmd) # this is an "atomic" (uninterruptable) operation
def addmethod(self, method, data):
if(self.visualize):
while not baseObj.sent: # baseObj.sent is always True in the notebook case
time.sleep(0.001)
baseObj.updates['methods'].append((self.idx, method, data)) # this is an "atomic" (uninterruptable) operation
def addattr(self, attr):
if(self.visualize):
while not baseObj.sent: # baseObj.sent is always True in the notebook case
time.sleep(0.001)
baseObj.attrs.add((self.idx, attr)) # this is an "atomic" (uninterruptable) operation
Then update the canvas class around line number 2926 to check if visualize was passed as an argument and if so set the baseObj.visualize class variable. Since all vpython objects inherit from baseObj, by having the baseObj.visualize class variable set to False then no objects will send data to the javascript front end.
if "visualize" in args:
baseObj.visualize = args["visualize"]
# set values of user-defined attributes
for key, value in args.items(): # Assign all other properties
setattr(self, key, value)
With these modifications to vpython.py file you should be able to accomplish what you are looking for. I tried it in a jupyter notebook and it seemed to work. Attached is a version of vpython.py from vpython release 7.6.3 with the above changes.
John