POST
|
Based on the responses in the other forum, something like this should work: for m in range(1, 13):
print (m-1)/3+1 where the outcome is: 1 1 1 2 2 2 3 3 3 4 4 4 I can't think of a way that will take my date = datetime.date.today() and use the math they provided on that to check over my date to determine which quarter it belongs to. **UPDATE** Based on Blake's update, this may be the easiest solution.
... View more
07-10-2017
11:16 AM
|
0
|
0
|
1447
|
POST
|
I am currently writing a script where it's to automate generating reports for end of quarter reports. Part of the naming convention for the folders includes Q1, Q2, Q3, or Q4 based on which quarter it is for based on the date it is generated. So far, my code looks like this: import arcpy
import datetime
date = datetime.date.today()
quarter = 'Q1' if '2017-01-01' =< str(date) =< '2017-03-31' elif 'Q2' if '2017-04-01' =< str(date) =< '2017-06-30' elif 'Q3' if '2017-07-01' =< str(date) =< '2017-09-30' else 'Q4' My issue is that I get an output of Q4 when I try print quarter . The output generated should have been Q3 as I ran this today (July 10, 2017). If I change the ending of the code to be 'Q4' if '2017-10-01' =< str(date) =< '2017-12-31' , the result would be a syntax error. What am I doing wrong and how can I fix it but also stored the if conditional in one line and set it equal to the variable quarter?
... View more
07-10-2017
10:26 AM
|
0
|
13
|
2466
|
POST
|
The code is completely different but I wanted to know if the way i have msg = to the message box if that will read whatever the user input to use later in the script? In a sense I wanted to see if I am placing the variable in the right way
... View more
03-14-2017
12:37 PM
|
0
|
0
|
997
|
POST
|
Joshua, I am currently working on another tool where setting the user input equal to a variable is crucial. Is this the right way to do it in terms of setting the variable equal to something the user can do an input and then a conditional to check on what they input? if editor.isEditing == True:
pythonaddins.GPToolDialog(toolPath, 'CustomExportTool')
elif editor.isEditing == False:
pythonaddins.MessageBox("", "", 4)
msg = pythonaddins.MessageBox("", "", 4)
if msg == 'Yes':
... View more
03-14-2017
12:06 PM
|
0
|
2
|
997
|
POST
|
Joshua is this what you had in mind? import arcpy
import pythonaddins
import os
toolPath = r'path to toolboox.tbx'
workspace = 'some workspace'
editor = arcpy.da.Editor(workspace)
if editor.isEditing == 'true':
pythonaddins.GPToolDialog(toolPath, 'CustomExportTool')
elif editor.isEditing == 'false':
pythonaddins.MessageBox("You must be in an edit session to run the Custom Export Tool. If you wish to turn an edit session on, please click 'yes'. If you do not wish to turn an edit session on, please click 'no'.", "Turn Editor On?", 4)
msg = pythonaddins.MessageBox("You must be in an edit session to run the Custom Export Tool. If you wish to turn an edit session on, please click 'yes'. If you do not wish to turn an edit session on, please click 'no'.", "Turn Editor On?", 4)
if msg == 'yes':
editor.startEditing(False, False)
pythonaddins.GPToolDialog(toolPath, 'CustomExportTool')
elif msg == 'no':
quit
... View more
03-10-2017
12:32 PM
|
0
|
4
|
997
|
POST
|
Hey Joshua I just tried what you suggested but the Message Box did not pop up and so the value could not be stored. Any solutions on fixing this?
... View more
03-10-2017
12:03 PM
|
0
|
0
|
2907
|
POST
|
And would you define this variable at the beginning or where would you implement that variable in the code I have?
... View more
03-10-2017
09:37 AM
|
0
|
0
|
2907
|
POST
|
So I made a previous post on how to do a check in my addin module to see if the user using a custom tool was in an edit session. based on thoughtful discussions and research, I came to this conclusion for my script hoping for it to work. You're able to click on the tool but then nothing happens. I am not able to get to the Message Box and nothing happens with editor in terms of starting an edit session. Do I need to define my variables right after class or can I leave them in the portion. Any input and help would be greatly appreciated. How am I able to get my Message Box to pop up? def onClick(self): My entire code is the following: class tool_project(object):
"""Implementation for Mapping_Tools_addin.tool_project (Button)"""
def __init__(self):
self.enabled = True
self.checked = False
def onClick(self):
ws = r"workspace location"
workspace = os.path.dirname(ws)
editor = arcpy.da.Editor(workspace)
if editor.isEditing == 'true':
pythonaddins.GPToolDialog(toolPath, 'Tool Project')
elif editor.isEditing == 'false':
pythonaddins.MessageBox("You must be in an edit session to run this tool. If you wish to turn an edit session on, please click 'yes'. If you do not wish to turn an edit session on, please click 'no'.", "Turn Editor On?", 4)
if mb_type == 'yes':
editor.startEditing(False, False)
pythonaddins.GPToolDialog(toolPath, 'Tool Project')
elif mb_type == 'no':
quit mb_type is the third parameter in the pythonaddins.MessageBox module. More information regarding it can be found here.
... View more
03-10-2017
08:55 AM
|
0
|
1
|
1205
|
POST
|
So I believe doing it this way may actually work in a sense to get the Message Box using the python add-ins module. However, one issue I am having is doing the check to see which value from the message box the user selected. This is the first thing that happens when the user selects to use this tool. This is an add-in portion of the tool. Any help on figuring out how to call on the value in the Message Box will be helpful. The mb_type here is 4 so that the message box type is yes/no. Other mb_types and information about python add-ins can be found here. So my issue is figuring out how to see if the Message Box value the user selected was a yes or a no. import arcpy
import pythonaddins
import os
toolPath = r'path to toolboox.tbx'
workspace = 'some workspace'
editor = arcpy.da.Editor(workspace)
if editor.isEditing == 'true':
pythonaddins.GPToolDialog(toolPath, 'CustomExportTool')
elif editor.isEditing == 'false':
pythonaddins.MessageBox("You must be in an edit session to run the Custom Export Tool. If you wish to turn an edit session on, please click 'yes'. If you do not wish to turn an edit session on, please click 'no'.", "Turn Editor On?", 4)
if MessageBox == 'yes':
editor.startEditing(False, False)
pythonaddins.GPToolDialog(toolPath, 'CustomExportTool')
elif MessageBox == 'no':
quit
... View more
03-10-2017
06:03 AM
|
0
|
8
|
2907
|
POST
|
Joshua, so it's actually a Runtime Error that says "Objects in this class cannot be updated outside an edit session [lists the feature class]." Then it says "Failed to execute (ToolName)." So there wasn't an error code you get and so I'm wondering if using exceptions would work then?
... View more
03-09-2017
09:57 AM
|
1
|
2
|
701
|
POST
|
I've never worked with exceptions before so I was wondering if you have an example of what it may look like and the formatting of the script so I may try that out.
... View more
03-09-2017
09:33 AM
|
0
|
0
|
997
|
POST
|
Hi Joshua, so the error pops up milliseconds to like 2 seconds after you start running the tool. The tool is a custom export tool that has the function updateCursor function, which updates the fields to a particular value rather than leaving the blank fields as null values. The error states that updateCursor can not be used outside of the edit session and the rest of the tool does not run. Hence why I want to create this check to see if edit session is active and if not, to provide a prompt for the user that enables the user to select 'Yes' or 'No' to allow the script to turn an edit session on and then run the tool.
... View more
03-09-2017
08:50 AM
|
0
|
6
|
997
|
POST
|
Dan, I was thinking along the lines of the format I have below. This way users wouldn't have to turn editor on manually but just have to simply click yes or no. Would this work? if isEditing == True:
run tool
elif isEditing == False:
dialogue box pops up informing user to be in edit session and ask if they want script to turn it on for them:
if yes:
arcpy.startEditing()
elif no:
quit
... View more
03-08-2017
01:46 PM
|
0
|
12
|
2907
|
POST
|
I am currently working on a tool that uses the updateCursor function but the tool needs to be in an edit session to use. However some who may use the tool may end up not being in an edit session before running the tool and get an error. Rather than come ask me every time about the error, I'd like to implement an if statement in the script in the beginning that checks if the user is currently in an edit session, if they are then run tool. if not, a dialogue box explaining they need to be in an edit session and ask if they want the script to turn editor on. Formatted as such: #if edit session is on:
#run tool
#elif edit session is off:
#dialogue box explaining user has to be in edit session and asking if they want the script to turn editor on (Yes or no option):
#if yes:
#run tool
#if no:
#quit I am trying to do this without using the work done by Mark Cederholm as referenced in this post: How do I access ArcObjects from Python?, and code examples provided by Matt Wilkie in his "Snippits.py" file.
... View more
03-08-2017
12:52 PM
|
0
|
23
|
8629
|
POST
|
So here I'm testing it with showLabels being false to turn the labels off (default being Labels turned on). And this is was I passed in but it did not turn labels off for the feature classes x and y x = 'location of first feature class in the mxd'
y = 'locaion of the second feature class in the mxd'
layerList = [x, y]
mxd = acpy.mapping.MapDocument("CURRENT")
for lyr in arcpy.mapping.ListLayers(mxd):
if lyr.supports("LABELCLASSES"):
if lyr.datasetName in layerList:
lyr.showLabels = False
arcpy.RefreshActiveView()
... View more
03-06-2017
12:24 PM
|
0
|
0
|
1361
|
Title | Kudos | Posted |
---|---|---|
1 | 07-26-2018 09:12 AM | |
1 | 07-18-2017 01:12 PM | |
1 | 03-09-2017 09:57 AM | |
2 | 03-22-2018 09:49 AM | |
1 | 09-19-2017 01:18 PM |