AnsweredAssumed Answered

Passing variable to another script

Question asked by mfrias on Aug 25, 2015
Latest reply on Aug 25, 2015 by jon.morris

I want to make a point layer from a csv file with AIS data (Automated Identification System, i.e., shipping data) . Then I want to make lines using a script called TrackBuilder.

 

So I have two python scripts: PythonTest.py to make the points and TrackBuilderVersion2_x64.py to make the lines.

 

I don't know how to tell python to use the variable outFC_Project in TrackBuilderVersion2_x64.py

 

The error I get is:

 

exceptions.NameError: name 'outFC_Project' is not defined

PythonTest.py:

 

#import modules
import arcpy
import os
from arcpy import env
import TrackBuilderVersion2_x64

#Set env settings
env.workspace = "E:/DensityMaps/DensityMapsTest.gdb/"
arcpy.env.overwriteOutput =True

#Define variables
monthTable = "E:/test_division/division_finale2014/file_list_months_weeks/scope_ais_december.csv"
monthPoints = "monthPoints"
x_coords = "long"
y_coords = "lat"

out_Layer = "monthLayer"
path_outLayer = "E:/DensityMaps/"

saved_Layer = "E:/DensityMaps/monthlayer.lyr"
outFC = "MonthFC"
outFC_Project = outFC+"_Project"

#set spatial reference
spRef =arcpy.SpatialReference("WGS 1984")

try:
    #Process
    arcpy.MakeXYEventLayer_management(monthTable, x_coords, y_coords, out_Layer, spRef, "")

    #Save to layer file
    arcpy.SaveToLayerFile_management(out_Layer, saved_Layer)

    #Copy features to FC
    arcpy.CopyFeatures_management(saved_Layer,outFC)

    #Set output coordinate system. 3035 = LAEA
    outCS = arcpy.SpatialReference(3035)

   #Project to LAEA
    arcpy.Project_management(outFC, outFC_Project, outCS)

    #Calling trackbuilder
    TrackBuilderVersion2_x64

    #Delete temporary files
    arcpy.Delete_management('monthLayer')
    os.remove(saved_Layer)

    #Check messages
    print(arcpy.GetMessages())

except:
    print arcpy.GetMessages()

print 'Script completed'

 

TrackBuilderVersion2_x64.py (only first lines, see the complete script in attachment):

 

#Import PythonTest.py to get the variable month
import PythonTest
#print "Testing printing "+PythonTest.outFC


print "Printing test "+PythonTest.outFC_Project
#Path to input points (broadcast feature class)
sInputFile = outFC_Project

#ID field name (can keep as is most likely)
sID_Field = "mmsi"


#DaeTime field name (can keep as is most likely)
sDT_Field = "timestamp_pretty"

#Path to output workspace (file geodatabase)
sOutWorkspace = r"E:/DensityMaps/DensityMapsTest.gdb"

#name of output trackline feature class
sOutName = "MonthTest"


#Break Track line method option (comment/uncomment the selected option)
sLineMethod = "Maximum Time and Distance"
#sLineMethod = "Time Interval"


#Maximum Time in minutes (keep as string in quotes, use 0 if using Time Interval method, default = 60)
sMaxTimeMinutes = "600"


#Maximum Distance in miles (keep as string in quotes, use 0 if using Time Interval method, default = 6)
sMaxDistMiles = "150"


#Time Interval in hours (keep as string in quotes, use 0 if using Maximum Time and Distance method, default = 24)
sIntervalHours = "0"


#Include Voyage Attributes (comment/uncomment the selected option)
#sAddVoyageData = "true"
sAddVoyageData = "false"


#Voyage Table (path to voyage table) - OPTIONAL
#voyageTable = r"D:\AISTrackBuilder\Test\test.gdb\Voyage"


#Voyage Matching Option (comment/uncomment the selected option) - OPTIONAL
#voyageMethod = "Most Frequent"
#voyageMethod = "First"


#Include Vessel Attributes (comment/uncomment the selected option)
#sAddVesselData = "true"
sAddVesselData = "false"


#Vessel Table (path to vessel table) - OPTIONAL
#vesselTable = r"D:\AISTrackBuilder\Test\test.gdb\Vessel"

Outcomes