|
POST
|
I had not, but I was under the assumption that simply adding the python script to wthe toolbar as sufficient. I'll look into creating add-ins and see if it is worth the effort for what we need. Thanks for the suggestion!
... View more
07-30-2015
01:55 PM
|
0
|
3
|
1402
|
|
POST
|
I have been trying to come up with a custom toolbar that incorporates some of the python scripts that I have created, but I can't seem to get ArcMap to save some of the customizations that I make to the toolbar. I have created the custom toolbar, I made sure that the options to save customizations to the MXD were unchecked, and I added in a mix of standard tools as well as my python scripts. I edited labels and images to a point where I was happy with it, saved the map and closed it. None of the python scripts that I added in were saved in the toolbar. The standard tools stayed, but all python scripts just don't show up on the toolbar, and are no longer visible in the Customize > Commands > GP Tools section. Can you incorporate python scripts in a toolbar without the use of any other code? I'm not really sure why it even allows you to add a python script to a toolbar if it doesn't allow them to stay there after closing. I deleted my Normal.mxt file and started from scratch with no luck. Right now the scripts are stored within a toolbox on a shared drive so that we can all use them, which works, but I would like to create a toolbar if possible. Any suggestions?
... View more
07-30-2015
01:36 PM
|
0
|
5
|
5315
|
|
POST
|
That did the trick. I tried with a variable of 1 and 2, and both returned the desired results. Many thanks! I used the code pasted below: for row in cursor:
if (row[0] and numIDs < 2):
row[3] = "(" + str(row[2]) + ") - (" + str(row[0]) + ") - (" + str(row[1]) + ") - (01)"
elif (row[0] and nuIDs <3):
row[3] = "(" + str(row[2]) + ") - (" + str(row[0]) + ") - (" + str(row[1]) + ") - (01)"
row[4] = "(" + str(row[2]) + ") - (" + str(row[0]) + ") - (" + str(row[1]) + ") - (02)"
else
pass
cursor.updateRow(row) I'm a little confused why you have to designate it as a string only because I thought it was grabbing the actual value from the row reference. I didn't realize the program read the number literally, but rather thought it SAW row[0] and THOUGHT NodeID field. Either way, it works and you have helped me once again!
... View more
07-10-2015
02:36 PM
|
0
|
1
|
992
|
|
POST
|
I tried your suggestion with the same three scenarios as shown in my response to Dan (below), and I got the following results in order from top example to bottom: Example 1: "Runtime error Traceback (most recent call last): File "<string>", line 17, in <module> TypeError: coercing to Unicode: need string or buffer, NoneType found" Example 2: "Runtime error Traceback (most recent call last): File "<string>", line 16, in <module> TypeError: coercing to Unicode: need string or buffer, NoneType found" Example 3: Same as explained in my response to Dan where it seems like nothing really happens.
... View more
07-10-2015
01:59 PM
|
0
|
3
|
992
|
|
POST
|
I used your suggestion on all previous versions of the code and none worked. (param1 and param2) for row in cursor:
if (row[0] and numIDs < 2):
row[3] = "(" + row[2] + ") - (" + row[0] + ") - (" + row[1] + ") - (01)"
elif (row[0] and numIDs < 3):
row[3] = "(" + row[2] + ") - (" + row[0] + ") - (" + row[1] + ") - (01)"
row[4] = "(" + row[2] + ") - (" + row[0] + ") - (" + row[1] + ") - (02)"
cursor.updateRow(row) Returns this errors: "Runtime error Traceback (most recent call last): File "<string>", line 16, in <module> TypeError: coercing to Unicode: need string or buffer, NoneType found" (param1) and (param2) for row in cursor:
if (row[0]) and (numIDs < 2):
row[3] = "(" + row[2] + ") - (" + row[0] + ") - (" + row[1] + ") - (01)"
elif (row[0]) and (numIDs < 3):
row[3] = "(" + row[2] + ") - (" + row[0] + ") - (" + row[1] + ") - (01)"
row[4] = "(" + row[2] + ") - (" + row[0] + ") - (" + row[1] + ") - (02)"
cursor.updateRow(row) Returns the same error to the letter. And Lastly: if param1 if param2 for row in cursor:
if row[0]:
if numIDs < 2:
row[3] = "(" + row[2] + ") - (" + row[0] + ") - (" + row[1] + ") - (01)"
elif row[0]:
if numIDs < 3:
row[3] = "(" + row[2] + ") - (" + row[0] + ") - (" + row[1] + ") - (01)"
row[4] = "(" + row[2] + ") - (" + row[0] + ") - (" + row[1] + ") - (02)"
cursor.updateRow(row) This one doesn't seem to do anything. I'm not even sure if it runs. It doesn't kick back an error, but it also doesn't update the fields.
... View more
07-10-2015
01:49 PM
|
0
|
1
|
992
|
|
POST
|
The colon was missing only in entry error...I manually typed out the code because whenever I try to paste into the syntax highlighter it ends up cutting off pieces. (I just tested and realized that you could paste the code first and then apply the syntax highlighting...doh! Nothing like a simple mistake to make you feel dumb) I only used "&" because that's what Dan used in his examples. I substituted "and" in the same sample that was using "&", and I get the same error message: "Runtime error Traceback (most recent call last): File "<string>", line 16, in <module> TypeError: coercing to Unicode: need string or buffer, NoneType found"
... View more
07-10-2015
11:59 AM
|
0
|
8
|
992
|
|
POST
|
If row[0] has a null value, then I want the script to return nothing. Basically if there is no node name, then we don't need a circuit ID for that node. I ran the following samples and got different errors with each: for row in cursor:
if (row[0] != None):
if (numIDs == 1):
row[3] = "(" + row[2] + ") - (" + row[0] + ") - (" + row[1] + ") - (01)"
elif (numIDs == 2)
row[3] = "(" + row[2] + ") - (" + row[0] + ") - (" + row[1] + ") - (01)"
row[4] = "(" + row[2] + ") - (" + row[0] + ") - (" + row[1] + ") - (02)"
cursor.updateRow(row)
This returns the error message: "Parsing error SyntaxError: EOL while scanning string literal (line 16)" for row in cursor:
if (row[0] != None) & (numIDs < 2):
row[3] = "(" + row[2] + ") - (" + row[0] + ") - (" + row[1] + ") - (01)"
elif (row[0] != None) & (numIDs < 3):
row[3] = "(" + row[2] + ") - (" + row[0] + ") - (" + row[1] + ") - (01)"
row[4] = "(" + row[2] + ") - (" + row[0] + ") - (" + row[1] + ") - (02)"
cursor.updateRow(row)
This returns the error message: "Runtime error Traceback (most recent call last): File "<string>", line 16, in <module> TypeError: coercing to Unicode: need string or buffer, NoneType found"
... View more
07-10-2015
11:21 AM
|
0
|
11
|
2275
|
|
POST
|
The actual code that I used that doesn't update both the if and elif is below: import arcpy
numIDs = 2
fc = r'my node feature class'
fields = ('NodeID', 'HomeID', 'CustName', 'CircuitID1', 'CircuitID2')
with arcpy.da.UpdateCursor(fc, fields) as cursor:
for row in cursor:
if row[0] != None:
row[3] = "(" + row[2] + ") - (" + row[0] + ") - (" + row[1] + ") - (01)" # this works fine
elif row[0] != None and numIDs >= 2):
row[4] = "(" + row[2] + ") - (" + row[0] + ") - (" + row[1] + ") - (02)" # this one won't run
cursor.updateRow(row) If I take the elif statement exactly as it is and put it in the if portion, it works, so I know the syntax is there for it to work, but something isn't allowing it to work in tandem with the other in an if/elif/elif/elif/elif format. When I run it just as it it typed above, it just runs through and updated the first if, and ignores the second. Any ideas why?
... View more
07-10-2015
07:48 AM
|
0
|
13
|
2275
|
|
POST
|
Does the code have the ability to step through each row and update them accordingly? In my example above the first line simply checks to see if the NodeID field is populated, and then if so it updates the CircuitID1 field. However, the second line checks whether the NodeID field is populated AND if the input variable is > or = to 2, and if so it updates the CircuitID2 field. In the example above I used an input value of 1 just to see if it would stop there and not calculate the 2nd, and it seemed to work, but I believe it did for unwanted reasons. When I change the input variable to 2, the second line still doesn't calculate. If I remove the first line altogether and just run the second line, it populates the CircuitID2 field correctly. Ideally the code should step through each if statement, check the parameters, and conditionally update the corresponding field below it, right? if NodeID != None:
calculate CircuitID1
elif NodeID != None and input variable >= 2:
calculate CircuitID2
elif NodeID != None and input variable >= 3:
calculate CircuitID3 etc... So if I input 4, it'll update CircuitID1, 2, 3, and 4. However, if I only put 1, it'll update just CircuitID1. Is that not the way it should work?
... View more
07-09-2015
02:28 PM
|
0
|
0
|
2275
|
|
POST
|
Yeah, I noticed how the row corresponded with each position in the variable list, but I didn't realize that I would use the actual "row" nomenclature for the variable in the concatenation. That did the trick! Thanks once again, dkwiens! I'm very thankful for people like you and Dan_Patterson!
... View more
07-09-2015
01:24 PM
|
0
|
0
|
2275
|
|
POST
|
I use a script that calculates a lot of fields and runs a lot of summary statistics before exporting the results to Excel tables (a lot of the work that you have helped me with in other posts over the previous weeks). That script is ran from an ArcToolbox within ArcMap. This script is ran after we have created the data and made sure that all of the manually populated fields are populated, and then this script populates the rest and exports for us. Essentially the circuit ID fields have either gone unpopulated or done manually by the users, and I've been trying find the time to go through and figure out a way to automate the process of their creation. I could technically just do individual calculations for every single CircuitID field, but there are 10 per customer, and 5 total customers, so I would prefer not to rewrite the code for all 50 fields. Darren Wiens's suggestion above seems to be a good solution, and I think I have it nearly worked out, with the exception of the string issue.
... View more
07-09-2015
12:48 PM
|
0
|
0
|
408
|
|
POST
|
The UpdateCursor method works wonders, but I can't seem to get the string portion of the return calculation to work properly. It keeps returning a literal string. I tried single quotes, and I tried ' """ + var + "" ' both with an without the space in between, and I just kept getting a literal string. import arcpy
numIDs = arcpy.GetParameterAsText(0) # I equaled this to 1 in my testing to see if it would ignore CircuitID2 and it did
fc = r'my node feature class'
fields = ('Cust1NodeID', 'Cust1HomeID', 'Cust1Name', 'Cust1CircuitID1', 'Cust1CircuitID2', 'Cust1CircuitID3', 'Cust1CircuitID4', Cust1CircuitID5', 'Cust1CircuitID6', 'Cust1CircuitID7', 'Cust1CircuitID8', 'Cust1CircuitID9', 'Cust1CircuitID10')
with arcpy.da.UpdateCursor(fc, fields) as cursor:
for row in cursor:
if row[0] != None:
row[3] = "(" + Cust1Name + ") - (" + Cust1NodeID + ") - (" + Cust1HomeID + ") - (01)"
elif (row[0] != None and numIDs >= 2):
row[4] = "(" + Cust1Name + ") - (" + Cust1NodeID + ") - (" + Cust1HomeID + ") - (02)"
This runs through and only updates Cust1CircuitID1, but I just need to get over the whole literal string hand up. I only wrote it out to calculate the first two CircuitID fields, but as my script note above states, I set the variable to 1 so that it would only calculate the first one. I've seen the UpdateCursor function in other code samples, and I've seen reference to it, but I haven't tried it yet. Glad your suggestion led me to do a little research and learn it a little better . I'll likely be going back and updating some other code that I've created using this method.
... View more
07-09-2015
12:39 PM
|
0
|
18
|
2275
|
|
POST
|
*UPDATE* For samples of the correct code, see posts below. I'll start off by apologizing for not having any sort of sample of my code, but I am really just unsure on how to begin the code, so all I have is notes of what I need. I have a feature class that has a number of fields that are duplicated for 5 different customers. The fields that I need to focus on in this exercise are the Cust1Name, Cust1NodeID, Cust1HomeID, and 10 Cust1CircuitID fields. I'm using "Cust1", "Cust2", etc only as examples in place of their actual names...just stating that to eliminate your efforts in trying to add the customer number in a potential for/while loop. Essentially the fields look as they do below: Cust1Name Cust1NodeID Cust1HomeID Cust1CircuitID1 ... Cust1CirctuitID10 Cust2Name Cust2NodeID Cust2HomeID Cust2CircuitID1 ... Cust2CircuitID10 etc... My feature class has fields for all 5 customers, but not all 5 will be populated. I've used the Cust#NodeID field as my reference for whether calculations will run or not because that field determines if they are needed or not. Populated means run the calculation, while Null means do nothing. if Cust1NodeID != None:
return # insert calculation here
else:
return None I also need to get a users input to know the amount of circuit ID's needed. The number varies from 1 to 10 circuit ID's. numberIDs = arcpy.GetParameterAsText(0) With this information I need the script to go through each Cust#NodeID field to check and see if it's null or not. If it's null, keep moving...if it has data, calculate the amount of circuit ID fields needed based on the input. Again, sorry for having nothing to start with. I'm just confused on which route to take (for loop, while loop, if/if...), and I can't figure out any of them either way. I'm just not sure how to add so many arguments together. *EDIT* I'll also note that the circuit ID calculation itself is just a concatenation of the given fields, as shown below: Cust1CircuitID1 = (Cust1Name) - (Cust1NodeID) - (Cust1HomeID) - (01) Cust1CircuitID2 = (Cust1Name) - (Cust1NodeID) - (Cust1HomeID) - (02) etc...
... View more
07-09-2015
09:46 AM
|
0
|
22
|
7316
|
|
POST
|
Thank you kindly for that explanation, Joshua Bixby.
... View more
07-01-2015
02:28 PM
|
0
|
0
|
437
|
|
POST
|
Great! That works like a charm. Now moving on to why? What does the triple double quotes do? I'm assuming the single quotes make it a string, correct? Thanks for figuring that out for me, Darren Wiens!
... View more
07-01-2015
01:35 PM
|
0
|
2
|
4449
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 06-16-2015 11:55 AM | |
| 1 | 02-04-2015 02:30 PM | |
| 2 | 03-23-2015 11:22 AM | |
| 7 | 03-23-2015 10:09 AM | |
| 3 | 03-23-2016 12:54 PM |
| Online Status |
Offline
|
| Date Last Visited |
03-06-2025
09:05 PM
|