Over the last few weeks, I’ve released several posts on learning IronPython.
- Learning IronPython
- Learning IronPython One Code Snippet at a Time
- Learning IronPython Navigating the API
The response has been extremely positive. Many users identify with the struggle to learn IronPython (and other languages) for Spotfire. One individual reached out to say that he needed more information on where/how to apply the code. I realized I’ve written that post for TERR, but I haven’t for IronPython. So, this post will explain implementing IronPython code. Let’s get to it.
Where do you put the code?
So, you found an IronPython code snippet to apply in your own DXP, but you don’t know where it goes. Perhaps, you found something on Brock’s website.
Now, unlike TERR scripts, IronPython scripts don’t run automatically. They must be triggered, usually by a button or a property control, which live in text areas. Therefore, IronPython scripts start in text areas. So, add a text area and follow the instructions below.
- First, add text area.
- Right-click and select Edit HTML. You can also select Edit Text Area.
- Then, click the insert action control button in the toolbar.
- You’ll then need to decide whether you want to click on a Button, Link or Image. Buttons are most common. Make a selection in the Control type drop down.
- Give it a name in the Display text input box.
- Now, click on the Script button on the left hand side of the dialog.
- This opens a new dialog where you want to click New.
- Name the script.
- Copy and paste the script in the script window. Make any modifications as needed.
- Add any required parameters.
- Finally, click Run Script to make sure it works.
- Click Ok.
If needed, you may edit the script from the text area going thru similar steps. Or, IronPython scripts can also be edited from the Edit — Document Properties menu.
What about Python modules?
The same user who requested this post also asked if he needed to install anything to use IronPython. He was thinking about how users install R or TERR packages to run TERR scripts. You don’t need to install anything, although you can. There are TIBCO Community posts on how to install custom python modules if you want to use your own or other modules like numpy or pandas. You can find those here and here. If you are reading this, you probably aren’t that far along. But that’s okay! There’s plenty to learn. This should get you started implementing IronPython in your own DXPs.
Content created with Spotfire 7.12.
Guest Spotfire blogger residing in Whitefish, MT. Working for SM Energy’s Advanced Analytics and Emerging Technology team!