LAE

Welcome to the LAE community!  Please feel free to start a discussion in the discussion tab or join in a conversation.

Discussions

Members

Resources

Events

 View Only
  • 1.  Python Node example

    Employee
    Posted 10-13-2015 11:06

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: sozdemir

    Hello,

    Does anyone have a simple file showing how to use Python Node? I am looking for something really basic.

    Thank you.


  • 2.  RE: Python Node example

    Employee
    Posted 11-04-2015 11:05

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: the1don

    Did you ever get an example of how to use the Python Node? I am trying to convert text to title case (first letter capital the rest lower) and Lavastorm does not provide that I figured it shoudl be easy to use the Python node and title() but still trying to figure it out.

    Thank you


  • 3.  RE: Python Node example

    Employee
    Posted 11-05-2015 04:51

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: aop

    Check C:\Users\Public\Documents\Lavastorm BRAIN\Examples for Python examples. Could be different directory in LAE 6 but the project file is ExamplePythonNodes.brg.

    Also search for Python Node Getting Started.pdf in LAE installation directory.


  • 4.  RE: Python Node example

    Employee
    Posted 11-06-2015 02:17

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: gmullin

    Very simple example below. Just takes an input pin, reads it and prints it out again. Hopefully will help to get you started.

    			
    				node:Python
    bretype:core::Python
    editor:sortkey=561387df4af457f7
    input:5613885d5c905f77/in1=Static_Data.40fe6c55598828e5
    output:561387f030076ca2/out1=
    prop:Python2Implementation=<<EOX
    import braininfo

    def setup(brainNodeControlObj, BrainNodeClass):
    ''' Must return a class that inherits from BrainNodeClass. '''
    class BrainNode(BrainNodeClass):
    def initialize(self):
    ''' Called at node initialization, before first pump.'''
    super(BrainNode, self).initialize()

    def finalize(self, val):
    ''' Called at node end, after last pump call. '''
    super(BrainNode, self).finalize(val)

    def pump(self, quant):
    ''' Will continue to be called until False is returned.

    Only a small amount of work should be done in pump without checking
    quant.permitsRunning. When that returns False, return from pump
    with a True value to be called again, a False value when finished.'''
    while quant.permitsRunning(self):
    # your code here
    #setup metadata
    metadata = self.newMetadata()
    om = self.newMetadata()

    #create output pins
    om.append("Status", "string")
    om.append("Input", "string")
    self.outputs[0].metadata = om
    outputRec = self.outputs[0].newRecord()

    #read input pins
    inputRec = self.inputs[0].read()

    # Check that we haven't passed the last record
    if inputRec is None:
    return False

    #create a record to output in output pin
    outputRec = self.outputs[0].newRecord()
    outputRec[0] = inputRec["second_input"] #can specify the name of the field or use index
    outputRec[1] = inputRec[0] #using index
    self.outputs[0].write(outputRec)

    # when complete
    return False
    # finished your quantum, you want pump called again
    return True

    # If you implement your logic here, you don't need code below. If you want
    # to inherit, and add more logic at next level, uncomment below code

    # py3File = brainNodeControlObj.properties.getString("ls.brain .node.BrainPython.python3ImplementationFile")
    # braininfo.loadModule(py3File, "py3", brainNodeControlObj)
    # import py3
    # BrainNodeImpl = py3.setup(brainNodeControlObj, BrainNode)
    # return BrainNodeImpl

    return BrainNode
    EOX
    editor:XY=350,140
    end:Python

    node:Static_Data
    bretype:core::Static Data
    editor:sortkey=5613888b71f17848
    output:@40fe6c55598828e5/=
    prop:StaticData=<<EOX
    single_input,second_input
    hello,this
    EOX
    editor:XY=210,140
    end:Static_Data