public override void Install(IDictionary stateSaver) { //Debugger.Launch(); // make sure addin manifest is written var assemblyFolder = Path.GetDirectoryName(Context.Parameters["assemblypath"]); var assemblyPath = Path.Combine(assemblyFolder, "RevitPythonShell.dll"); var manifest = new RevitAddInManifest(); var application = new RevitAddInApplication("RevitPythonShell", assemblyPath, Guid.Parse("3a7a1d24-51ed-462b-949f-1ddcca12008d"), "RevitPythonShell.RevitPythonShellApplication", "RIPS"); manifest.AddInApplications.Add(application); var revitProducts = RevitProductUtility.GetAllInstalledRevitProducts(); if (revitProducts.Count < 1) { throw new InvalidOperationException("No Autodesk Revit products found"); } foreach (var product in revitProducts.Where(p => p.Version == RevitVersion.Revit2012)) { manifest.SaveAs(Path.Combine(product.CurrentUserAddInFolder, "RevitPythonShell2012.addin")); } base.Install(stateSaver); }
public override void Install(IDictionary stateSaver) { // Debugger.Launch(); // make sure addin manifest is written var assemblyFolder = Path.GetDirectoryName(Context.Parameters["assemblypath"]); var assemblyPath = Path.Combine(assemblyFolder, "RevitPythonShell.dll"); var manifest = new RevitAddInManifest(); var application = new RevitAddInApplication("RevitPythonShell", assemblyPath, Guid.Parse("3a7a1d24-51ed-462b-949f-1ddcca12008d"), "RevitPythonShell.RevitPythonShellApplication", "RIPS"); manifest.AddInApplications.Add(application); var revitProducts = RevitProductUtility.GetAllInstalledRevitProducts(); if (revitProducts.Count < 1) { throw new InvalidOperationException("No Autodesk Revit products found"); } foreach (var product in revitProducts.Where(p => p.Version == RevitVersion.Revit2013)) { var manifestFolder = Context.Parameters["allusers"] == "1" ? product.AllUsersAddInFolder : product.CurrentUserAddInFolder; var manifestPath = Path.Combine(manifestFolder, "RevitPythonShell2013.addin"); manifest.SaveAs(manifestPath); } base.Install(stateSaver); }
private static RevitAddInApplication CreateRevitAddInApp(AddInAppInfo appInfo) { RevitAddInApplication myApp = new RevitAddInApplication(appInfo.Name, appInfo.Assembly, new Guid(appInfo.AddInId), appInfo.FullClassName, appInfo.VendorId); myApp.VendorDescription = appInfo.VendorDescription; return(myApp); }
public static bool Install() { if (RevitProductUtility.GetAllInstalledRevitProducts().Count == 0) { return(false); } foreach (var product in RevitProductUtility.GetAllInstalledRevitProducts()) { if (product.Version == RevitVersion.Unknown) { continue; } var addinFile = product.CurrentUserAddInFolder + "\\rubyshell.addin"; var pluginFile = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + string.Format("\\RevitRubyShell{0}.dll", product.Version); var manifest = File.Exists(addinFile) ? AddInManifestUtility.GetRevitAddInManifest(addinFile) : new RevitAddInManifest(); if (!File.Exists(pluginFile)) { MessageBox.Show(string.Format("{0} is not supported by this version of RevitRubyShell", product.Version), "RevitRubyShell", MessageBoxButton.OK, MessageBoxImage.Error); continue; } //Search manifest for app RevitAddInApplication app = null; foreach (var a in manifest.AddInApplications) { if (a.AddInId == AppGuid) { app = a; } } if (app == null) { app = new RevitAddInApplication("RevitRubyShell", pluginFile, AppGuid, AppClass, "NOSYK"); manifest.AddInApplications.Add(app); } else { app.Assembly = pluginFile; app.FullClassName = AppClass; } if (manifest.Name == null) { manifest.SaveAs(addinFile); } else { manifest.Save(); } MessageBox.Show(string.Format("RevitRubyShell for {0} was successully installed ", product.Version), "RevitRubyShell"); } return(true); }
/// <summary> /// Create a .addin manifest file when user push this button. /// The new created manifest file contains an external command and an external application. /// </summary> private void CreateAddInManifestButton_Click(object sender, EventArgs e) { RevitAddInManifest Manifest = new RevitAddInManifest(); FileInfo fileInfo = new FileInfo("..\\ExternalCommandRegistration\\ExternalCommandRegistration.dll"); //create an external application RevitAddInApplication application1 = new RevitAddInApplication( "ExternalApplication", fileInfo.FullName, Guid.NewGuid(), "Revit.SDK.Samples.ExternalCommandRegistration.CS.ExternalApplicationClass", "adsk"); //create an external command to create a wall //This command will not be visible in Revit Structure or there is no active document. //And this command will be disabled if user selected a wall. RevitAddInCommand command1 = new RevitAddInCommand( fileInfo.FullName, Guid.NewGuid(), "Revit.SDK.Samples.ExternalCommandRegistration.CS.ExternalCommandCreateWall", "adsk"); command1.Description = "A simple external command which is used to create a wall."; command1.Text = "@createWallText"; command1.AvailabilityClassName = "Revit.SDK.Samples.ExternalCommandRegistration.CS.WallSelection"; command1.LanguageType = LanguageType.English_USA; command1.LargeImage = "@CreateWall"; command1.TooltipImage = "@CreateWallTooltip"; command1.VisibilityMode = VisibilityMode.NotVisibleInStructure | VisibilityMode.NotVisibleWhenNoActiveDocument; command1.LongDescription = "This command will not be visible in Revit Structure or there is no active document."; command1.LongDescription += " And this command will be disabled if user selected a wall. "; //create an external command to show a message box //This command will not be visible in Revit MEP, Family Document or no active document. //And this command will be disabled if the active view is not a 3D view. "; RevitAddInCommand command2 = new RevitAddInCommand( fileInfo.FullName, Guid.NewGuid(), "Revit.SDK.Samples.ExternalCommandRegistration.CS.ExternalCommand3DView", "adsk"); command2.Description = "A simple external command which show a message box."; command2.Text = "@view3DText"; command2.AvailabilityClassName = "Revit.SDK.Samples.ExternalCommandRegistration.CS.View3D"; command2.LargeImage = "@View3D"; command2.LanguageType = LanguageType.English_USA; command2.VisibilityMode = VisibilityMode.NotVisibleInMEP | VisibilityMode.NotVisibleInFamily | VisibilityMode.NotVisibleWhenNoActiveDocument; command2.LongDescription = "This command will not be visible in Revit MEP, Family Document or no active document."; command2.LongDescription += " And this command will be disabled if the active view is not a 3D view. "; //add both applications and commands into addin manifest Manifest.AddInApplications.Add(application1); Manifest.AddInCommands.Add(command1); Manifest.AddInCommands.Add(command2); //save addin manifest in same place with RevitAddInUtilitySample.exe fileInfo = new FileInfo("ExteranlCommand.Sample.addin"); Manifest.SaveAs(fileInfo.FullName); AddInsInfoButton_Click(null, null); //show addins information in the tree view this.AddInsInfoButton.Enabled = true; this.OpenAddInFileButton.Enabled = true; }
public static bool Install() { if (RevitProductUtility.GetAllInstalledRevitProducts().Count == 0) { return false; } foreach (var product in RevitProductUtility.GetAllInstalledRevitProducts()) { if (product.Version == RevitVersion.Unknown) continue; var addinFile = product.CurrentUserAddInFolder + "\\rubyshell.addin"; var pluginFile = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + string.Format("\\RevitRubyShell{0}.dll", product.Version); var manifest = File.Exists(addinFile) ? AddInManifestUtility.GetRevitAddInManifest(addinFile) : new RevitAddInManifest(); if (!File.Exists(pluginFile)) { MessageBox.Show(string.Format("{0} is not supported by this version of RevitRubyShell", product.Version), "RevitRubyShell", MessageBoxButton.OK, MessageBoxImage.Error); continue; } //Search manifest for app RevitAddInApplication app = null; foreach (var a in manifest.AddInApplications) { if (a.AddInId == AppGuid) { app = a; } } if (app == null) { app = new RevitAddInApplication("RevitRubyShell", pluginFile, AppGuid, AppClass,"NOSYK"); manifest.AddInApplications.Add(app); } else { app.Assembly = pluginFile; app.FullClassName = AppClass; } if (manifest.Name == null) { manifest.SaveAs(addinFile); } else { manifest.Save(); } MessageBox.Show(string.Format("RevitRubyShell for {0} was successully installed ", product.Version), "RevitRubyShell"); } return true; }
public override void Install(IDictionary stateSaver) { // make sure addin manifest is written var assemblyFolder = Path.GetDirectoryName(Context.Parameters["assemblypath"]); var assemblyPath = Path.Combine(assemblyFolder, "RevitPythonShell.dll"); var manifest = new RevitAddInManifest(); var application = new RevitAddInApplication("RevitPythonShell", assemblyPath, Guid.NewGuid(), "RevitPythonShell.RevitPythonShellApplication"); manifest.AddInApplications.Add(application); var revitProducts = RevitProductUtility.GetAllInstalledRevitProducts(); if (revitProducts.Count < 1) { throw new InvalidOperationException("No Autodesk Revit products found"); } manifest.SaveAs(Path.Combine(revitProducts[0].CurrentUserAddInFolder, "RevitPythonShell.addin")); base.Install(stateSaver); }
private static void Main(string[] args) { try { //create a new addin manifest var manifest = new RevitAddInManifest(); #if Revit2015 var revitProduct = RevitProductUtility.GetAllInstalledRevitProducts() .FirstOrDefault(p => p.Version == RevitVersion.Revit2015); const string revitVersion = "Revit 2015"; #elif Revit2016 var revitProduct = RevitProductUtility.GetAllInstalledRevitProducts() .FirstOrDefault(p => p.Version == RevitVersion.Revit2016); const string revitVersion = "Revit 2016"; #endif if (revitProduct != null) { var addinPath = Path.Combine(revitProduct.AllUsersAddInFolder, "CzechBimLibrary.addin"); //uninstall option - delete addin file if (args.FirstOrDefault() == "-u") { if (File.Exists(addinPath)) File.Delete(addinPath); } //install addin - create addin file and save it to register the addin else { var location = typeof (DummyReference).Assembly.Location; //create an external application var id = new Guid("936A5434-1A11-484C-BFE3-A310658180B1"); var application = new RevitAddInApplication("BimLibraryApplication", location, id, "BimLibraryAddin.AddInApplication", "ADSK"); //add both command(s) and application(s) into manifest manifest.AddInApplications.Add(application); //save manifest to a file manifest.SaveAs(addinPath); //delete shared parameter file for the case its structure has been changed //if (File.Exists(Paths.SharedParamFile)) // File.Delete(Paths.SharedParamFile); } } else { if (args.FirstOrDefault() != "-u") { MessageBox.Show( "There is no " + revitVersion + " installed on your machine. Run this again after you have Revit installed.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } catch (Exception e) { MessageBox.Show( "There was an error during registration of the Add-in. Tool functionality will be affected.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); #if DEBUG var log = new ExceptionLog(); log.Add(e); string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); path = Path.Combine(path, "RevitExceptions.xml"); log.SaveToFile(path); #endif } }
public static string CreateManifest(string addinName, string version, AddInCmdInfo cmdInfo, AddInAppInfo appInfo) { string manifestFilePath = string.Format("{0}\\{1}\\{2}.addin", SystemVariables.RevitProgramDataPath, version, addinName); try { RevitAddInManifest revitAddInManifest = AddInManifestUtility.GetRevitAddInManifest(manifestFilePath); var cmds = revitAddInManifest.AddInCommands; var apps = revitAddInManifest.AddInApplications; for (int i = 0; i < cmds.Count; i++) { var cmd = cmds[i]; if (cmd.AddInId.ToString() != cmdInfo.AddInId) { revitAddInManifest.AddInCommands.Add(CreateRevitAddInCmd(cmdInfo)); } else { cmd.VendorId = cmdInfo.VendorId; cmd.VendorDescription = cmdInfo.VendorDescription; cmd.Description = cmdInfo.Description; cmd.Text = cmdInfo.Text; cmd.FullClassName = cmdInfo.FullClassName; cmd.Discipline = cmdInfo.Discipline; cmd.VisibilityMode = cmdInfo.VisibilityMode; cmd.AvailabilityClassName = cmdInfo.AvailabilityClassName; cmd.AllowLoadIntoExistingSession = cmdInfo.AllowLoadIntoExistingSession; } } for (int i = 0; i < apps.Count; i++) { var app = apps[i]; if (app.AddInId.ToString() != appInfo.AddInId) { revitAddInManifest.AddInApplications.Add(CreateRevitAddInApp(appInfo)); } else { app.Name = appInfo.Name; app.VendorId = appInfo.VendorId; app.VendorDescription = appInfo.VendorDescription; app.FullClassName = appInfo.FullClassName; app.AllowLoadIntoExistingSession = appInfo.AllowLoadIntoExistingSession; } } revitAddInManifest.Save(); } catch { try { RevitAddInManifest manifest = new RevitAddInManifest(); if (cmdInfo != null) { RevitAddInCommand myCmd = CreateRevitAddInCmd(cmdInfo); manifest.AddInCommands.Add(myCmd); } if (appInfo != null) { RevitAddInApplication myApp = CreateRevitAddInApp(appInfo); manifest.AddInApplications.Add(myApp); } //RevitProduct newRevitProduct = RevitProductUtility.GetAllInstalledRevitProducts()[0]; //string manifestFilePath = string.Format("{0}\\{1}", newRevitProduct.AllUsersAddInFolder, addinName); manifest.SaveAs(manifestFilePath); } catch (Exception ex) { return(ex.Message); } } return("创建成功"); }
private static void Main(string[] args) { try { //create a new addin manifest var manifest = new RevitAddInManifest(); #if Revit2015 var revitProduct = RevitProductUtility.GetAllInstalledRevitProducts() .FirstOrDefault(p => p.Version == RevitVersion.Revit2015); const string revitVersion = "Revit 2015"; #elif Revit2016 var revitProduct = RevitProductUtility.GetAllInstalledRevitProducts() .FirstOrDefault(p => p.Version == RevitVersion.Revit2016); const string revitVersion = "Revit 2016"; #endif if (revitProduct != null) { var addinPath = Path.Combine(revitProduct.AllUsersAddInFolder, "CzechBimLibrary.addin"); //uninstall option - delete addin file if (args.FirstOrDefault() == "-u") { if (File.Exists(addinPath)) { File.Delete(addinPath); } } //install addin - create addin file and save it to register the addin else { var location = typeof(DummyReference).Assembly.Location; //create an external application var id = new Guid("936A5434-1A11-484C-BFE3-A310658180B1"); var application = new RevitAddInApplication("BimLibraryApplication", location, id, "BimLibraryAddin.AddInApplication", "ADSK"); //add both command(s) and application(s) into manifest manifest.AddInApplications.Add(application); //save manifest to a file manifest.SaveAs(addinPath); //delete shared parameter file for the case its structure has been changed //if (File.Exists(Paths.SharedParamFile)) // File.Delete(Paths.SharedParamFile); } } else { if (args.FirstOrDefault() != "-u") { MessageBox.Show( "There is no " + revitVersion + " installed on your machine. Run this again after you have Revit installed.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } catch (Exception e) { MessageBox.Show( "There was an error during registration of the Add-in. Tool functionality will be affected.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); #if DEBUG var log = new ExceptionLog(); log.Add(e); string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); path = Path.Combine(path, "RevitExceptions.xml"); log.SaveToFile(path); #endif } }