Tidy up argument parsing

master
Dan Howe 7 years ago
parent ff16ea841c
commit 68fe6c9c9d

@ -31,8 +31,7 @@ def point_to_row(point, layer, dxf_type, dxf_id):
return row
def convert(dxf_name, layer_name):
# Read dxf file
def print_layers(dxf_name):
dxf = dxfgrabber.readfile(dxf_name)
# Get data from DTM
@ -41,6 +40,11 @@ def convert(dxf_name, layer_name):
for layer in layers:
print(layer)
def convert(dxf_name, layer_name):
# Read dxf file
dxf = dxfgrabber.readfile(dxf_name)
if layer_name:
print("\nExtracting data from layer '{}'".format(layer_name))
entities = [
@ -86,12 +90,25 @@ def convert(dxf_name, layer_name):
def main():
dxf_name = sys.argv[1]
try:
layer_name = sys.argv[2]
except IndexError:
layer_name = None
# Set up command line arguments
parser = argparse.ArgumentParser()
parser.add_argument('dxf_name', help='path to dxf file', default=None)
parser.add_argument(
'-n', metavar='LAYER_NAME', help='name of layer', default=None)
parser.add_argument(
'-l', action='store_true', help='show list of layers', default=False)
args = parser.parse_args()
# Parse arguments
dxf_name = args.dxf_name
layer_name = args.n
show_layers_only = args.l
if show_layers_only:
# Print list of layers only
print_layers(dxf_name)
else:
# Convert to csv
convert(dxf_name, layer_name)

Loading…
Cancel
Save