Community
Vault Customization
Share your knowledge, ask questions, and explore popular Vault API, Data Standard, and VBA topics related to programming, creating add-ins, or working with the Vault API.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How can I run a command from onlogon

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
meatall
468 Views, 7 Replies

How can I run a command from onlogon

meatall
Participant
Participant

I wrote a command and run it by pressing a button. How can I run it from OnLogOn?

0 Likes

How can I run a command from onlogon

I wrote a command and run it by pressing a button. How can I run it from OnLogOn?

7 REPLIES 7
Message 2 of 8
Nick_Hall
in reply to: meatall

Nick_Hall
Advocate
Advocate

Hi

 

From your brief description, it sounds like you need to use the OnLogOn method

 

Here's a screenshot from the Vault API help

Nick_Hall_0-1718048790992.png

The HelloWorld sample in the SDK contains the template for the method (but no actual code in it)

 

Hope that helps

Nick

 

0 Likes

Hi

 

From your brief description, it sounds like you need to use the OnLogOn method

 

Here's a screenshot from the Vault API help

Nick_Hall_0-1718048790992.png

The HelloWorld sample in the SDK contains the template for the method (but no actual code in it)

 

Hope that helps

Nick

 

Message 3 of 8
meatall
in reply to: Nick_Hall

meatall
Participant
Participant

Yes, thanks, I know that. But I don't understand how to call the command specifically from OnLogOn. I could run the written CommandHandler(CommandItem, CommandItemEventArgs). But I don't know how to receive CommandItemEventArgs at the moment of OnLogOn to pass it to CommandHandler.

0 Likes

Yes, thanks, I know that. But I don't understand how to call the command specifically from OnLogOn. I could run the written CommandHandler(CommandItem, CommandItemEventArgs). But I don't know how to receive CommandItemEventArgs at the moment of OnLogOn to pass it to CommandHandler.

Message 4 of 8
Nick_Hall
in reply to: meatall

Nick_Hall
Advocate
Advocate

Hi

 

Now I understand your question better

 

You can't use CommandItemEventArgs because the OnLogOn event doesn't have one

 

This is due to when the event occurs, immediately after the user has logged in, but before the UI is initialised

 

Because the UI has not initialised, there's no Context to pass into the event - all you have is the iApplication, which is the same as CommandItemEventArgs.Context.Application

 

If your command only uses CommandItemEventArgs.Context.Application, you can replace it directly, but if you use any other members of CommandItemEventArgs.Context, you'll need to look at another way of calling it

 

If you can tell me roughly what your command does, I might be able to suggest something

 

Hope that helps

Nick

 

0 Likes

Hi

 

Now I understand your question better

 

You can't use CommandItemEventArgs because the OnLogOn event doesn't have one

 

This is due to when the event occurs, immediately after the user has logged in, but before the UI is initialised

 

Because the UI has not initialised, there's no Context to pass into the event - all you have is the iApplication, which is the same as CommandItemEventArgs.Context.Application

 

If your command only uses CommandItemEventArgs.Context.Application, you can replace it directly, but if you use any other members of CommandItemEventArgs.Context, you'll need to look at another way of calling it

 

If you can tell me roughly what your command does, I might be able to suggest something

 

Hope that helps

Nick

 

Message 5 of 8
meatall
in reply to: Nick_Hall

meatall
Participant
Participant

Hello! My command runs AcquireFiles. The user has a configuration file that specifies which files and where to upload them. I rewrote this command based on Hello World. Also, the command only becomes available if the user selects a file, although it is not used in the command. This is probably wrong

0 Likes

Hello! My command runs AcquireFiles. The user has a configuration file that specifies which files and where to upload them. I rewrote this command based on Hello World. Also, the command only becomes available if the user selects a file, although it is not used in the command. This is probably wrong

Message 6 of 8
meatall
in reply to: meatall

meatall
Participant
Participant

Here is my code:

public IEnumerable<CommandSite> CommandSites()
        {
            CommandItem helloWorldCmdItem = new CommandItem("HelloWorldCommand", "BackUp files")
            {
                NavigationTypes = new SelectionTypeId[] { SelectionTypeId.File, SelectionTypeId.FileVersion, SelectionTypeId.Folder },

                MultiSelectEnabled = false
            };

            helloWorldCmdItem.Execute += FileDownloadCommandhandler;

            CommandSite toolbarCmdSite = new CommandSite("HelloWorldCommand.Toolbar", "Hello World Menu")
            {
                Location = CommandSiteLocation.AdvancedToolbar,
                DeployAsPulldownMenu = false
            };
            toolbarCmdSite.AddCommand(helloWorldCmdItem);

            List<CommandSite> sites = new List<CommandSite>();
            sites.Add(toolbarCmdSite);

            return sites;
        }

        public IEnumerable<DetailPaneTab> DetailTabs()
        {
            List<DetailPaneTab> fileTabs = new List<DetailPaneTab>();

            DetailPaneTab filePropertyTab = new DetailPaneTab("File.Tab.PropertyGrid", "Selection Info", SelectionTypeId.File,
                                                        typeof(VaultFileCopyOfSheduleTabControl));

            filePropertyTab.SelectionChanged += propertyTab_SelectionChanged;
            fileTabs.Add(filePropertyTab);

            DetailPaneTab folderPropertyTab = new DetailPaneTab("Folder.Tab.PropertyGrid", "Selection Info",
                SelectionTypeId.Folder, typeof(VaultFileCopyOfSheduleTabControl));

            folderPropertyTab.SelectionChanged += propertyTab_SelectionChanged;
            fileTabs.Add(folderPropertyTab);

            DetailPaneTab itemPropertyTab = new DetailPaneTab("Item.Tab.PropertyGrid", "Selection Info",
                                                        SelectionTypeId.Item,
                                                        typeof(VaultFileCopyOfSheduleTabControl));

            itemPropertyTab.SelectionChanged += propertyTab_SelectionChanged;
            fileTabs.Add(itemPropertyTab);

            DetailPaneTab coPropertyTab = new DetailPaneTab("Co.Tab.PropertyGrid", "Selection Info",
                                                        SelectionTypeId.ChangeOrder,
                                                        typeof(VaultFileCopyOfSheduleTabControl));

            coPropertyTab.SelectionChanged += propertyTab_SelectionChanged;
            fileTabs.Add(coPropertyTab);

            return fileTabs;
        }


        void FileDownloadCommandhandler(object s, CommandItemEventArgs e)
        {
            Connection connection = e.Context.Application.Connection;

            try
            {
                if (startFromButton == true && backupFileOfExplorer == false)
                {
                    AnalyzeTXTFile(connection);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message);
            }
        }

        void AnalyzeTXTFile(Connection connection)
        {
            //read config txt file
            GetTheFile(connection, file);
        }

        public void GetTheFile(Connection connection, File file)
        {
            var acquireSettings = new VDF.Vault.Settings.AcquireFilesSettings(connection);

            if (pathToCopy != null)
            {
                acquireSettings.LocalPath = new VDF.Currency.FolderPathAbsolute(pathToCopy);
            }
            else
            {
                acquireSettings.LocalPath = new VDF.Currency.FolderPathAbsolute(@"C:\TestBackUp");
            }
            acquireSettings.AddFileToAcquire(new VDF.Vault.Currency.Entities.FileIteration(connection, file),
                VDF.Vault.Settings.AcquireFilesSettings.AcquisitionOption.Download);

            VDF.Vault.Results.AcquireFilesResults results = connection.FileManager.AcquireFiles(acquireSettings);
        }

 

0 Likes

Here is my code:

