POST
|
BTW, thanks for your help. I'm having one of those days. I swear the code block ran as written in the first post.
... View more
07-17-2015
11:48 AM
|
0
|
0
|
380
|
POST
|
This is the code block that is working for me now. So in line 3 where I create the featurelass paths, I'm not creating a 'list' of paths stored in memory, but a bunch of individual strings that are the paths? I would think path in line 5 would have to be indexed with layers, and the same for symPath? # Create directory paths, make feature layers, and apply symbologies.
for i, file in enumerate(files):
path = os.path.join(root, files) # Create directory path for featureclasses
symPath = os.path.join(symRoot, files + ".lyr") # Create directory path for .lyr files
arcpy.MakeFeatureLayer_management(path, layers, pws) # Make all the layers from "files" list
arcpy.ApplySymbologyFromLayer_management(layers, symPath) # Apply the symbologies from "symNames" list.
... View more
07-17-2015
11:39 AM
|
0
|
2
|
380
|
POST
|
It goes to turd on line 31 Re: Two issues creating a script tool
... View more
07-17-2015
10:43 AM
|
0
|
5
|
380
|
POST
|
Would I add print statements after each directory path? that's what I did the error comes after they all print.
... View more
07-17-2015
09:58 AM
|
0
|
7
|
734
|
POST
|
ERROR 000732: Input Features: Dataset V does not exist or is not supported is the error I get when I change 'path' to 'paths'. This is a serious WTF moment for me.
... View more
07-17-2015
09:13 AM
|
0
|
9
|
734
|
POST
|
Now when I run the original script in the Python window in the mxd i'm getting this error: NameError: name 'paths' is not defined. This code ran fine this morning
... View more
07-17-2015
08:36 AM
|
0
|
11
|
734
|
POST
|
I have this script below. When the three arguments are set as variables and I run the script in the ArcMap Python window to test it it runs perfectly. I created a tool for this script. In the parameters for the tool properties I have the Data Types for the 3 arguments are set as "SQL expressions" and all the data types for the feature layers created are "Feature Layers" with a "Type: Derived" and "Direction: Output". First problem: when I run the tool with the script as is i get this error 'RuntimeError: LayerObject: Set attribute showLabels does not exist'. I remove the code block that applies the labels then I get this error 'ValueError: Unknown value for Extent argument'. Running the script in the mxd both code blocks work perfectly. Second Problem: I remove both code blocks from the script and run the tool and nothing happens. No errors. Just doesn't add layers. # Import modules
import os, arcpy
# Set arguments
pws = arcpy.GetParameterAsText(0)
ass_pws = arcpy.GetParameterAsText(1)
mtr_recpws = arcpy.GetParameterAsText(2)
# Set variables
sources = r"V:\Source Water Protection\SWAP Model\SWAP.code_newrasters\GIS\SWAP.gdb\sources" # Will need to change if used outside of SWPP staff because of directory permissions. "Sources" feature class is in WATER_FACILITY.gdb
assessment = r"V:\Source Water Protection\SWAP Model\SWAP.code_newrasters\GIS\SWAP.gdb\assessment_areas" # Will need to change if used outside of SWPP staff because of directory permissions. "Assessments" feature class not in WATER_FACILITY.gdb..
meter = r"V:\WATER_FACILITY\WATER_FACILITY.gdb\MASTER_METER"
files = ["BACTI", "DBP", "DBP_STAGE2", "OFFICE", "PRV", "PUMP_STATION", "SERVICE_AREA_COMBO", "TANK", "VALVE_MISCELLANEOUS", "WTP"] # list all names used for feature classes ans .lyr files.
layers = ["Bacti", "DBP", "DBP Stage 2", "Office", "PRV", "Pump Station", "Service Area", "Tank","Valve", "Water Treatment Plant"]
src_layer = "Source"
ass_layer = "Assessment Area"
mtr_layer = "Master Meter"
src_symb = r"V:\Source Water Protection\PWS_ID_Tool\SOURCE.lyr"
ass_symb = r"V:\Source Water Protection\PWS_ID_Tool\ASSESSMENT.lyr"
mtr_symb = r"V:\Source Water Protection\PWS_ID_Tool\MASTER_METER.lyr"
root = r"V:\WATER_FACILITY\WATER_FACILITY.gdb"
symRoot = r"V:\Source Water Protection\PWS_ID_Tool"
# Create directory paths, make feature layers, and apply symbologies.
for i, file in enumerate(files):
path = os.path.join(root, files) # Create directory path for featureclasses
symPath = os.path.join(symRoot, files + ".lyr") # Create directory path for .lyr files
arcpy.MakeFeatureLayer_management(paths, layers, pws) # Make all the layers from "files" list
arcpy.ApplySymbologyFromLayer_management(layers, symPaths) # Apply the symbologies from "symNames" list.
arcpy.MakeFeatureLayer_management(assessment, ass_layer, ass_pws)
arcpy.ApplySymbologyFromLayer_management(ass_layer, ass_symb)
arcpy.MakeFeatureLayer_management(meter, mtr_layer, mtr_recpws)
arcpy.ApplySymbologyFromLayer_management(mtr_layer, mtr_symb)
arcpy.MakeFeatureLayer_management(sources, src_layer, pws) # Ordered to have the "Source" layer in the 0 position.
arcpy.ApplySymbologyFromLayer_management(src_layer, src_symb)
# Apply label
mxd = arcpy.mapping.MapDocument("CURRENT") # Reference to current open map document. Could insert path.
layer = arcpy.mapping.ListLayers(mxd, "")[0] # Indexing for first layer in table of contents. "Make feature layers" functions ordered so "Source" is in 0 position.
if layer.supports("LABELCLASSES"):
for lblclass in layer.labelClasses:
lblclass.showClassLabels = True
lblclass.expression = '"%s" & [SOURCE_ID] & "%s"' % ("<CLR red='255'><FNT size = '12'>", "</FNT></CLR>")
layer.showLabels = True
arcpy.RefreshActiveView()
#Apply extent from "Source" layer
mxd = arcpy.mapping.MapDocument("CURRENT") # Using current map, can also use a path to an mxd here
df = arcpy.mapping.ListDataFrames(mxd)[0]
lyr = arcpy.mapping.ListLayers(mxd, "", df)[0]
ext = lyr.getExtent()
df.extent = ext Message was edited by: Brad Jones
... View more
07-17-2015
07:35 AM
|
0
|
25
|
5841
|
POST
|
THANKS! I knew there was a way to do it. I haven't ever used the os module but I will explore this. The fc names I can't change but I can change the .lyr names to match so I will only have one list. you have no idea how giddy this makes me. Ha!
... View more
07-10-2015
05:30 AM
|
0
|
0
|
444
|
POST
|
I'm building a tool where a coworker can enter an ID# (called PWS ID) and then go through choose from a list of features (about 15) they want added from to the map based on the ID#. The tool will select the features based on the ID number, add them as a layer to the map and add the symbology. It wont create any new data, just what is stored in the map memory while it is open. I'm just working on the code at this point. I have a script with A LOT of variables and iterations of arcpy.MakefeatureLayer_management and arcpy.ApplySymbologyFromLayer_managment functions. I know I can hardcode the path to the .lyr files used for symbology, but I'm drawing a blank from there. I'm very much a Python novice and I cant figure out if it can be done by a for loop with arcpy.mapping.ListLayers (for symbology) or some other way. Also, I didn't add the whole script. I left out the code for labels and applying the extent of a layer. Thanks. # Import module(s) import arcpy from arcpy import env # Set overwrite option env.overwriteOutput = True # Local variables. Reduce number of variables. Hardcode path for ApplySymbologyFromLayer function or create a list or dictionary? pws = "PWS_ID='465'" # SQL query. ass_pws = "PWS_ID1 = '465'" # SQL query. Assessment table has different firle dname for PWS ID. mtr_recpws = "REC_ID = '465'" # SQL query. 'REC_ID" is PWS ID of PWS receiving water through master meter, I assume. sources = "V:\\Source Water Protection\\SWAP Model\\SWAP.code_newrasters\\GIS\\SWAP.gdb\\sources" # Will need to change if used outside of SWPP staff because of directory permissions. assessment = "V:\\Source Water Protection\\SWAP Model\\SWAP.code_newrasters\\GIS\\SWAP.gdb\\assessment_areas" # Will need to change if used outside of SWPP staff because of directory permissions. Assessments not in WATER_FACILITY.gdb. srvc_area = "V:\\WATER_FACILITY\\WATER_FACILITY.gdb\\SERVICE_AREA_COMBO" bacti = "V:\\WATER_FACILITY\\WATER_FACILITY.gdb\\BACTI" wtp = "V:\\WATER_FACILITY\\WATER_FACILITY.gdb\\WTP" dbp2 = "V:\\WATER_FACILITY\\WATER_FACILITY.gdb\\DBP_STAGE2" dbp = "V:\\WATER_FACILITY\\WATER_FACILITY.gdb\\DBP" tank = "V:\\WATER_FACILITY\\WATER_FACILITY.gdb\\TANK" valve = "V:\\WATER_FACILITY\\WATER_FACILITY.gdb\\VALVE_MISCELLANEOUS" mstr_mtr = "V:\\WATER_FACILITY\\WATER_FACILITY.gdb\\MASTER_METER" waterline = "V:\\WATER_FACILITY\\WATERLINES.gdb" pumpstn = "V:\\WATER_FACILITY\\WATER_FACILITY.gdb\\PUMP_STATION" prv = "V:\\WATER_FACILITY\\WATER_FACILITY.gdb\\PRV" press_plane = "V:\\WATER_FACILITY\\WATER_FACILITY.gdb\\PRESSURE_PLANES" office = "V:\\WATER_FACILITY\\WATER_FACILITY.gdb\\OFFICE" src_layer = "Sources" ass_layer = "Assessment Area" srvc_layer = "Service Area" bacti_layer = "Bacti" wtp_layer = "WTP" dbp_layer = "DBP" dbp2_layer = "DBP Stage 2" tank_layer = "Tank" valve_layer = "Valve" mtr_layer = "Master Meter" line_layer = "Waterline" pump_layer = "Pump Station" prv_layer = "PRV" press_layer = "Pressure Plane" ofc_layer = "Office" src_symb = "V:\\Source Water Protection\\PWS_ID_Tool\\SOURCE.lyr" ass_symb = "V:\\Source Water Protection\\PWS_ID_Tool\\ASSESSMENT.lyr" wtp_symb = "V:\\Source Water Protection\\PWS_ID_Tool\\WTP.lyr" valve_symb = "V:\\Source Water Protection\\PWS_ID_Tool\\VALVE.lyr" tank_symb = "V:\\Source Water Protection\\PWS_ID_Tool\\TANK.lyr" dbp_symb = "V:\\Source Water Protection\\PWS_ID_Tool\\DBP.lyr" dbp2_symb = "V:\\Source Water Protection\\PWS_ID_Tool\\DBP2.lyr" bacti_symb = "V:\\Source Water Protection\\PWS_ID_Tool\\BACTI.lyr" mtr_symb = "V:\\Source Water Protection\\PWS_ID_Tool\\MASTER_METER.lyr" ofc_symb = "V:\\Source Water Protection\\PWS_ID_Tool\\OFFICE.lyr" prv_symb = "V:\\Source Water Protection\\PWS_ID_Tool\\PRV.lyr" pump_symb = "V:\\Source Water Protection\\PWS_ID_Tool\\PUMP.lyr" # Make feature layers arcpy.MakeFeatureLayer_management(office, ofc_layer, pws) arcpy.MakeFeatureLayer_management(press_plane, press_layer, pws) arcpy.MakeFeatureLayer_management(srvc_area, srvc_layer, pws) arcpy.MakeFeatureLayer_management(mstr_mtr, mtr_layer, mtr_recpws) arcpy.MakeFeatureLayer_management(pumpstn, pump_layer, pws) arcpy.MakeFeatureLayer_management(prv, prv_layer, pws) arcpy.MakeFeatureLayer_management(tank, tank_layer, pws) arcpy.MakeFeatureLayer_management(valve, valve_layer, pws) arcpy.MakeFeatureLayer_management(wtp, wtp_layer, pws) arcpy.MakeFeatureLayer_management(dbp, dbp_layer, pws) arcpy.MakeFeatureLayer_management(dbp2, dbp2_layer, pws) arcpy.MakeFeatureLayer_management(bacti, bacti_layer, pws) arcpy.MakeFeatureLayer_management(sources, src_layer, pws) arcpy.MakeFeatureLayer_management(assessment, ass_layer, ass_pws) # Apply the symbology from the symbology layer to the input layers arcpy.ApplySymbologyFromLayer_management(src_layer, src_symb) arcpy.ApplySymbologyFromLayer_management(ass_layer, ass_symb) arcpy.ApplySymbologyFromLayer_management(bacti_layer, bacti_symb) arcpy.ApplySymbologyFromLayer_management(wtp_layer, wtp_symb) arcpy.ApplySymbologyFromLayer_management(valve_layer, valve_symb) arcpy.ApplySymbologyFromLayer_management(dbp_layer, dbp_symb) arcpy.ApplySymbologyFromLayer_management(dbp2_layer, dbp2_symb) arcpy.ApplySymbologyFromLayer_management(tank_layer, tank_symb) arcpy.ApplySymbologyFromLayer_management(valve_layer, valve_symb) arcpy.ApplySymbologyFromLayer_management(mtr_layer, mtr_symb) arcpy.ApplySymbologyFromLayer_management(ofc_layer, ofc_symb) arcpy.ApplySymbologyFromLayer_management(prv_layer, prv_symb) arcpy.ApplySymbologyFromLayer_management(pump_layer, pump_symb)
... View more
07-09-2015
01:23 PM
|
0
|
2
|
2987
|
POST
|
Simplifying the feature worked. I didn't initially think this was the problem because the original data set published OK. Thanks.
... View more
05-20-2015
12:11 PM
|
0
|
0
|
1321
|
POST
|
Also, the original data displays fine from feature layer created from the file geodatabse. This is about 94 out of 1800 features.
... View more
05-20-2015
07:44 AM
|
0
|
2
|
1321
|
Title | Kudos | Posted |
---|---|---|
2 | 04-06-2016 11:38 AM |
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:23 AM
|