Jump to content

Javier

Member
  • Posts

    1
  • Joined

  • Last visited

Reputation

0 Neutral

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. I had the same issue but what appears to be actually happening is: While vectorworks is running it has an instance of the python interpreter running so when you say import modulename modulename gets put into sys.modules. If you then make changes to modulename the interpreter wont reload the file which is why it needs to be reloaded as suggested by Justin above. Note that the run scripts in debug mode check box in the session preferences will only reload the plugin file script. Not any modules you've defined outside of vectorworks which are referenced by that script. The easy way around this is to restart vectorworks every time you make a change which is annoying. The second is to reload manually as suggested above. Or if you structure your plugin as in the tutorials so the first script contains import _main _main.execute() you can use a decorator on your execute function to unload any modules loaded during the execute() call when it's finished. An example of such a decorator: # decorator that causes any newly imported modules (i.e imported in decorated function) # to have their reference count decremented i.e. del called on the module. So that # they will be reloaded on their next import import sys from functools import wraps def VWModuleReloader(f): #modified original from pyUnit #http://pyunit.sourceforge.net/notes/reloading.html class RollbackImporter: def __init__(self): "Creates an instance and installs as the global importer" self.previousModules = sys.modules.copy() self.realImport = __builtins__['__import__'] __builtins__['__import__'] = self._import self.newModules = {} def _import(self, name, globals=None, locals=None, fromlist=[], level=0): result = self.realImport(name, globals, locals, fromlist, level) self.newModules[name] = 1 return result def uninstall(self): for modname in self.newModules.keys(): if modname not in self.previousModules: # Force reload when modname next imported del(sys.modules[modname]) __builtins__['__import__'] = self.realImport @wraps(f) def reloader(*args, **kwargs): rollbackImporter = RollbackImporter() try: f(*args, **kwargs) except: raise finally: rollbackImporter.uninstall() return reloader To use it decorate the execute function in your _main.py #Anything imported outside of decorated function won't be reloaded from vwModuleReloader import VWModuleReloader . . . @VWModuleReloader def execute(): #any changes to a or b will be reloaded next time execute is called import a from b import C Hope this helps
×
×
  • Create New...