Access Dynamo's Package Paths from Python

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 clr
		clr.AddReference('DynamoCore')
		_loc = clr.References[2].Location
		_ver = _loc.split('\\')[-2].split(' ')[-1]

I have been doing this:


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
2 Likes

Thanks! I’m looking for a solution to access it form Dynamo Configuration. Here is the PathManager class.

Looks like the things that you need are public so you should be able to access them. Let us know if you can figure this out. :slight_smile:

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…