- Document initialization
- Update (not necessary right now)
If this is possible it would be a serious security hole.
Hmm. That might be the rationale why this "facility" doesn't exist in Spreadsheet in the first place.
I was aware of the existence of the StepUp Project, but when I looked at it again, I see that the outputs are generated from source models, which is much like what I want to achieve, only for FreeCAD models.Bance wrote: ↑Wed Sep 05, 2018 5:38 pm Slightly off topic, but have you investigated Kicad stepup project....
https://forum.freecadweb.org/viewtopic.php?t=14276
Steve.
You certainly can, and in itself it is very easy. But you then have to put an explicit warning that by installing your workbench, one opens a huge security hole. I doubt your workbench will be accepted into addon installer, unless you carefully design your workbench to never run code from untrusted FCStd files.
It may be possible to restrict python enough to turn it into javascript. But I don't know if it is, and it is probably a lot of work. Python is a very general-purpose programming language, which can read/write/delete arbitrary files, connect to internet, run executable files, call OS API, and so on. While it might be challenging to damage operating system or install a virus (depends on OS), user data (which is much more valuable) is readily available and unprotected.
I disagree here, because there are limited number of attractions that should be restricted, like you said, filesystem access and network access. I remember that there are readily available Python sandboxes for similar purposes. I mean, the engine might be specifically trimmed to allow only current project's directory, no network access, and maybe a few more things I can't think of right now. I'm also a heavy Javascript user (on browser and server side via NodeJS) and I can say that Javascript has the same same abilities, which in turns, if Javascript can be safe, then Python might be too. Amount of work might be trivial to complex, but I guess it shouldn't be that hard if we could benefit from already available tools.DeepSOIC wrote: ↑Wed Sep 05, 2018 8:03 pmIt may be possible to restrict python enough to turn it into javascript. But I don't know if it is, and it is probably a lot of work. Python is a very general-purpose programming language, which can read/write/delete arbitrary files, connect to internet, run executable files, call OS API, and so on. While it might be challenging to damage operating system or install a virus (depends on OS), user data (which is much more valuable) is readily available and unprotected.
Code: Select all
import FreeCAD as App
import FreeCAD
class FPObject:
def __init__(self, obj):
obj.Proxy = self
def onChanged(self, fp, prop):
'''Do something when a property has changed'''
FreeCAD.Console.PrintMessage("onchanged\n")
def execute(self, fp):
'''Do something when doing a recomputation, this method is mandatory'''
FreeCAD.Console.PrintMessage("execute\n")
def onDocumentRestored(self, fp):
FreeCAD.Console.PrintMessage("onDocumentRestored()\n")
FreeCAD.Console.PrintMessage("macro.py loaded\n")
Code: Select all
from macro import FPObject
m = App.ActiveDocument.addObject("App::FeaturePython","FP")
FPObject(m)