0
$\begingroup$

I am using blender with an addon called blensor. I have some trouble with this addon and would like to alter its code at some place to see the effect my changes made. Here is a working procedure:

  1. Edit the appropriate python file of the addon in a text editor and save.
  2. Restart blender
  3. Change is visible when running addon

This however is quite tidious for debugging. It would be nice to be able to reload the addon without having to restart blender. I did some research and tried to following, with no success:

  1. Pressing F8 within blender. Looking at the console I can see that blensor seems to be reloaded but the changes I made are not visible when running it. Maybe the output "addon_utils.disable: cycles not disabled" in the system console means something?
  2. Opening the python script in blender's text editor, changing and saving it and clicking Text -> Reload. Does not seem to have any effect.

Any other ways or idea what I am missing?

$\endgroup$
  • $\begingroup$ F8 should be working, are you sure you edited the script file in the right location? In certain cases, it is unavoidable to restart Blender, see developer.blender.org/T37021 $\endgroup$ – CoDEmanX Jul 23 '14 at 10:25
  • $\begingroup$ @CoDEmanX: Well, pretty sure, since the change I make is applied once I restart blender. As for your link: What I could identify as interesting was "As for F8, it is only designed to reload installed addons/ui scripts/etc., not any kind of random py file.". I think that blensor is an addon since I can disable it using bpy.ops.wm.addon_disable. When I browse under user preferences -> addons I cannot find it however....(edit, for reference: blensor.org) $\endgroup$ – user1809923 Jul 23 '14 at 13:35
  • $\begingroup$ It is an addon and should actually be listed somewhere in User Preferences > Addons. The reason why F8 doesn't work appears to be the missing support for it in the code: __init__.py imports the scripts from the same folder, but doesn't handle reloads (see e.g. io_scene_fbx/__init__.py, search for all occurrences of import_fbx for an example of proper import). $\endgroup$ – CoDEmanX Jul 23 '14 at 16:10
1
$\begingroup$

I am the author of the blensor addon.

I used the tip from CoDEmanX and just implemented the reload functionality in the blensor module.

If you have an older blensor version and don't want to compile it from source you can manually add it by changing the file __init__.py

Everything above __version__ has to be changed to

import sys
import traceback
from mathutils import Matrix
from math import pi
import types
import bpy

import blensor.blendodyne
import blensor.depthmap
import blensor.tof
import blensor.evd
import blensor.ibeo
import blensor.generic_lidar
import blensor.kinect
import blensor.exportmotion
import blensor.mesh_utils
import blensor.noise

"""If the blensor module is reloaded, reload all submodules as well
   This will reload all modules at the initial import as well but 
   that should not be a problem
"""
import imp
locals_copy = dict(locals())
for var in locals_copy:
    tmp = locals_copy[var]
    if isinstance(tmp, types.ModuleType) and tmp.__package__ == "blensor":
      print ("Reloading: %s"%(var))
      imp.reload(tmp)

After that hitting F8 should reload the submodules as well.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.