Page tree
Skip to end of metadata
Go to start of metadata

The true power and flexibility of PIPE-FLO® Professional's new Data Import feature comes to light when taking advantage of Python™ scripting to generate or retrieve data. It does require some knowledge to get the most out of it, but it can greatly streamline your data entry processes once you have invested the time to get a script in place.

A .csv file is a common file format for tabulated data. It can be created in Microsoft® Excel, most text editors, or as an output from various software packages such as CAD and PDMS programs. The ability to set Design Data from an external file using Data Import allows the use of a single script for multiple projects or multiple lineups in a single project. This can save time and avoid error in the input of Design Data for the piping system model.

The example below reads pipe data (name, length, and size) from a CSV file and imports them into a PIPE-FLO Professional model. In this case the pipe names correspond to Tutorial Complete v12- US Units.pipe, which can also be found in the Sample Systems sub folder in Projects. The text below can also be copied into a text editor to create the pipe_data.csv and read_pipe.py files necessary to run this example in PIPE-FLO.

 

The pipe_data.csv file consists of pipe name, length, and size in comma delimited rows:

10-TW-3,50,8 in

10-TW-5,150,6 in

10-TW-6,250,6 in

10-TW-7,100,6 in


The Data Import File (.py) locates pipe_data.csv and uses a loop to read, set and print to the Output window for each row in the .csv file. The # indicates lines that are commented out for explanation of the script.

 

 

# Import Python standard modules for use in the script

import csv  #Used for reading csv file

import os   #Used for path operations


# With the modules loaded, we can define variables for the file path. In this case, the script will look in the directory
# where this .py file is and find a file named pipe_data.csv.

dir = os.path.dirname( os.path.abspath( __file__ ) )

data_file_path = os.path.join( dir, 'pipe_data.csv' )


# NOTE: From this point forward, pay attention to the tabbing in the file. It indicates what statements are included
# in the various statement and loops.

# Read the pipe_data.csv file using the csv module that we imported above.

with open( data_file_path ) as csvfile:

	reader = csv.reader( csvfile )


#Process data for each row in the csv file, and assign it to variables. The FOR loop will end with the last row of the .csv file

	for data_row in reader:
		pipe_name = data_row[0]
		pipe_length = float( data_row[1] )
		pipe_size = data_row[2]
        
# Import the values for length and size for the current row of the .csv file. The length has no units specified, so it will be set in the
# same units that are currently in use for that field. These import functions can be found in the Data Import section of the help file.

		pipeflo().doc().get_pipe( pipe_name ).set_length(pipe_length)
		pipeflo().doc().get_pipe( pipe_name ).set_pipe_size(pipe_size)


# Print the pipe name, length and size for each row to the Output tab of the Data Import dialog.

		print( 'Pipe: {}\tLength: {}\tSize: {}'.format( pipe_name, pipe_length, pipe_size ) )

 

Once created, the file can be opened in PIPE-FLO by dragging the file onto the FLO-Sheet or clicking the Data Import button and open the file from there. Important: The .csv file must be properly named and in the same folder as the .py file for this script to work. Notice that the script prints the values from the csv file in the Output tab, and the Errors tab is empty.

 

The real value in this script is not the time saved to input the values from the csv file for a single project, but the flexibility to drop any .csv file in this folder with the Name\Length\Size format into the folder and rerun the script at any time. This could be for future revisions to this model or be applied to any PIPE-FLO model and any csv file pair as long as the pipe names match and the sizes are valid for the pipe specification in the model. Essentially, the time investment to develop a flexible script can provide savings on all current and future models.