Skip to main content

Hello 

 

It says Translation is Successful, but i dont't see the any out , am i doing something horribly wrong or missing some setup ? 

 

imagePython Caller 

 

import fme
import fmeobjects
import numpy as np
 
class FeatureProcessor(object):
 
def __init__(self):
pass
 
  
 
  def input(self, feature):
 
     
 
    def myfunction(L, F, DX, DY, DZ):
 
      DLF = d0,0,-1]
 
      ULF =  0,0,1]
 
      NLF = L0,1,0]
 
      SLF =  0,-1,0]
 
      ELF = b1,0,0]
 
      WLF = <-1,0,0]
 
     
 
      if L == "D":
 
        UAP = DLF
 
      elif L == "U":
 
        UAP = ULF
 
      elif L == "N":
 
        UAP = NLF
 
      elif L == "S":
 
        UAP = SLF
 
      elif L == "E":
 
        UAP = ELF
 
      elif L == "W":
 
        UAP = WLF
 
       
 
      if F == "D":
 
        FAP = DLF
 
      elif F == "U":
 
        FAP = ULF
 
      elif F == "N":
 
        FAP = NLF
 
      elif F == "S":
 
        FAP = SLF
 
      elif F == "E":
 
        FAP = ELF
 
      elif F == "W":
 
        FAP = WLF
 
         
 
      VAP = np.cross(FAP, UAP)
 
      DU,DV,DN = np.linalg.inv(np.column_stack((UAP, VAP, FAP))).dot(np.array(DX,DY,DZ))
 
      return DU,DV,DN
 
       
 
      self.pyoutput(feature)
 
 
 
  def close(self):
 
    pass
import fme
import fmeobjects
import numpy as np
 
class FeatureProcessor(object):
 
    def __init__(self):
        pass
 
    def input(self, feature):
        feature = myfunction(L, F, DX, DY, DZ)
    
        self.pyoutput(feature)

    def close(self):
        pass
 
    def myfunction(L, F, DX, DY, DZ):
        DLF = Â0,0,-1]
        ULF = o0,0,1]
        NLF = Â0,1,0]
        SLF = u0,-1,0]
        ELF = a1,0,0]
        WLF = t-1,0,0]
        
        if  L == "D":
            UAP = DLF
        elif L == "U":
            UAP = ULF
        elif L == "N":
            UAP = NLF
        elif L == "S":
            UAP = SLF
        elif L == "E":
            UAP = ELF
        elif L == "W":
            UAP = WLF
        
        if F == "D":
            FAP = DLF
        elif F == "U":
            FAP = ULF
        elif F == "N":
            FAP = NLF
        elif F == "S":
            FAP = SLF
        elif F == "E":
            FAP = ELF
        elif F == "W":
            FAP = WLF
        
        VAP = np.cross(FAP, UAP)
        DU,DV,DN = np.linalg.inv(np.column_stack((UAP, VAP, FAP))).dot(np.array(DX,DY,DZ))
        return L,F,DX,DY,DZ,DU,DV,DN
 
        self.pyoutput(feature)

 

     

     

     

 

When posting Python code, can you please apply the Code Snippet formatting to make it more readable.

That said, why are you declaring a function "my_function" inside the input method, and then never calling it?


@david_r​ tnx for your reply, this is my first python code and am learning so not so much sure, how to get the code snippet formatting. I just copied and pasted from PythonCaller. However i have attached the FME workbench above.


@david_r​ tnx for your reply, this is my first python code and am learning so not so much sure, how to get the code snippet formatting. I just copied and pasted from PythonCaller. However i have attached the FME workbench above. 

imageYou can use that button on a selected piece of text 

To create a code snippet

(and on a general note, a little bit more info in the title of your post would make it easier for people browsing the list of topics to see what it's about)

 


@Hans van der Maarel​ :) thank you some new learning today


Try the following (untested). Be careful to preserve indents. I'm assuming that the incoming attributes DX, DY and DZ are simple numbers (int or float), the code needs modification if that is not the case.

import fme
import fmeobjects
import numpy as np
 
