bool LoadRhinoInsideNXGHComponent() { { var bCoff = Instances.Settings.GetValue("Assemblies:COFF", false); try { Instances.Settings.SetValue("Assemblies:COFF", false); var location = Path.Combine(RhinoInsideDirectory, "Application", "RhinoInside.NX.GH.dll"); if (!LoadGHA(location)) { if (!File.Exists(location)) { throw new FileNotFoundException("File Not Found.", location); } if (CentralSettings.IsLoadProtected(location)) { throw new InvalidOperationException($"Assembly '{location}' is load protected."); } return(false); } } finally { Instances.Settings.SetValue("Assemblies:COFF", bCoff); } } GH_ComponentServer.UpdateRibbonUI(); return(true); }
bool LoadStartupAssemblies() { // Load This Assembly as a GHA in Grasshopper { var bCoff = Instances.Settings.GetValue("Assemblies:COFF", false); try { Instances.Settings.SetValue("Assemblies:COFF", false); var location = Assembly.GetExecutingAssembly().Location; location = Path.Combine(Path.GetDirectoryName(location), Path.GetFileNameWithoutExtension(location) + ".GH.gha"); if (!LoadGHA(location)) { if (!File.Exists(location)) { throw new FileNotFoundException("File Not Found.", location); } if (CentralSettings.IsLoadProtected(location)) { throw new InvalidOperationException($"Assembly '{location}' is load protected."); } return(false); } } finally { Instances.Settings.SetValue("Assemblies:COFF", bCoff); } } var assemblyList = GetAssembliesList(); foreach (var assemblyFile in assemblyList) { bool loaded = false; string mainContent = string.Empty; string expandedContent = string.Empty; try { loaded = LoadGHA(assemblyFile); } catch (Exception e) { mainContent = e.Message; expandedContent = e.Source; } if (!loaded) { using ( var taskDialog = new TaskDialog(MethodBase.GetCurrentMethod().DeclaringType.FullName) { Title = "Grasshopper Assembly Failure", MainIcon = External.UI.TaskDialogIcons.IconError, TitleAutoPrefix = false, AllowCancellation = false, MainInstruction = $"Grasshopper cannot load the external assembly {Path.GetFileName(assemblyFile)}. Please contact the provider for assistance.", MainContent = mainContent, ExpandedContent = expandedContent, FooterText = assemblyFile } ) { taskDialog.Show(); } } } GH_ComponentServer.UpdateRibbonUI(); return(true); }
bool LoadComponents() { // Load This Assembly as a GHA in Grasshopper { var bCoff = Instances.Settings.GetValue("Assemblies:COFF", true); try { Instances.Settings.SetValue("Assemblies:COFF", false); var location = Assembly.GetExecutingAssembly().Location; if (!LoadGHA(location)) { if (!File.Exists(location)) { throw new FileNotFoundException("File Not Found.", location); } if (CentralSettings.IsLoadProtected(location)) { throw new InvalidOperationException($"Assembly '{location}' is load protected."); } return(false); } } finally { Instances.Settings.SetValue("Assemblies:COFF", bCoff); } } var assemblyFolders = new DirectoryInfo[] { // %ProgramData%\Grasshopper\Libraries-Inside-Revit-20XX new DirectoryInfo(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Grasshopper", $"Libraries-{Rhinoceros.SchemeName}")), // %APPDATA%\Grasshopper\Libraries-Inside-Revit-20XX new DirectoryInfo(Folders.DefaultAssemblyFolder.Substring(0, Folders.DefaultAssemblyFolder.Length - 1) + '-' + Rhinoceros.SchemeName) }; foreach (var folder in assemblyFolders) { IEnumerable <FileInfo> assemblyFiles; try { assemblyFiles = folder.EnumerateFiles("*.gha"); } catch (System.IO.DirectoryNotFoundException) { continue; } foreach (var assemblyFile in assemblyFiles) { bool loaded = false; string mainContent = string.Empty; string expandedContent = string.Empty; try { loaded = LoadGHA(assemblyFile.FullName); } catch (Exception e) { mainContent = e.Message; expandedContent = e.Source; } if (!loaded) { using ( var taskDialog = new TaskDialog(MethodBase.GetCurrentMethod().DeclaringType.FullName) { Title = "Grasshopper Assembly Failure", MainIcon = TaskDialogIcons.IconError, TitleAutoPrefix = false, AllowCancellation = false, MainInstruction = $"Grasshopper cannot load the external assembly {assemblyFile.Name}. Please contact the provider for assistance.", MainContent = mainContent, ExpandedContent = expandedContent, FooterText = assemblyFile.FullName } ) { taskDialog.Show(); } } } } GH_ComponentServer.UpdateRibbonUI(); return(true); }