Can user defined functions be used in an expression?

Can a user defined function be used within a expression? For example, I want to bind a property to ‘myfunction(parameter)’ within an expression.

You’re in luck! As of 3.0, there is the runScript expression. Check it out in the documentation under
Technical Reference > Expression Language > Advanced

Hope this helps,

I guess I’m a little slow here but I can’t find the ‘Advanced’ topic under Technical Reference > Expression Language. :confused:

Oh shoot, thats right, it wasn’t there in the manual index in 3.0.0 due to an oversight. Look at the online manual on our website, its there.

Here is a direct link:
inductiveautomation.com/prod … ctions.htm

Sorry about that.

Whew! Thought I was losing it there for a moment.

While I’ve got your attention, I’ve a related issue…

I’ve a function where I’m attempting to use the fpmi.db.toPyDataSet() function. I import fpmi before I call toPyDataSet() but I’m getting a 'NameError: fpmi" error with reference to the line with the toPyDataSet() call. Here’s my code:

[code]import fpmi

def toPensList(pens):
pensList = []
for pen in fpmi.db.toPyDataSet(pens):
pensList.append([pen[‘COL_NAME’], pen[‘TABLE_NAME’]])

return fpmi.db.toDataSet(['COL_NAME', 'TABLE_NAME'], pensList)

[/code]

The error references the line with ‘for pen in…’ Any idea what I’m doing wrong?

Yes, this has to do with how Python’s scoping rules work. You’re importing fpmi, but your def defines a new scope. The newly defined function doesn’t share scope with its declaring module.

try this:

[code]
def toPensList(pens):
import fpmi
pensList = []
for pen in fpmi.db.toPyDataSet(pens):
pensList.append([pen[‘COL_NAME’], pen[‘TABLE_NAME’]])

return fpmi.db.toDataSet(['COL_NAME', 'TABLE_NAME'], pensList)[/code]

You nailed it again. Placing the import within the def block fixed the problem.

Thanks! :smiley: