Fish argument not available inside the function

Good day to you all!

I am writing a fish function that takes an argument and calls a Python function that uses that argument, say:

def myFish(x)
command
 call "myPython.py"
endcommand
end

where inside myPython.py is a line of the sort:

x = it.fish.get("x")

but this returns an error

*** Python error: ‘FISH variable not found.’

and indeed, if I issue pause inside the FISH function:

def myFish(x)

command
pause
 call "myPython.py"
endcommand
end

I see that x is not in my FISH Symbols.

What can I do to make the argument to my FISH function available? is this perhaps due to my argument not being global?

Thank you in advance,

Yes, as you said, x is not a global variable and it.get.fish doesn’t work. I don’t know why you need to call a python function inside fish function. But we usually use python as a super set to handle fish scripts.
If you still want to get x, you can use the command pythonfile. But it’s just a hack, I don’t recommend

def myFish(x)
command
 pythonfile x = [x]
 call "myPython.py"
endcommand
end
1 Like

Oh ok, thank you, I just delcared a global FISH variable and that works with it.fish.get. Regarding your point of why nest python inside fish, it’s just due to my not being so familiar with fish to do some more complex things.

I use a python file (distributeStruts.py) to loop through a line in the model and find nodes that are near a given set of points in space to create struts by calling another fish function ‘createStrut’ with exact coordinates of deformed nodes - not sure if this is necessary. This is nested inside another fish function (struts(z)) that creates a whole line of struts just by giving it the argument z. I just made it work with declaring

def struts(z)
 global zGlobal = z
 command 
    call 'distributeStruts.py' ; <---- uses zGlobal
 endcommand
end

this is probably more complicated than it needs to, so if you have any suggestions to improve my fishing I would greately appreciate it.

Cheers,