public IEnumerable<CommandSite> CommandSites()
        {
            CommandItem helloWorldCmdItem = new CommandItem("HelloWorldCommand", "BackUp files")
            {
                NavigationTypes = new SelectionTypeId[] { SelectionTypeId.File, SelectionTypeId.FileVersion, SelectionTypeId.Folder },

                MultiSelectEnabled = false
            };

            helloWorldCmdItem.Execute += FileDownloadCommandhandler;

            CommandSite toolbarCmdSite = new CommandSite("HelloWorldCommand.Toolbar", "Hello World Menu")
            {
                Location = CommandSiteLocation.AdvancedToolbar,
                DeployAsPulldownMenu = false
            };
            toolbarCmdSite.AddCommand(helloWorldCmdItem);

            List<CommandSite> sites = new List<CommandSite>();
            sites.Add(toolbarCmdSite);

            return sites;
        }

        public IEnumerable<DetailPaneTab> DetailTabs()
        {
            List<DetailPaneTab> fileTabs = new List<DetailPaneTab>();

            DetailPaneTab filePropertyTab = new DetailPaneTab("File.Tab.PropertyGrid", "Selection Info", SelectionTypeId.File,
                                                        typeof(VaultFileCopyOfSheduleTabControl));

            filePropertyTab.SelectionChanged += propertyTab_SelectionChanged;
            fileTabs.Add(filePropertyTab);

            DetailPaneTab folderPropertyTab = new DetailPaneTab("Folder.Tab.PropertyGrid", "Selection Info",
                SelectionTypeId.Folder, typeof(VaultFileCopyOfSheduleTabControl));

            folderPropertyTab.SelectionChanged += propertyTab_SelectionChanged;
            fileTabs.Add(folderPropertyTab);

            DetailPaneTab itemPropertyTab = new DetailPaneTab("Item.Tab.PropertyGrid", "Selection Info",
                                                        SelectionTypeId.Item,
                                                        typeof(VaultFileCopyOfSheduleTabControl));

            itemPropertyTab.SelectionChanged += propertyTab_SelectionChanged;
            fileTabs.Add(itemPropertyTab);

            DetailPaneTab coPropertyTab = new DetailPaneTab("Co.Tab.PropertyGrid", "Selection Info",
                                                        SelectionTypeId.ChangeOrder,
                                                        typeof(VaultFileCopyOfSheduleTabControl));

            coPropertyTab.SelectionChanged += propertyTab_SelectionChanged;
            fileTabs.Add(coPropertyTab);

            return fileTabs;
        }


        void FileDownloadCommandhandler(object s, CommandItemEventArgs e)
        {
            Connection connection = e.Context.Application.Connection;

            try
            {
                if (startFromButton == true && backupFileOfExplorer == false)
                {
                    AnalyzeTXTFile(connection);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message);
            }
        }

        void AnalyzeTXTFile(Connection connection)
        {
            //read config txt file
            GetTheFile(connection, file);
        }

        public void GetTheFile(Connection connection, File file)
        {
            var acquireSettings = new VDF.Vault.Settings.AcquireFilesSettings(connection);

            if (pathToCopy != null)
            {
                acquireSettings.LocalPath = new VDF.Currency.FolderPathAbsolute(pathToCopy);
            }
            else
            {
                acquireSettings.LocalPath = new VDF.Currency.FolderPathAbsolute(@"C:\TestBackUp");
            }
            acquireSettings.AddFileToAcquire(new VDF.Vault.Currency.Entities.FileIteration(connection, file),
                VDF.Vault.Settings.AcquireFilesSettings.AcquisitionOption.Download);

            VDF.Vault.Results.AcquireFilesResults results = connection.FileManager.AcquireFiles(acquireSettings);
        }

 

Message 7 of 8
Nick_Hall
in reply to: meatall

Nick_Hall
Advocate
Advocate
Accepted solution

Hi

 

In your command handler (FileDownloadCommandhandler), your code is essentially this

 

void FileDownloadCommandhandler(object s, CommandItemEventArgs e)
{
  Connection connection = e.Context.Application.Connection;
  AnalyzeTXTFile(connection);
}

 

To achieve the same thing in the OnLogOn method you would need this code

public void OnLogOn(IApplication application)
{
  Connection connection = application.Connection;
  AnalyzeTXTFile(connection);
}

 

That should get your AnalyzeTXTFile function running at the right point, and it should be relatively smooth from there

 

Nick

Hi

 

In your command handler (FileDownloadCommandhandler), your code is essentially this

 

void FileDownloadCommandhandler(object s, CommandItemEventArgs e)
{
  Connection connection = e.Context.Application.Connection;
  AnalyzeTXTFile(connection);
}

 

To achieve the same thing in the OnLogOn method you would need this code

public void OnLogOn(IApplication application)
{
  Connection connection = application.Connection;
  AnalyzeTXTFile(connection);
}

 

That should get your AnalyzeTXTFile function running at the right point, and it should be relatively smooth from there

 

Nick

Message 8 of 8
meatall
in reply to: Nick_Hall

meatall
Participant
Participant

Yes it works, thanks!

0 Likes

Yes it works, thanks!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report