def parseMaterialLibrary(): with _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, r'Software\META', 0, _winreg.KEY_READ | _winreg.KEY_WOW64_32KEY) as key: META_PATH = _winreg.QueryValueEx(key, 'META_PATH')[0] MATERIALLIBINTERFACEPATH = os.path.join(META_PATH, "bin", "Python27", "Lib", "site-packages") sys.path.insert(0, MATERIALLIBINTERFACEPATH) import sitecustomize from MaterialLibraryInterface import LibraryManager PATH = ctypes.c_wchar_p(chr(0x00) * 256) FOLDERID_DOCUMENTS = ctypes.c_char_p( uuid.UUID("ED4824AF-DCE4-45A8-81E2-FC7965083634").bytes_le) ctypes.windll.shell32.SHGetKnownFolderPath(FOLDERID_DOCUMENTS, 0, None, ctypes.byref(PATH)) MATERIALLIBPATH = os.path.join(PATH.value, "META Documents", "MaterialLibrary", "material_library.json") LIBRARY_MANAGER = LibraryManager(MATERIALLIBPATH) return LIBRARY_MANAGER
from MaterialLibraryInterface import LibraryManager import getpass import uuid import ctypes import os if __name__ == "__main__": #run only if main #get path to public documents path = ctypes.c_wchar_p(chr(0x00) * 256) FOLDERID_Documents = ctypes.c_char_p( uuid.UUID("ED4824AF-DCE4-45A8-81E2-FC7965083634").bytes_le) ctypes.windll.shell32.SHGetKnownFolderPath(FOLDERID_Documents, 0, None, ctypes.byref(path)) libraryLocation = os.path.join(path.value, "META Documents", "MaterialLibrary", "material_library.json") library_manager = LibraryManager(libraryLocation) username = raw_input("Username: "******"Password: ") matList = library_manager.updateJSON(username, password)
""" This file is a demo for the LibraryManager methods and demonstrates their usage. Many of the print statements are commented out, so that you can comment them back in and see what they do. """ if __name__ == "__main__": #run only if main """ First, we need to create a LibraryManager object. We'll call it "library_manager" so that we know what it is. The parameter passed to it is the location of the .json document. """ library_manager = LibraryManager() """ This class has a number of methods we'll demonstrate. The first method of importance is the materialData method, which takes as a parameter a string representing the name of the material for which you need data. """ steelData = library_manager.materialData("steel_stainless_316_l") """ The steelData variable now contains all the data about the steel_stainless_316_l material. As it stands, it isn't incredibly useful to us. We need to iterate through the data structure to extract the useful information. """ #pprint(steelData)