Some functions might require the full path to a given file. If you know it's relative path to the add-in then the following could help. The below samples show how to get the add-in folder in different programming languages - these samples are based on the API online help sample: http://fusion360.autodesk.com/learning/learning.html?caaskey=caas/CloudHelp/cloudhelp/ENU/Fusion-360-API/files/ExportManager-Sample-htm.html
Python
def getAddInFolder(): import os folderPath = os.path.dirname(os.path.realpath(__file__)) return folderPath
JavaScript
function getAddInFolder() {
var url = window.location.pathname; var des = decodeURI(url); // remove the / at beginning if (navigator.platform.match('Win')) { des = des.substr(1); }
var index = des.lastIndexOf('/'); var dir = des.substring(0, index);
return dir; }
C++
std::string getAddInFolder() { #if defined(_WINDOWS) || defined(_WIN32) || defined(_WIN64) HMODULE hModule = NULL; if (!GetModuleHandleExA( GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, (LPCSTR) ≥tDllPath, &hModule)) return ""; char winTempPath[2048]; ::GetModuleFileNameA (hModule, winTempPath, 2048); std::string strPath = winTempPath; size_t stPos = strPath.rfind('\\'); return strPath.substr(0, stPos); #else Dl_info info; dladdr((void*) getDllPath, ∈fo); std::string strPath = info.dli_fname; int stPos = (int)strPath.rfind('/'); if(stPos != -1) return strPath.substr(0, stPos); else return ""; #endif }
-Adam