Is there a clean way to access package path(s) from inside python node?
I’m currently using AddReference to find the location and version and then build the path based on that. I think I found it in a github issue. It works fine as far as the user installs all the packages in the default folder but won’t work if someone installs the package in some custom location.
import os
appDataPath = os.getenv('APPDATA')
dynPath = appDataPath + r"\Dynamo\0.9"
if dynPath not in sys.path:
sys.path.Add(dynPath)
bbPath = appDataPath + r"\Dynamo\0.9\packages\Bumblebee\extra"
if bbPath not in sys.path:
try:
sys.path.Add(bbPath)
import bumblebee as bb
except:
import xml.etree.ElementTree as et
root = et.parse(dynPath + "\DynamoSettings.xml").getroot()
for child in root:
if child.tag == "CustomPackageFolders":
for path in child:
path_bb = path.text + "\Bumblebee\extra"
if path not in sys.path:
sys.path.Add(path_bb)
import bumblebee as bb
hmm I would request this on github, perhaps we can expose it through DynamoServices - … but could you explain why you’d want to do this? Do you need your python node to access some data inside your package folder?
for now I think the fastest is to do as Konrad suggests and parse the xml file…
or if you are feeling brave you can try constructing a Dynamo model inside your python scope - If you construct another Dynamo model inside Dynamo… I am not sure what will happen :P… but you can then access the path manager which should have parsed the xml file…