Programmatically firing an action

Hi guys,

I am working on a module with a couple of blocks, I have block A accepting a string, when the string changes I fire the onExecute method and I would like to do a couple of things.

  1. pass the string value to block B
  2. invoke an action on block B

Just wondering if this is possible and if anyone can share some example code to give me a hint on how I can achieve this.

Thanks in advance for you time guys, have a great day.

A module or program object?

If this is a program object, you when you add a slot, you can select “execute on change” This will trigger the onExecute method in the program object.

If this is a module and you’re extending from BComponentt, you can use the doExecute or Changed method

I can send you an example when I can sit down.

Hi @Charles_Johnson, it is a module I am working on. I have the module working with both blocks in the palette and I can drop them on the wire sheet.
What I want to know is, can I trigger an action pin on block B if for example the string value of block A is equal to a certain value?
Appreciate any help you can offer, thanks.

You may be better off making this a topic slot vs an action slot.

Sorry for late responses. I’m doing some custom training but I should be able to type out a full response.

I’ll think about this more after class today. And I’ll get back to you.

1 Like

Sounds like 1 and 2 can be done in a single action:

you want something like this:

  1. make an action slot named sendInt
  2. add a parameter to the input.
private BInteger i;

public void onSendInt(BInteger i) throws Exception
{ 
    this.i = i; //sets global int to the value of incoming int

}

In this case, executing the action manually prompts a user input. If the action is executed programatically (onSendInt(10)), then it will fire the a trigger as well as send the “10” to whatever the set is connected to.
Remember that the sending and receiving action slot also needs to take BInteger is a parameter input.
I did this with a BInteger but you can simply switch to BString. I sent the integer example as i have used it before and can confirm that it works.

1 Like

This sounds about right. Sorry, been entertaining a potentially huge customer. I was thinking of using the onExecute to do something which then fires a topic slot, to connect to an action on another object.

Did you get your answer? If its a module, id suggest using a topic and pass the string with the topic. Otherwise you’d have to setup links

2 Likes

That’s correct. Completely agree

Guys,

Thanks for all your help, I have managed to get it working as @Boba suggested with a topic firing an action on the other block, had to leave it there on Thursday but back on it tomorrow and will modify the code to pass the string over.
Will I pass the string as a parameter form my topic and accept a string as a parameter on my action on the other block? How do you define these parameters so slotomatic can do its stuff?
Thanks everyone for your help so far :folded_hands: :grin:

1 Like

Can find this in the niagara docs module://docDeveloper/doc/slot-o-matic.html#niagara-annotations

@NiagaraAction

/**
 *  This is my action.  This comment will be included in the slot definition. Please note that this is a javaDoc comment.
 */
@NiagaraAction
(
  name = "myOnlyAction",                        //REQUIRED Name of the action.
  flags = Flags.HIDDEN,                         //Any flags the action my have. Note that multiple flags are grouped together with the "|" symbol.
  parameterType = "baja:RelTime",               //Parameter type of the action. Supports "Module:Type" typespec format (preferred) or full name. Example: "baja:RelTime" or "BRelTime" are valid.
  defaultValue = "BRelTime.makeSeconds(5)",     //The default value of the action.
  returnType = "baja:RelTime",     //Return type of the action. Supports "Module:Type" typespec format (preferred) or full name. Example: "baja:RelTime" or "BRelTime" are valid.
  facets =                                      //Any facets that the action may have.  The facet annotation works as a name-value pair.
  {
    @Facet(name = "BFacets.MIN", value = "BRelTime.makeSeconds(0)"),
    @Facet(name = "BFacets.MAX", value = "BRelTime.makeSeconds(60)")
  }
)

A @NiagaraAction annotation defines a single Action on a BComplex. A BComplex can have any number of actions, each declared in a separate @NiagaraAction annotation.

A @NiagaraAction annotation has the following attributes, in addition to the standard attributes detailed above:

  • parameterType: The type of the action’s single argument, as a String. Optional. If left blank, the action is assumed to take no argument. This can be a Baja typespec, a Class name, or a Java primitive.
  • returnType: The type of the value returned by the action. Optional. If left blank, the action is assumed to return “void”. This can be a Baja typespec, a Class name, or a Java primitive.
  • defaultValue: The default value for the action parameter. Required for actions which take a parameter.

@NiagaraTopic

/**
 *  This is my topic.  This comment will be included in the slot definition. Please note that this is a javaDoc comment.
 */
@NiagaraTopic
(
  name = "myFirstTopic",                //REQUIRED Name of the topic.
  flags = Flags.USER_DEFINED_1,         //Any flags the topic my have. Note that multiple flags are grouped together with the "|" symbol.
  eventType = "int",        //Event type of the topic. Supports "Module:Type" typespec format (preferred) or full name. Example: "baja:RelTime" or "BRelTime" are valid.
  facets =                              //Any facets that the topic may have.  The facet annotation works as a name-value pair.
  {
    @Facet(name = "BFacets.MIN", value = "1"),
    @Facet(name = "BFacets.MAX", value = "40")
  }
)

A @NiagaraTopic annotation defines a single Topic of a BComplex. A BComplex can have any number of topics, each declared in a separate @NiagaraTopic annotation.

A @NiagaraTopic annotation has the following attribute, in addition to the standard attributes detailed above:

  • eventType: Event type for the topic, as a String. Optional. If left blank, defaults to “void”. This can be a Baja typespec, a Class name, or a Java primitive.
1 Like

Hi guys,
Thanks for all your help, with @Boba ‘s suggestion and the input from @Giantsbane I managed to pass my string value from my topic slot on one block to my action shot on another all through the single link.

2 Likes

Fuck yeah! Nice one @gerrypm

All I need to figure out now are some rules for dropping the two blocks, one is actually a service so that is easy but the other needs to go on the wiresheet but only allow the drop if the service is installed, then a bit of auto-linking and we are away for some load testing.

1 Like