Disappearing Button in Python Script after executing .net Addon

Hello,
I have a small addon in .net which changes the author and description of a file. See attatchment.

To start the addon I took a python template from the tutorial. See files.
Once I start the application it seems that the addon is already executed the first time and after pressing the button to execute my TestCommand the button disappears and I don’t know why. What am I doing wrong?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ComponentModel.Composition;
using Caliburn.Micro;
using VisualComponents.Create3D;
using VisualComponents.UX.Shared;


namespace TestPlugin
{
    //action or netCommand
[Export(typeof(IActionItem))]
public class MyTest : ActionItem
{
    //[Import]
    //private Lazy<IApplication> app = null;
    public MyTest() : base("TestCommand")
    {

    }

    public override void Execute()
    {
        IApplication app = IoC.Get<IApplication>();
        ISimWorld sim = app.World;
        sim.LayoutMetadata.Author = "TEST";
        sim.LayoutMetadata.Description = "Hello";
        IMessageService ms = IoC.Get<IMessageService>();
        ms.AppendMessage(sim.LayoutMetadata.Author, MessageLevel.Warning);
    }
}

//plugin calling my action
[Export(typeof(IPlugin))]
public class MyPlugin : IPlugin
{
    void IPlugin.Exit()
    {
    }

    void IPlugin.Initialize()
    {
        ICommandRegistry cr = IoC.Get<ICommandRegistry>();
        cr.ExecuteAction("TestCommand");
    }
}
}

Plugin.TestPlugin.dll (4.5 KB) Plugin.TestPlugin.pdb (19.5 KB)

init.py|attachment (1.4 KB) Hello PDV.py (357 Bytes) PyResource.German.xaml (1020 Bytes) ShowContextualRibbonTab.py (276 Bytes)

Have you tried to call executeInActionPanel() again after you execute the other command? That might reopen the panel again. I guess executing a command closes other commands…

Unfortunately that didn’t work. The Button is still gone after the first execution

Hi,

I had a very similar issue. In my case an Action Panel linked to my command disappeared when my command called an other command during its own execution.

Indeed, when a command is executed, it closes other running commands. By default, a command is executed with execution type set to VC_COMMAND_NORMAL, which involves abortion of all active commands. Setting the execution type to VC_COMMAND_TOOL would rather suspend all active commands during execution, and resume them afterwards. I tried to enforce this execution mode by triggering the command in question by executeAsTool() instead of execute(). However, it did not seem to make any difference in my case.

The suggestion of @ccamilo did work for me, I called executeInActionPanel() again, and my action panel reappeared. It disappeared temporarily during execution of the intermediate command though.

My code looks now like the following snippet. Once I run my command, it opens an Action Panel at the right side of the Visual Components UI, displaying a button labeled ‘Open File’. When I click this button, the function open_file(args) is called as callback tied to the button. This function calls the predefined command dialogOpen that opens a dialog window to browse for a file. While that is happening, my Action Panel disappears, but when I browsed for a file it reappears, due to addition of executeInActionPanel() in the code again:

def my_command()
    print('implementation of my command')
    executeInActionPanel()


def open_file(args):
    opencmd = app.findCommand("dialogOpen")
    opencmd.execute()
    executeInActionPanel()
    

app = getApplication()
cmd = getCommand()

addState(my_command)

btn_open_file = cmd.createProperty(VC_BUTTON, 'Open File')
btn_open_file.OnChanged = open_file

I suggest to read the following sections of the Python API documentation:
Constants > Command Constants
vcCommand > Methods > execute, executeAsTool, executeInActionPanel

1 Like