Ejemplo n.º 1
0
        private RevitAddInCommand CreateNew(string fullDllPat, RevitAddInCommand current)
        {
            var newCommand = new RevitAddInCommand(
                fullDllPat, current.AddInId, current.FullClassName, current.VendorId);

            return(newCommand);
        }
Ejemplo n.º 2
0
        /// <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;
        }
Ejemplo n.º 3
0
 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);
 }
Ejemplo n.º 4
0
        private static RevitAddInCommand CreateRevitAddInCmd(AddInCmdInfo cmdInfo)
        {
            RevitAddInCommand myCmd = new RevitAddInCommand(cmdInfo.Assembly, new Guid(cmdInfo.AddInId), cmdInfo.FullClassName, cmdInfo.VendorId);

            myCmd.Description                  = cmdInfo.Description;
            myCmd.Text                         = cmdInfo.Text;
            myCmd.FullClassName                = cmdInfo.FullClassName;
            myCmd.Discipline                   = cmdInfo.Discipline;            //在什么样的程序模式下的命令按钮显示,程序命令模式如结构、设备……
            myCmd.VisibilityMode               = cmdInfo.VisibilityMode;        //在文档模式改变时命令按钮显示的方式
            myCmd.AvailabilityClassName        = cmdInfo.AvailabilityClassName; //验证程序名称
            myCmd.AllowLoadIntoExistingSession = cmdInfo.AllowLoadIntoExistingSession;
            myCmd.VendorDescription            = cmdInfo.VendorDescription;
            return(myCmd);
        }
Ejemplo n.º 5
0
        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("创建成功");
        }
Ejemplo n.º 6
0
        /// <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;
        }