Robowflex  v0.1
Making MoveIt Easy
blender.py
Go to the documentation of this file.
1 import bpy
2 import sys
3 import os
4 import importlib.util
5 import subprocess
6 """Run this script in order to execute:
7  `robowflex_visualization/src/robowflex.py`
8 
9  This script contains some utility functions for loading system Python paths
10  and finding the ROS package. You can change which script is ran by changing
11  the arguments to `load_ROS_module` at the bottom of the file.
12 
13  Moreover, the `robowflex_visualization/src` directory is added to the path,
14  so that the various helper modules can be found.
15 
16  You should put all of your visualization code in whatever file is loaded at
17  the bottom.
18 """
19 
20 
21 def add_path(path):
22  """Add a path to the system search path.
23  """
24  if not path in sys.path:
25  sys.path.append(path)
26  print("Adding path {} to system path.".format(path))
27 
28 
30  """Initialize Blender Python's system path with the system Python's paths.
31  """
32  try:
33  output = subprocess.check_output(
34  ["python3", "-c", "import sys; print('\\n'.join(sys.path))"])
35  paths = output.decode().strip().split('\n')
36 
37  for path in paths:
38  add_path(path)
39 
40  except subprocess.CalledProcessError:
41  print("Unable to call system Python3")
42  return ""
43 
44 
45 def find_package(package):
46  """Find a ROS package path.
47  """
48  try:
49  output = subprocess.check_output(["rospack", "find", package])
50  return output.decode().strip()
51 
52  except subprocess.CalledProcessError:
53  print("Unable to find package: `{}`".format(package))
54  return ""
55 
56 
58  """Adds the robowflex_visualization/src folder to search path.
59  """
60  directory = find_package("robowflex_visualization")
61  add_path(directory)
62 
63 
64 def load_ROS_module(module_name,
65  module_file,
66  package = "robowflex_visualization"):
67  """Load a robowflex visualization module.
68  """
69  directory = find_package(package)
70 
71  spec = importlib.util.spec_from_file_location( #
72  module_name, os.path.join(directory, module_file))
73 
74  module = importlib.util.module_from_spec(spec)
75  spec.loader.exec_module(module)
76 
77 
78 if __name__ == '__main__':
79  bpy.ops.outliner.orphans_purge()
82  load_ROS_module("robowflex", "scripts/robowflex.py")
def initialize_path()
Definition: blender.py:29
def find_package(package)
Definition: blender.py:45
def initialize_robowflex_path()
Definition: blender.py:57
def add_path(path)
Definition: blender.py:21
def load_ROS_module(module_name, module_file, package="robowflex_visualization")
Definition: blender.py:66
std::string format(const std::string &fmt, Args &&... args)
Recursion base case, return string form of formatted arguments.
Definition: log.h:60