import sys import truss if len(sys.argv) < 3: print('Usage:') print( 'python3 main.py [joints file] [beams file] [optional plot output file]' ) sys.exit() joints_file = sys.argv[1] beams_file = sys.argv[2] try: output_file = sys.argv[3] except: output_file = False try: result = truss.Truss(joints_file, beams_file, output_file) except RuntimeError as e: print('Runtime Error: {}'.format(e)) sys.exit() print(result)
# python3 main.py truss1/joints.dat truss1/beams.dat import sys import truss if len(sys.argv) < 3: print('Usage:') print(' python3 {} [joints file] [beams file] [optional output file]'. format(sys.argv[0])) sys.exit(0) input_joints = sys.argv[1] input_beams = sys.argv[2] if len(sys.argv) < 4: input_figure = 0 else: input_figure = sys.argv[3] try: a = truss.Truss(input_joints, input_beams) if (input_figure): a.PlotGeometry(sys.argv[3]) except RuntimeError as e: print('ERROR: {}'.format(e)) sys.exit(2) print(a)
import sys import truss try: a = truss.Truss(sys.argv[1], sys.argv[2]) a.PlotGeometry() except RuntimeError as e: print('ERROR: {}'.format(e)) sys.exit(2)
joints_file = sys.argv[1] beams_file = sys.argv[2] # Checks for formatting issues in user inputted files if bad_format(joints_file) or bad_format(beams_file): sys.exit(0) # Checks if user inputted files exist if file_not_found(joints_file) or file_not_found(beams_file): sys.exit(0) # Handles when user does not submit the (optional) plot file name # Just sets the name of the plot to be "figure.pdf" and saves it in # the working directory if len(sys.argv) == 3: try: t = truss.Truss(joints_file,beams_file,"figure") except RuntimeError as e: print('ERROR: {}'.format(e)) sys.exit(2) print(t) # Handles when user does include the output plot file name # Picks third argument as plot file, even if more than 3 arguments # are inputted (for some reason) if len(sys.argv) > 3: plot_file = sys.argv[3] # Check for formatting issues on user inputted plot file if bad_format(plot_file): sys.exit(0) [plot_filepath,plot_filename] = os.path.split(plot_file) # If user attached a directory to their plot file name, check if
from os.path import abspath as a import sys import truss #Only printing usage information if called with no input arguments, as specified if len(sys.argv) == 1: print('Usage:') print( ' python3 {} <joints file> <beams file> <optional plot output file>') sys.exit(0) joint = sys.argv[1] beam = sys.argv[2] #Instantiate different instances of class depending on presence of optional argument if len(sys.argv) == 4: plot = sys.argv[3] t = truss.Truss(a(joint), a(beam), a(plot)) else: t = truss.Truss(a(joint), a(beam), "no plot") print(t)
# Check for adequate input arguments, and print usage message if inadequate if len(sys.argv) < 3: print('Usage:') str1 = ' python3 main.py [joints file] [beams file] ' str2 = '[optional plot output file]' print(str1 + str2) sys.exit(0) # Store input arguments jointsFile = sys.argv[1] beamsFile = sys.argv[2] try: # Create truss object t = truss.Truss(jointsFile, beamsFile) # If a plot output file is given, plot the truss geometry. # This is done before calculations so that geometry can be shown even if # forces cannot be calculated. if len(sys.argv) == 4: outFile = sys.argv[3] t.PlotGeometry(outFile) # Calculate static equilibrium forces and print results t.computeStaticEquilibrium() print(t) except RuntimeError as e: print('ERROR: {}'.format(e)) sys.exit(2)
import copy,sys import truss if len(sys.argv)==4: # Checks the number of input arguments, stores file name inputs into # variables, creates a truss class with beams and joints files. joints_file=copy.copy(sys.argv[1]) beams_file=copy.copy(sys.argv[2]) plot_file=sys.argv[3] a=truss.Truss(joints_file,beams_file) a.PlotGeometry(plot_file) # Plots the geometry and saves as the plot_file name to the current # directory. elif len(sys.argv)==3: joints_file=copy.copy(sys.argv[1]) beams_file=copy.copy(sys.argv[2]) a=truss.Truss(joints_file,beams_file) # Does not plot the file if plot_file is not given as input. else: print('Usage: $python3 [joints file] [beams file]\ [optional plot output file]\n') sys.exit(0) # If the number of inputs are not correct, prints the usage directions # and exits. a.Analysis() print(a) # Runs the analysis of the system and prints results.
import sys import truss # print instruction when not enough arguments given if len(sys.argv) not in [3, 4]: print( "Usage:\n$ python3 main.py [joints file] [beams file] [optional plot output file]" ) sys.exit(0) fjoints, fbeam = sys.argv[1:3] fplot = None if len(sys.argv) == 4: fplot = sys.argv[3] a = truss.Truss(fjoints, fbeam, fplot) print(a)
import sys import truss if (len(sys.argv) < 3): print('Usage:') print(' python {} [joints file] [beams file] [optional plot output file]'. format(sys.argv[0])) exit() joint_file = sys.argv[1] beam_file = sys.argv[2] output_file = None if len(sys.argv) >= 4: output_file = sys.argv[3] try: t = truss.Truss(joint_file, beam_file, output_file) except Exception as e: print('ERROR: {}'.format(e)) exit() print(t)