Create dataset from a function

Hi all,

I am very new to Ignition and scripting so I am learning on multiple fronts. I am working on a sample project just to learn.

I want to split the results of system.project.getProjectNames() into a single column dataset.

I thought I would use split() to do this but have not been able to.

I ultimately want to this dataset on a dropdown to select a project to retarget.

All help and advice is much appreciated.

Thanks, Steven

That function returns a list of names (an array in other language terms).
To convert to a dataset to use on a dropdown you need to add each element into a dimensional list, in this case a single dimensional list. Think, if you have multiple columns in your table, you would have multiple dimensions to the table list.

projectNames = system.project.getProjectNames() 
data=[[projectName] for projectName in projectNames] 
ds = system.dataset.toDataSet(['projectName'], data)
dropDownObj.data = ds

I’m guessing projectMames will give you some trouble. :grinning:

Problem solved.

1 Like

I would blame autocucumber, but I think it was more anti-dexterous fingers

1 Like

This is what I want to do. How do I get this dataset bound the dataset property on the dropdown?

Do I need to create a DB table?

Sorry for the fundamental questions but this is very new to me.

Thanks, Steven

Vision or Perspective?

I’m sorry, Vivion

thanks, steven

I would put it in the window's InternalFrameActivated event. This event fires each time the window is activated.

@JordanCClark that sounds like a good idea. Now if I new how to do that, that would be great.

InternalFrameActivated is not on the scripting event handler list for the main window or the component.

How would I go about doing this?

Thanks, teven

https://docs.inductiveautomation.com/display/DOC80/Component+Events

Right-click on the window name in the project tree. Note: The window has to be open, or it will be greyed out.


@JordanCClark thank you for the help! The dropdown component does not have the internalFrame event handlers.

Am I missing something? This is version 8.0.16

I tried using the mouseClicked and received this error.

image

Seems this would be a solution for this object but I must have something set wrong.

Again, thanks for the help and for showing I can put images int he forum.

Thanks, Steven

You’ll need to access dropDownObj via event.source.getComponent("dropDownObj").data or something similar. The easiest way to get the correct path is to use the insert property button at top right of script editor (above insert tag button) to navigate to the component:
image

Components don't have them. Windows do. :wink:

dropDownObj = system.gui.getParentWindow(event).getComponentForPath('Root Container.Dropdown')

projectNames = system.project.getProjectNames() 
data=[[projectName] for projectName in projectNames] 
ds = system.dataset.toDataSet(['projectName'], data)
dropDownObj.data = ds

@JordanCClark’s code should do the trick in the internalFrame event. If you want to put the code on the component, you’d put it in a property change event checking for the componentRunning property:
if event.propertyName == "componentRunning":

@witman, Thats what I was missing!! I forgot about the insert property button. Makes a lot more since now. Especially when I went back and added it to the internalFrameActivated event on the main window.

@JordanCClark, I was missing the correct path to the dropdown dataset property when I tried it in the window.

Thank y’all so much for the help. Now on to the next step.

Thanks, Steven

2 Likes