private RevitAddInManifest GetCurrentManifest(string fullPathDll, AddInId addInId) { var dirPath = Path.GetDirectoryName(fullPathDll); //var manifestPath = Path.Combine(dirPath, addinFileName); var addins = AddInManifestUtility.GetRevitAddInManifests(dirPath, new Dictionary <string, string>()); if (addins == null || addins.Count == 0) { return(null); } RevitAddInManifest searchedAddin = null; foreach (var addin in addins) { foreach (var command in addin.AddInCommands) { var cmdId = command.AddInId; if (cmdId.Equals(addInId.GetGUID()) == false) { continue; } searchedAddin = addin; break; } if (searchedAddin != null) { break; } } //return AddInManifestUtility.GetRevitAddInManifest(manifestPath); return(searchedAddin is null ? new RevitAddInManifest() : searchedAddin); }
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); }
/// <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; }
private bool HasCommandId(RevitAddInManifest manifest, string addinId, out RevitAddInCommand command) { command = null; foreach (var cmd in manifest.AddInCommands) { if (cmd.AddInId.ToString().Equals(addinId)) { command = cmd; break; } } return(command != null); }
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); }
public void CreateAddinFile(CreateJournalSetting setting) { var fullPath = Assembly.GetAssembly(GetType()).Location; if (Guid.TryParse(setting.AddinId, out var addinGuid) == false) { throw new ArgumentException("No valid AddinId - can NOT be parsed to GUID"); } var addinId = new AddInId(addinGuid); var currentManifest = GetCurrentManifest(fullPath, addinId); if (HasCommandId(currentManifest, setting.AddinId, out var command)) { var newCommand = CreateNew(fullPath, command); var newManifest = new RevitAddInManifest(); newManifest.AddInCommands.Add(newCommand); var newManifestPath = Path.Combine(setting.DestinationDir, addinFileName); newManifest.SaveAs(newManifestPath); } }
/// <summary> /// Show AddIns information of new create manifest file in the tree view /// </summary> private void AddInsInfoButton_Click(object sender, EventArgs e) { FileInfo fileInfo = new FileInfo("ExteranlCommand.Sample.addin"); RevitAddInManifest revitAddInManifest = Autodesk.RevitAddIns.AddInManifestUtility.GetRevitAddInManifest(fileInfo.FullName); this.treeView1.Nodes.Clear(); if (revitAddInManifest.AddInApplications.Count >= 1) { TreeNode apps = this.treeView1.Nodes.Add("External Applications"); foreach (RevitAddInApplication app in revitAddInManifest.AddInApplications) { TreeNode appNode = apps.Nodes.Add(app.Name); appNode.Nodes.Add("Name: " + app.Name); appNode.Nodes.Add("Assembly: " + app.Assembly); appNode.Nodes.Add("AddInId: " + app.AddInId); appNode.Nodes.Add("Full Class Name: " + app.FullClassName); } } if (revitAddInManifest.AddInCommands.Count >= 1) { TreeNode cmds = this.treeView1.Nodes.Add("External Commands"); foreach (RevitAddInCommand cmd in revitAddInManifest.AddInCommands) { TreeNode cmdNode = cmds.Nodes.Add(cmd.Text); cmdNode.Nodes.Add("Assembly: " + cmd.Assembly); cmdNode.Nodes.Add("AddInId: " + cmd.AddInId); cmdNode.Nodes.Add("Full Class Name: " + cmd.FullClassName); cmdNode.Nodes.Add("Text: " + cmd.Text); cmdNode.Nodes.Add("Description: " + cmd.Description); cmdNode.Nodes.Add("LanguageType: " + cmd.LanguageType); cmdNode.Nodes.Add("LargeImage: " + cmd.LargeImage); cmdNode.Nodes.Add("LongDescription: " + cmd.LongDescription); cmdNode.Nodes.Add("TooltipImage: " + cmd.TooltipImage); cmdNode.Nodes.Add("VisibilityMode: " + cmd.VisibilityMode.ToString()); cmdNode.Nodes.Add("AvailabilityClassName: " + cmd.AvailabilityClassName); } } }
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 bool install() { if (RevitProductUtility.GetAllInstalledRevitProducts().Count == 0) { return(false); } foreach (RevitProduct product in RevitProductUtility.GetAllInstalledRevitProducts()) { var addinFile = product.CurrentUserAddInFolder + "\\rubyshell.addin"; var pluginFile = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + string.Format("\\RevitRubyShell{0}.dll", product.Version); 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; } RevitAddInManifest manifest; if (File.Exists(addinFile)) { manifest = AddInManifestUtility.GetRevitAddInManifest(addinFile); } else { manifest = new RevitAddInManifest(); } //Search manifest for app RevitAddInApplication app = null; foreach (RevitAddInApplication a in manifest.AddInApplications) { if (a.AddInId == APP_GUID) { app = a; } } if (app == null) { app = new RevitAddInApplication("RevitRubyShell", pluginFile, APP_GUID, APP_CLASS, "NOSYK"); manifest.AddInApplications.Add(app); } else { app.Assembly = pluginFile; app.FullClassName = APP_CLASS; } 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 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 } }
public static void CreateAddinManifest(RevitVersion revitVersion, string directory) { RevitAddInManifest revitManifest = new RevitAddInManifest(); FileInfo fileInfo = new FileInfo(Path.Combine()); }