Skip to main content

I have a Python Script Tool already created that creates a custom staged Project Folder containing all of the AutoCAD Drawings (.dwg) and a File Geodatabase (.gdb) with the correct naming conventions based on our submittal requirements. I also have a FME Workspace created that can read a specified .dwg and then create/write features to a .gdb.

I would like to maybe execute the Python Script Tool as a Startup Python Script to build the Project Folder and then pass the .dwg and .gdb stored in the created folder as the src/dst or read/write in the FME Workspace. I am sure this or something that will accomplish the same end goal is possible. I have found similar questions in reverse (passing parameters from FME to a Python Script). I just have not found the correct documentation for it in my searches thus far.

Thanks for any help in advance.

There are a number of ways but using shared Python global variables is one, Dave Campanas provides a sample:

https://knowledge.safe.com/articles/849/how-to-extract-and-use-log-information-in-workbenc.html?smartspace=fme-desktop-workbench-scripting


There are a number of ways but using shared Python global variables is one, Dave Campanas provides a sample:

https://knowledge.safe.com/articles/849/how-to-extract-and-use-log-information-in-workbenc.html?smartspace=fme-desktop-workbench-scripting

That solution seems to be the reverse of what I would like to do. I would like to start with a Python Script Tool. In this tool the User specifies what .dwg file to include in the creation of the project folder. When the Script Tool has completed its process, we now have a .dwg(src/reader) and a .gdb(dst/writer) identified. I want to use these in the workspace.

 

 

I found a post that discusses executing a FME Workspace from a Python Script and this might be viable if I can figure out how to modify my FME Workspace Reader and Writer to accept the Parameters passed from the script.

 

 


I've attached a small demo template that demonstrates two different concepts:

  • Retrieve a value from the Python startup script as a workspace attribute
  • Retrieve a Python scripted parameter as a workspace attribute

If you need to use any of these values in your reader I recommend you use the FeatureReader rather than the "classic" reader.

get-scripted-startup-param.fmwt


That solution seems to be the reverse of what I would like to do. I would like to start with a Python Script Tool. In this tool the User specifies what .dwg file to include in the creation of the project folder. When the Script Tool has completed its process, we now have a .dwg(src/reader) and a .gdb(dst/writer) identified. I want to use these in the workspace.

 

 

I found a post that discusses executing a FME Workspace from a Python Script and this might be viable if I can figure out how to modify my FME Workspace Reader and Writer to accept the Parameters passed from the script.

 

 

Hello @dane_stephenson,

I'm trying to accomplish something like this for my workflow

I have a python script that scrapes outlook inbox and downloads the attachments which are the readers in my FME workspace.

Have you had any success with your task?

 


Hello @dane_stephenson,

I'm trying to accomplish something like this for my workflow

I have a python script that scrapes outlook inbox and downloads the attachments which are the readers in my FME workspace.

Have you had any success with your task?

 

@adi -

I believe I was successful, although this was some time ago. Back then we did not yet have FME Server and I wanted to execute the FME workspace stored on a network drive via an ArcGIS Toolbox Script Tool. This would have to be performed on a desktop machine that had both ArcGIS Desktop and FME Workbench installed. The concept was that I had a script tool that took in some parameters and assembled a project folder with all of the pieces necessary appropriately named, etc. Then I wanted to immediately execute a FME Workspace that would take the pieces provided and staged and process a portion of it to create new features in a feature class as a starting point for the Users.

I have attached the script below to help you get started. Forgive all of the commenting, it was to help explain the essentials.

ArcGIS_Toolbox_Script_Tool_FME_Execution.py


@adi -

I believe I was successful, although this was some time ago. Back then we did not yet have FME Server and I wanted to execute the FME workspace stored on a network drive via an ArcGIS Toolbox Script Tool. This would have to be performed on a desktop machine that had both ArcGIS Desktop and FME Workbench installed. The concept was that I had a script tool that took in some parameters and assembled a project folder with all of the pieces necessary appropriately named, etc. Then I wanted to immediately execute a FME Workspace that would take the pieces provided and staged and process a portion of it to create new features in a feature class as a starting point for the Users.

I have attached the script below to help you get started. Forgive all of the commenting, it was to help explain the essentials.

ArcGIS_Toolbox_Script_Tool_FME_Execution.py

Hello @dane_stephenson,

appreciate you sharing the script !!

The explanation helps indeed,we do not have FMEserver and Im looking for a way to pass parameters to FME workspace via python script.

Thank s again


Hello @dane_stephenson,

appreciate you sharing the script !!

The explanation helps indeed,we do not have FMEserver and Im looking for a way to pass parameters to FME workspace via python script.

Thank s again

@adi -

What I attached was a Python Script used to invoke the execution of an FME Workspace from the Python Script. The messages in said script were tailored to return a message in the "Results" window of an ArcGIS Script Tool execution, but the same Script could be used in a straight Python Script execution (via Command, etc.) by swapping "arcpy.AddMessage" for "print".

You just have to be sure to include the "fmeobjects.pyd" (which can be found in your ".....\\FME\\fmeobjects\\python27" (or whatever your flavor of python is) folder) in your Python interpreter's ".....\\Lib\\site-packages" folder.

My comment about FME Server was explaining that this (executing a Workspace from a Python Script) was how we were doing it prior to getting FME Server.

I used to run a Workspace overnight on a schedule by using a Python Script similar to the attached one. I wrote a .bat file that called and executed the Python Script. I then used Windows Task Scheduler on my Desktop to set a schedule to execute the .bat file. Task Scheduler executed the .bat file, the .bat file executed the Python Script, and the Python Script executed the FME Workspace.

Good Luck with your endeavors, let me know if you have any other questions.


It might be possible to use the File Copy Writer to create your project directory. That way you wouldn't need to pass information between the startup script and transformers.

I am doing the same thing in one of my workflows. The problem you may have initially is that FME may try write the features into the .dwg and .gdb before it has created the project directory. To avoid this issue, I used Dale's suggestion in the link. It works great. This may be a none issue for you, as I'm doing alot of fanning out of the file names into multiple directories.

https://knowledge.safe.com/questions/21228/holding-an-entire-workbench.html

 


I appreciate all of the new responses. I discovered a solution and resolved my problem not long after originally posting this. I have recently been responding to @adi comments on @bruceharold response and that seems to be the reason for renewed interest. However, it is good to know that there are multiple methods for addressing the issue.


Reply