How to excute when button controltype is 'ExToggleButton'

    [Export(typeof(IPlugin))]
[Export(typeof(IActionItem))]
public class DebugAction : ActionItem, IPlugin, IHandle<ManipulationModeChangedMessage>
{
    private bool _canExecute;
    public new bool CanExecute
    {
        get { return _canExecute; }
        set
        {
            if (CanExecute != value)
            {
                _canExecute = value;
                NotifyOfPropertyChange("CanExecute");
            }
        }
    }
    public DebugAction() : base("DEBUG_ID", Translator.Get("DEBUG"), Package.IconPath + "DEBUG.svg", null, MenuTools.ButtonTool, false, true)
    {
        ActionID = Id;
        CanExecute = true;
        ToolTipContent = Translator.Get("DEBUG");
        ControlType = "ExToggleButton";
        //EvaluateCanExecute();
        AttachTo = "[Event Click] = [Action Execute]";
    }

    public override void Execute()
    {
        IoC.Get<ICommandRegistry>().Actions.FirstOrDefault(x => x.Id == "DebugAction").Execute();
    }

    public void Initialize()
    {

    }

    public void Exit()
    {
        //throw new NotImplementedException();
    }

    public void Handle(ManipulationModeChangedMessage message)
    {
        throw new NotImplementedException();
    }

    public static string ActionID { get; set; }
}

If I set controltype to ‘ExToggleButton’, Event Click didn’t work. Which event trigger when click ExToggleButton.

Toggle is considered a boolean just like a check box, so it is a type of ActionItem.

[Export(typeof(IActionItem))]
[PartCreationPolicy(CreationPolicy.Shared)]
public class MyAction : ActionItem<Boolean>
{
    public MyAction() : base("exampleToggle", "Stankonia", "", null, MenuTools.ExToggleButton)
    {
        AttachTo = "[Shortcut Control + F2] = [Action Execute]; [Event Click] = [Action Execute]";
        this.IsChecked = true;
    }

    private bool isChecked = false;
    public bool IsChecked
    {
        get { return isChecked; }
        set { isChecked = value; NotifyOfPropertyChange(); }
    }
    public override void Execute(bool isChecked)
    {
        IMessageService ms = IoC.Get<IMessageService>();
        ms.AppendMessage(isChecked.ToString(), MessageLevel.Warning);
    }

image

1 Like

Thank you, it works.
Now I want to delivery PropertyCollection, but I don’t know how to define ‘IProperty’.

    [Export(typeof(IPlugin))]
[Export(typeof(IActionItem))]
public class DebugAction : ActionItem<Boolean>, IPlugin, IHandle<ManipulationModeChangedMessage>
{
    private bool _canExecute;
    public new bool CanExecute
    {
        get { return _canExecute; }
        set
        {
            if (CanExecute != value)
            {
                _canExecute = value;
                NotifyOfPropertyChange("CanExecute");
            }
        }
    }

    private bool _isChecked = false;
    public bool IsChecked
    {
        get { return _isChecked; }
        set { _isChecked = value; NotifyOfPropertyChange(); }
    }

    public DebugAction() : base("DEBUG_ID", Translator.Get("DEBUG"), Package.IconPath + "DEBUG.svg", null, MenuTools.ExToggleButton, false, true)
    {
        ActionID = Id;
        CanExecute = true;
        ToolTipContent = Translator.Get("DEBUG");
        //ControlType = "ExToggleButton";
        //EvaluateCanExecute();
        AttachTo = "[Event Click] = [Action Execute]";
    }


    public override void Execute(bool IsChecked)
    {
        List<IProperty> propertyList = new List<IProperty>();
        var fixedPropertyContainer = new FixedPropertyContainer();
        IProperty property = fixedPropertyContainer.CreateProperty(typeof(bool), PropertyConstraintType.NotSpecified);
        property.Value = IsChecked;
        propertyList.Add(property);
        var propertyCollection = new PropertyCollection(propertyList);
        //IoC.Get<ICommandRegistry>().Actions.FirstOrDefault(x => x.Id == "DebugAction").Execute();//new PropertyCollection(new IEnumerable<IProperty>(new IProperty()))

        //List<IProperty> propertyList = new List<IProperty>();
        //propertyList.
        //var propertyCollection = new PropertyCollection();
        //var items = propertyCollection.GetValue("Items");
        IoC.Get<ICommandRegistry>().ExecuteAction("DebugAction", propertyCollection);
    }

    public void Initialize()
    {

    }

    public void Exit()
    {
        //throw new NotImplementedException();
    }

    public void Handle(ManipulationModeChangedMessage message)
    {
        throw new NotImplementedException();
    }

    public static string ActionID { get; set; }
}

My understanding is IProperty objects need to be associated with object known to world. And creating list or container independently of world and trying to use it for creating IProperty objects is restricted. But others who know the code better can comment on best approach for creating and use property containers.

What I did in this example is show two examples of creating and associating property with component object and layout item object.

public override void Execute(bool isChecked)
{
    IApplication app = IoC.Get<IApplication>();
    ISimComponent comp = app.CreateComponent("Test");
    IProperty property = comp.CreateProperty(typeof(bool), PropertyConstraintType.NotSpecified, "Prop1");
    property.Value = isChecked;

    IMessageService ms = IoC.Get<IMessageService>();
    ms.AppendMessage(property.Value.ToString(), MessageLevel.Warning);

    ILayoutPropertyList layout_item = app.World.CreateLayoutItem<ILayoutPropertyList>("test");
    IProperty other_prop = layout_item.CreateProperty(typeof(string), PropertyConstraintType.NotSpecified, "Prop2");
    other_prop.Value = "Pepe Lopez";
    ms.AppendMessage(other_prop.Value.ToString(), MessageLevel.Warning);

    PropertyCollection container = new PropertyCollection();
    container.Add(property);
}

In .NET API exist a method ‘ExcuteAction(key,PropertyCollection)’ , but it occur error when delivery PropertyCollection. I don’t know how to use this method.

I want to delivery parameters to other command, how to do?

Never used that method, so I don’t know. I do know that Execute(PropertyCollection args) is meant for Python calls that execute the action, for example when using netCommand. Execute() is always used when action is triggered via UI.

Execute(PropertyCollection args)

  • When I add arguments to Execute, I get a syntax error.
    image
    The Execute method of the query ActionItem also has no arguments

Please show me how I should implement the python script. NETComand pass parameters?

I should really look into this, https://www.buymeacoffee.com/

You are asking the right questions. When using netCommand in script, the action item Execute(PropertyCollection args) method is called. So in the script, pass the required amount of arguments and handle those arguments as IProperty objects in the .NET side.

There is brief mention in Help file about this. SDK examples are available, but I think they are not shared on this forum. You would need to ask support for those.

  • Thank you very much for your reply and help!

First of all, please forgive my increasing demands. Can I do that if I want to return a value from a.NET function? Check the API, can by ExecutePythonCommandMethod function,
bool ExecutePythonCommandMethod(string commandName, string methodName, string[] arguments, out object result);

but can’t find the corresponding example, convenient to give guidance? thank you