Skip to main content
Hello, 

 

 

I would like to access FME Objects from my Python Code. But I don't understand how to import fmeobjects, which is the correct folder to copy in the Python folder ?

 

 

I just need to do a simple thing : i have an AutoCAD .dwg file as input in FME and i would like my Python script to go through the layers in the dwg file and to print the name of those layers. (something that FME does using Mapping File Generation to merge the schema features from the dataset).

 

 

Thanks,

 

Paul
Also, can fmeobject work with Python3.x now ?
Hi Paul,

 

 

This is the dynamic module file for the fmeobjects.

 

<FME Installation Folder Path>\\fmeobjects\\python27\\fmeobjects.pyd

 

 

Copy it into "<Python Home>\\Lib\\site-packages" folder.

 

OR, append a searching path in your Python script like this.

 

-----

 

import sys

 

sys.path.append('<FME Installation Folder Path>/fmeobjects/python27')

 

import fmeobjects

 

-----

 

 

But I'm not sure whether the module works with Python 3.x, since it is implemented with Python 2.7.x.

 

 

Takashi
Thanks a lot for your answer!

 

I think it doesn't work on Python3 😞 i don't know what to do..
I think you have at least three choices if the fmeobjects module doesn't work with Python 3.x.

 

-----

 

pA] Install Python 2.7 to your machine.

 

/B] Embed the script into an FME workspace (startup or PythonCreator/Caller script) and execute it with FME Workbench.

 

Thank you !

Option [a] is not possible for me.

Option [b] : this could work. I write a code that goes through the layers in the dwg and writes the result in a Published Parameter that I can use after. What do you think ?

Option [c] : this could work too, but i don't see how the Schema Reader can be used to get layer names ?


[b] All parameter values are determined before executing startup script, you cannot set any parameter value with script. If you need to use the resulting value from the script in other part of the workspace, consider using a Python global variable (save the resulting value into a global variable; get the value with other script defined in a PythonCaller).

 

 

pC] Just add a Schema (Any Format) reader to the workspace with setting the dwg file path to its Dataset parameter. The reader will create features having schema information for each layer in the specified dwg file. Each schema feature has an attribute called "fme_feature_type_name" that stores the layer name.

 

 

The Schema reader approach might be easier than other approaches.
If you embed the script to a PythonCreator, you could create a feature holding the required layer name as its attribute and send out it to the data flow.

In the Reader, i used the autocad_layer in the Format Attributes to get the names of the layers. Then I copied them into a new Attribute but i don't see how can I pass these values in my Python script and my GUI.


I was thinking to write the name of the layers in a csv file, that way I can have access to the csv file from my Python console. What do you think ?
The "fme_feature_type_name" read by the Schema reader contains a layer name, which is the same as the "autocad_layer". So I thought that using the Schema reader would be easy just to get layer names.

 

But I cannot decide what is the best way since I'm unclear what your requirement is.

 

What's the purpose to get the layer names?

I am using the Amazon s3 bucket modified listener to trigger a workspace and process data as soon as it enters our bucket. Some days ago we had to change the region settings and since then i am getting this error:

2021-07-12T10:32:29Z | An error occurred: The authorization header is malformed; the region 'us-east-1' is wrong; expecting 'us-east-2' (Service: Amazon S3; Status Code: 400; Error Code: AuthorizationHeaderMalformed; Request ID: ********; S3 Extended Request ID: *****)

The FME server version is 2020.1.3.2, i don't have access to the config files of the server. Is it possible to set the region of the listener manually somehow or a trick to solve the problem? I tried same connection on another instance of the FME server and i had no problems there.


What should the workspace do after informing?
Nothing. The workspace should have the dwg as input and get the layer names.
As you mentioned, saving layer names to a csv file might be a good idea.

 

Alternatively, there is a way to prompt a message box just to inform layer names to the user. See this old QA.

 

Message or Alert Box (https://knowledge.safe.com/CommunityAnswers?id=906a0000000cojVAAQ)
I didn't know you could prompt a message with FME, thanks!

 

However I'm experiencing some issues : when I choose my dwg file through my GUI, I'm not sure it correctly opens all the layers in FME (ie : when you have a Reader that is a dwg/dxf format, FME asks you which layers you want to upload ; it is this part that I'm having trouble with).
Therefore, I think the Schema (Any Format) reader would be effective to collect layer (feature type) names from a specified source dataset. Have you tried the Schema reader?

 

 

This is another discussion on how to collect feature type names and display them with a dialog, using the Schema reader and a PythonCaller.

 

select different feature type each time workspace runs (https://knowledge.safe.com/CommunityAnswers#!/feedtype=SINGLE_QUESTION_SEARCH_RESULT&id=906a0000000d27zAAA)
Hi Takashi,

 

 

I am using C:\\Python27\\ArcGISx6410.3 for running my scripts. No I want to use fmeobjects from my folder C:\\Program Files (x86)\\FME\\fmeobjects\\python27. I tried to copy the fmeobjectes.pyd to my python Lib folder like you mentioned in your post above but I get an error like this,

 

"ImportError: DLL load failed: %1 is not a valid Win32 application"
Probably the Python/ArcGIS is 64bit version but the fmeobjects module is from FME 32bit version. Generally there is no interoperability between 64bit application and 32bit application.

 

How about installing FME 64bit version and using its "fmeobjects.pyd"? You can install both FME 32bit and FME 64bit into different folders of the  same machine.
Hi Takashi, yup that was the case, So I simply copied over the fmeobjectes.pyd to my 32bit python installed by arcgis and its working now. Thanks

Reply