Example of using a custom method

Hi,

Could I get an example or two of how to use the ‘custom method’ in component scripting?
I can’t seem to grasp how to utilize it.

My goal is to be able to drag-n-drop tags from a tag browser tree into a standard table component.
The standard table component doesn’t have a ‘onTagsDropped’ extention function like some other compoennts do.
So I want to add that functionality - possibly through a custom method?

Thanks

Unfortunately, no, that won’t work. Custom methods are conveniences for consolidating code for a component, with a self object available for the code, but nothing in Ignition will automatically call them. To implement onTagsDropped for a component that doesn’t natively support it would require a bunch of Java Swing hackery, if doable at all.

1 Like

@pturmel Ok, tough luck I guess. Thanks for the reply.

I’m still very interested in seeing a practial example of how to use the custom method though.

Try checking out this link, there is another link to a video from the page I’m referencing.

Probably the most common use of custom methods is to get access to self in runScript bindings. I hardly ever use those, as I can do better with my objectScript() expresssion function (part of the free Simulation Aids modules), without needing custom methods.

One big advantage is separating logic from event handling - ie, if you want a component to do the same thing on key press that it does on right click (for a contrived example) you can just have each event handler call the same custom method, to avoid duplicating logic.

Also, I thought this sounded familiar, so I did a search, and realized that I actually already did this a year ago:

3 Likes

@PGriffith Interesting :slight_smile: Would you mind sharing the code for your ‘addListener()’ custom method?
Also to make it work you need the ‘initialize()’ extension function right?

Paul did share his code – in the example project.

Ah, so he did. I missed that. Thanks.