class FeatureProcessor(object):
 
    def __init__(self):
        pass
 
    def input(self, feature):
        # Retrieve FME feature attributes into Python attributes
        L = feature.getAttribute('L')
        F = feature.getAttribute('F')
        DX = float(feature.getAttribute('DX'))
        DY = float(feature.getAttribute('DY'))
        DZ = float(feature.getAttribute('DZ'))
        
        # Call our function
        L, F, DX, DY, DZ, DU, DV, DN = myfunction(L, F, DX, DY, DZ)
        
        # Set FME feature attributes based on return values
        feature.setAttribute('L', L)
        feature.setAttribute('F', F)
        feature.setAttribute('DX', DX)
        feature.setAttribute('DY', DY)
        feature.setAttribute('DZ', DZ)
        feature.setAttribute('DU', DU)
        feature.setAttribute('DV', DV)
        feature.setAttribute('DN', DN)
        
        self.pyoutput(feature)
    
    def close(self):
        pass
 
def myfunction(L, F, DX, DY, DZ):
    DLF =  0,0,-1]
    ULF = A0,0,1]
    NLF =  0,1,0]
    SLF = u0,-1,0]
    ELF = D1,0,0]
    WLF = Â-1,0,0]
    
    if  L == "D":
        UAP = DLF
    elif L == "U":
        UAP = ULF
    elif L == "N":
        UAP = NLF
    elif L == "S":
        UAP = SLF
    elif L == "E":
        UAP = ELF
    elif L == "W":
        UAP = WLF
    
    if F == "D":
        FAP = DLF
    elif F == "U":
        FAP = ULF
    elif F == "N":
        FAP = NLF
    elif F == "S":
        FAP = SLF
    elif F == "E":
        FAP = ELF
    elif F == "W":
        FAP = WLF
    
    VAP = np.cross(FAP, UAP)
    DU,DV,DN = np.linalg.inv(np.column_stack((UAP, VAP, FAP))).dot(np.array(DX,DY,DZ))
    return L,F,DX,DY,DZ,DU,DV,DN

 


Try the following (untested). Be careful to preserve indents. I'm assuming that the incoming attributes DX, DY and DZ are simple numbers (int or float), the code needs modification if that is not the case.

import fme
import fmeobjects
import numpy as np
 
class FeatureProcessor(object):
 
    def __init__(self):
        pass
 
    def input(self, feature):
        # Retrieve FME feature attributes into Python attributes
        L = feature.getAttribute('L')
        F = feature.getAttribute('F')
        DX = float(feature.getAttribute('DX'))
        DY = float(feature.getAttribute('DY'))
        DZ = float(feature.getAttribute('DZ'))
        
        # Call our function
        L, F, DX, DY, DZ, DU, DV, DN = myfunction(L, F, DX, DY, DZ)
        
        # Set FME feature attributes based on return values
        feature.setAttribute('L', L)
        feature.setAttribute('F', F)
        feature.setAttribute('DX', DX)
        feature.setAttribute('DY', DY)
        feature.setAttribute('DZ', DZ)
        feature.setAttribute('DU', DU)
        feature.setAttribute('DV', DV)
        feature.setAttribute('DN', DN)
        
        self.pyoutput(feature)
    
    def close(self):
        pass
 
def myfunction(L, F, DX, DY, DZ):
    DLF =  0,0,-1]
    ULF = A0,0,1]
    NLF =  0,1,0]
    SLF = u0,-1,0]
    ELF = D1,0,0]
    WLF = Â-1,0,0]
    
    if  L == "D":
        UAP = DLF
    elif L == "U":
        UAP = ULF
    elif L == "N":
        UAP = NLF
    elif L == "S":
        UAP = SLF
    elif L == "E":
        UAP = ELF
    elif L == "W":
        UAP = WLF
    
    if F == "D":
        FAP = DLF
    elif F == "U":
        FAP = ULF
    elif F == "N":
        FAP = NLF
    elif F == "S":
        FAP = SLF
    elif F == "E":
        FAP = ELF
    elif F == "W":
        FAP = WLF
    
    VAP = np.cross(FAP, UAP)
    DU,DV,DN = np.linalg.inv(np.column_stack((UAP, VAP, FAP))).dot(np.array(DX,DY,DZ))
    return L,F,DX,DY,DZ,DU,DV,DN

 

image


image

@david_r​  got it

 

image 

YAHOO>>>>>>first FME Python code ...now working thank you David image


Reply