Custom statements

I would like to make some custom statements for VC with the .net plugin. I think i need ICustomStatement, but i am not sure. I cannot find any information or examples about this. Is there anyone with an example or short explanation of how this works?

From the documentation i see that i have to use CustomStatementBase. But i am not sure how to add that to the menu and add an icon.

Hi,

Below is the basic implementation of custom statements. I stopped writing the code after I realized a major issue with this approach. The custom statement plugin will only work on application with the custom statement dll in the application folder. That means if you program a robot and then send the layout to someone, that person will not be able to open the layout with the robot program intact unless they have your custom statement dll in their application folder.

A better approach is to create a process statement on python API and then attach it to a process handler script and then write your logic in the script.

Anyway here is the basic implementation of ICustomStatement.

 

using Caliburn.Micro;
using System.ComponentModel.Composition;
using VisualComponents.Create3D;
using VisualComponents.UX.Shared;

namespace Plugin.CustomStatement
{
    public class CustomStatement : CustomPositionStatementBase
    {
        public CustomStatement()
        {
                      
        }
     
        public override void Execute(IExecutor executor)
        {
           
        }

        public override void ExecuteImmediate(IExecutor executor)
        {
          
        }
    }

    [Export(typeof(IPlugin))]
    [Export(typeof(IActionItem))]
    public class CustomStatementActionItem : ActionItem, IPlugin
    {

        public CustomStatementActionItem(): 
            base("CustomStatement", "Custom Statement", "", null, MenuTools.ButtonTool, true, true)
        {

        }
        public void Exit()
        {
            
        }

        public override void Execute()
        {
            var teach = IoC.Get<ITeachContext>();

            if (teach.ActiveScope != null)
            {
               var customStatement = teach.ActiveScope.AddStatement(typeof(CustomStatement), false);
                customStatement.Name = "My CustomStatement";
                customStatement.Executing += CustomStatement_Executing;
            }

        }

        private void CustomStatement_Executing(object sender, StatementExecutingEventArgs e)
        {
            IoC.Get<IConsoleViewModel>().AppendMessage("Executing...");
        }

        public void Initialize()
        {
            addActionItemToUI();
        }

        private void addActionItemToUI()
        {
            var cmdReg = IoC.Get<ICommandRegistry>();
            var actionItem = cmdReg.FindItem("CustomStatement");
            var item = new UXSiteSetup
            {
                UXSiteIdPath = "VcProgramStatements/ProgramStatements/Movement",
                EntryId = actionItem.Id
            };
            cmdReg.RegisterActionItem(actionItem, item);
        }
    }
}

 

 

 

Hi,

I tested Jay’s code and it works. One small thing is that executor doesn’t seem to move on to the next statement by itself. Calling executor.Continue() at the end of CustomStatement.Execute() seems to do the trick. With python process handler the behavior is different and execution continues by itself.

-k