Select to view content in your preferred language

error: global name 'Primary_OH' is not defined

5246
43
Jump to solution
12-27-2019 11:14 AM
RickHawkins
New Contributor II

I am trying to run my program and when i get to this part of the program

I get the error that global name 'Primary_OH is not defined. Can someone look at my code and tell what i need to do to fix this.

Thanks

Tags (1)
0 Kudos
43 Replies
RickHawkins
New Contributor II
from tkinter import *
from tkinter import messagebox
import Tkinter, arcpy

#mxd = arcpy.mapping.MapDocument("C:/GISMAPS/LUS Map.mxd")
mxd = arcpy.mapping.MapDocument(r"C:/GISMAPS/LUS Map.mxd")
#mxd = arcpy.mapping.MapDocument("CURRENT")

#reset (overwrite) MakeFeatureLayer_management. This is needed so you can run the program more than once.
arcpy.env.overwriteOutput = True 
#delete the layer
#arcpy.Delete_managment 

#set variables for when you run the section of program that set the layers that should be on
geodatabase = "C:\gismaps\LusData.mdb"
dataset = "ElectricData"
feature_class = "PriOHElectricLineSegment"

#Create main window
window = Tk()
window.title("Feeders Selection")
window.geometry("680x500")
window.iconbitmap('C:/GISMAPS/lus.ico')


#Define the frame for the feeders to be displayed
frame = Frame(window)
frame.grid(row=1, column=1, padx=15, pady=5)
listNodes = Listbox(frame, width=10, height=10, font=("Helvetica", 10))
listNodes.pack(side="left", fill="y")

#Define the scrollbar in frame window
scrollbar = Scrollbar(frame, orient="vertical")
scrollbar.config(command=listNodes.yview)
scrollbar.pack(side="right", fill="y")
listNodes.config(yscrollcommand=scrollbar.set)


#Add the selection of all feeders
for item in [2050, 2051, 2052,
             3050, 3051, 3052, 3550,
             4050, 4051, 4052,
             5050, 5051, 5052]:
    listNodes.insert(END, item)
    feeder = listNodes.get(ACTIVE)


#Define all of the checkboxes
prioh_var = IntVar()
priug_var = IntVar()
secoh_var = IntVar()
secug_var = IntVar()
fuse_var = IntVar()
switch_var = IntVar()
sp_var = IntVar()
cap_var = IntVar()
rec_var = IntVar()
pinhook_var = IntVar()
mall_var = IntVar()
peck_var = IntVar()
pri_oh = Checkbutton(window, text = "Primary Overhead", variable = prioh_var,onvalue = 1, offvalue = 0, height=2, width = 20).place(x=2, y=175)
pri_ug = Checkbutton(window, text = "Primary Underground", variable = priug_var,onvalue = 1, offvalue = 0, height=2, width = 20).place(x=12, y=200)
sec_oh = Checkbutton(window, text = "Secondary Overhead", variable = secoh_var,onvalue = 1, offvalue = 0, height=2, width = 20).place(x=8, y=225)
sec_ug = Checkbutton(window, text = "Secondary Underground", variable = secug_var,onvalue = 1, offvalue = 0, height=2, width = 20).place(x=18, y=250)
fuse = Checkbutton(window, text = "Fuse", variable = fuse_var,onvalue = 1, offvalue = 0, height=2, width = 20).place(x=400, y=10)
switch = Checkbutton(window, text = "Switch", variable = switch_var,onvalue = 1, offvalue = 0, height=2, width = 20).place(x=405, y=35)
servicepoint = Checkbutton(window, text = "Service Point", variable = sp_var,onvalue = 1, offvalue = 0, height=2, width = 20).place(x=420, y=88)
capacitor = Checkbutton(window, text = "Capacitor", variable = cap_var,onvalue = 1, offvalue = 0, height=2, width = 20).place(x=412, y=60)
recloser = Checkbutton(window, text = "Recloser", variable = rec_var,onvalue = 1, offvalue = 0, height=2, width = 20).place(x=409, y=87)
pinhook = Checkbutton(window, text = "Pinhook", variable = pinhook_var, state = DISABLED, onvalue = 1, offvalue = 0, height=2, width = 20).place(x=175, y=15)
mall = Checkbutton(window, text = "Mall", variable = mall_var, state = DISABLED, onvalue = 1, offvalue = 0, height=2, width = 20).place(x=165, y=45)
peck = Checkbutton(window, text = "Peck", variable = peck_var, state = DISABLED, onvalue = 1, offvalue = 0, height=2, width = 20).place(x=165, y=75)


#Commit all of the options

def commit():
    feeder = listNodes.get(ACTIVE)
    
#check to see which inputs have been selected

#Primary Overhead
    if prioh_var.get() == 1:
        print("pri_oh = 1") 
	# show primary overhead feeder where feederid = feeder -ie: [FEEDERID] = "2050"
        print "Primary_OH"
        
		
        
        layer_name = "Primary OH"  
        primary_oh = arcpy.mapping.ListLayers(mxd, layer_name)[0] 
        primary_oh.definitionQuery = "[FEEDERID] = '2050'"  

        print feeder
        
        #Primary_OH_path = r"{0}\{1}\{2}".format(geodatabase, dataset, feature_class) 
        #Primary_OH = arcpy.MakeFeatureLayer_management(Primary_OH_path, "Primary_OH_layer2") 

    else:
        print("pri_oh = 0")
		# do not display primary overhead feeder for [FEEDERID] = "2050"
		
        
#Primary Underground		
	if priug_var.get() == 1:
		print("pri_ug = 1")
		
		
		layer_name = "Primary UG"  
        primary_ug = arcpy.mapping.ListLayers(mxd, layer_name)[0] 
        primary_ug.definitionQuery = "[FEEDERID] = '2050'"  

        print feeder

    #else:
        #print("pri_ug = 0")
        # do not display primary underground feeder for [FEEDERID] = "2050"
        
    mxd.save()

    return

	
#reset all variables  
#def reset():



  
#Button to run the commit command    
Button(window, text="commit", command=commit).place(x=300, y=350)

#Button to run the reset command
#Button(window, text="reset", command=reset).place(x=400, y=350)

#Quit the program
Button(window, text="Quit", command=window.destroy).place(x=500, y=350)




window.mainloop()

Still getting the same error.   

0 Kudos
RickHawkins
New Contributor II

Is there a way to not save the mxd file but refresh screen to see the changes. 

0 Kudos
RickHawkins
New Contributor II

Javier,

for this query in arcGIS

Do these lines in the python script do the same thing?

When i apply the query from ArcGIS all of the primaryOH that is not part of 2050 turns off.

0 Kudos
RickHawkins
New Contributor II

Javier,

It looks like the code you sent me is working. I had to quit the script for the changes to show up.

Thank you for all of your help