POST
|
Ah, did not know that, thanks. Now I'm getting an error in the python window: So...where (and how) should I define WTF_toolbar?
... View more
04-27-2016
05:13 AM
|
0
|
0
|
926
|
POST
|
just tried the extension to disable the toolbar in layout view, and that doesn't work either. Code: import arcpy
import pythonaddins
class FishButton(object):
"""Implementation for WTF_addin.fish_button (Button)"""
def __init__(self):
self.enabled = True
## self.checked = False
def onClick(self):
self.mxd = arcpy.mapping.MapDocument('current')
## layer = r'\\msds.wv.de\dfsroot\HV\GROUP\Gis\DATEN\wvdat\Querbauwerke\Fischaufstieg.lyr'
layer = r'G:\Gis\DATEN\wvdat\Querbauwerke\Fischaufstieg.lyr'
activeDataFrame = self.mxd.activeView
df = arcpy.mapping.ListDataFrames(self.mxd, activeDataFrame)[0]
if arcpy.Exists(layer):
layerToAdd = arcpy.mapping.Layer(layer)
arcpy.mapping.AddLayer(df, layerToAdd, 'TOP')
else:
warningButton = pythonaddins.MessageBox("Die Datei ist nicht verfugbar.\nBitte kontaktieren Sie die GIS Abteilung.", "Datei nicht verfugbar", 0)
pass
class changeToolState(object):
"""Implementation for WTF_addin.disable (Extension)"""
def __init__(self):
# For performance considerations, please remove all unused methods in this class.
self.enabled = True
def activeViewChanged(self):
mxd = arcpy.mapping.MapDocument('current')
active_view = mxd.activeView
if active_view == 'PAGE_LAYOUT':
WTF_toolbar.enabled = False
print 'button has been disabled...'
else:
WTF_toolbar.enabled = True
print 'button re-enabled...'
arcpy.RefreshActiveView()
return And the corresponding config.xml: <ESRI.Configuration xmlns="http://schemas.esri.com/Desktop/AddIns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><Name>WTF</Name><AddInID>{8ed28a7b-5aa3-4474-baa5-7674acbb350a}</AddInID><Description>New Addin</Description><Version>0.1</Version><Image /><Author>Untitled</Author><Company>Untitled</Company><Date>04/27/2016</Date><Targets><Target name="Desktop" version="10.2" /></Targets><AddIn language="PYTHON" library="WTF_addin.py" namespace="WTF_addin"><ArcMap>
<Commands>
<Button caption="Fish" category="WTF" class="FishButton" id="WTF_addin.fish_button" image="" message="" tip=""><Help heading="" /></Button>
</Commands>
<Extensions>
<Extension autoLoad="true" category="WTF" class="changeToolState" description="" id="WTF_addin.disable" name="Disable" productName="Disable" showInExtensionDialog="true" />
</Extensions>
<Toolbars>
<Toolbar caption="WTF_Toolbar" category="WTF" id="WTF_addin.WTF_toolbar" showInitially="true"><Items><Menu refID="WTF_addin.cat_menu" /></Items></Toolbar>
</Toolbars>
<Menus>
<Menu caption="Category" category="WTF" id="WTF_addin.cat_menu" isRootMenu="false" isShortcutMenu="false" separator="false"><Items><Button refID="WTF_addin.fish_button" /></Items></Menu>
</Menus>
</ArcMap></AddIn></ESRI.Configuration>
... View more
04-27-2016
12:03 AM
|
0
|
1
|
926
|
POST
|
yeah, I posted this on stack overflow as well. disabling the toolbar in layout view is plan b, but that seems like it should be unnecessary...after all, you can add data with the 'Add Data' button while in layout view, so why wouldn't a custom toolbar with the same functionality work? seems like an oversight on ESRI's part.
... View more
04-26-2016
11:23 PM
|
0
|
0
|
926
|
POST
|
I also tried this, but it doesn't work either: import arcpy
import pythonaddins
class ButtonClass1(object):
"""Implementation for TEST_addin.button (Button)"""
def __init__(self):
self.enabled = True
## self.checked = False
self.mxd = arcpy.mapping.MapDocument('current')
def onClick(self):
layer = r'G:\Gis\DATEN\wvdat\Querbauwerke\Fischaufstieg.lyr'
activeDataFrame = self.mxd.activeView
df = arcpy.mapping.ListDataFrames(self.mxd, activeDataFrame)[0]
if activeDataFrame == 'PAGE_LAYOUT':
if arcpy.Exists(layer):
layerToAdd = arcpy.mapping.Layer(layer)
arcpy.mapping.AddLayer(df, layerToAdd, 'TOP')
else:
warningButton = pythonaddins.MessageBox("Die Datei ist nicht verfugbar.\nBitte kontaktieren Sie die GIS Abteilung.", "Datei nicht verfugbar", 0)
else:
if arcpy.Exists(layer):
layerToAdd = arcpy.mapping.Layer(layer)
arcpy.mapping.AddLayer(df, layerToAdd, 'TOP')
else:
warningButton = pythonaddins.MessageBox("Die Datei ist nicht verfugbar.\nBitte kontaktieren Sie die GIS Abteilung.", "Datei nicht verfugbar", 0)
pass
... View more
04-26-2016
04:04 AM
|
0
|
0
|
926
|
POST
|
Hello All, I've developed a python addin toolbar that adds a desired layer file (chosen from a menu in the toolbar) to the table of contents in a project. The functionality only works, however, when the project is in the data frame view -- clicking a layer in the menu does nothing if the project is in the layout view. I've googled around, but haven't found a sollution to this issue. Anyone have any ideas? Feedback is greatly appreciated! Using: ArcGIS 10.2.2, Python 2.7 Sample code: # -*- coding: utf-8 -*-
import arcpy
import pythonaddins
class FD_Bau_Fischaufstiege(object):
"""Implementation for Themenmanager_addin.button (Button)"""
def __init__(self):
self.enabled = True
## self.checked = False
self.mxd = arcpy.mapping.MapDocument('current')
def onClick(self):
layer = r'G:\Gis\DATEN\wvdat\Querbauwerke\Fischaufstieg.lyr'
activeDataFrame = self.mxd.activeView
df = arcpy.mapping.ListDataFrames(self.mxd, activeDataFrame)[0]
if arcpy.Exists(layer):
layerToAdd = arcpy.mapping.Layer(layer)
arcpy.mapping.AddLayer(df, layerToAdd, 'TOP')
else:
warningButton = pythonaddins.MessageBox("Die Datei ist nicht verfugbar.\nBitte kontaktieren Sie die GIS Abteilung.", "Datei nicht verfugbar", 0)
pass EDIT: I was able to get this to work in both views with the following code: class FD_Bau_Fischaufstiege(object):
"""Implementation for Themenmanager_addin.button (Button)"""
def __init__(self):
self.enabled = True
## self.checked = False
def onClick(self):
mxd = arcpy.mapping.MapDocument("CURRENT")
df = mxd.activeDataFrame
layer = r'G:\Gis\DATEN\wvdat\Querbauwerke\Fischaufstieg.lyr'
if arcpy.Exists(layer):
layerToAdd = arcpy.mapping.Layer(layer)
arcpy.mapping.AddLayer(df, layerToAdd, 'TOP')
else:
warningButton = pythonaddins.MessageBox("Die Datei ist nicht verfugbar.\nBitte kontaktieren Sie die GIS Abteilung.", "Datei nicht verfugbar", 0)
pass
... View more
04-26-2016
12:39 AM
|
0
|
10
|
4637
|
POST
|
Hi Marco, Sorry for the late answer, here's what I ended up with that works, hope it's helpful -- does a bit of logging for you too: # -*- coding: utf-8 -*-
import os
from os import path
import arcpy
from arcpy import env
from sets import Set
import time, datetime
from datetime import date
arcpy.env.overwriteOutput = True
newProjection = arcpy.SpatialReference(25832) # wkid for 'ETRS_1989_UTM_Zone_32N'
# ################### #
# FUNCTIONS #
# ################### #
def recursiveDatasets(workspace):
"""
Function iterates through a workspace and its subfolders using arcpy.da.walk and returns
a list of spatial reference objects of all geographic datasets (including those inside
geodatabases). Parameter: target workspace
"""
paths = []
uniquePaths = []
for dirpath, dirnames, filenames in arcpy.da.Walk(workspace):
for filename in filenames:
desc = arcpy.Describe(os.path.join(dirpath, filename))
if hasattr(desc, 'path'):
descPth = arcpy.Describe(desc.path)
if hasattr(descPth, 'dataType'):
# return list of FD paths and FC paths not in FD's
if descPth.dataType == 'FeatureDataset':
paths.append(dirpath)
elif desc.datasetType == 'FeatureClass':
paths.append(os.path.join(dirpath, filename))
# make list without duplicates
uniquePaths = list(set(paths))
return uniquePaths
def defineProjection(workspace, toRedefine):
""" Function redefines datasets in a given projection in a geodatabase. Parameters: workspace, projection to consider
"""
paths = recursiveDatasets(workspace)
for path in paths:
# create a description object for every dataset (incl. tables, relationship classes) not residing in FD
desc = arcpy.Describe(path)
if desc.spatialReference.Name == toRedefine:
arcpy.management.DefineProjection(desc.Name, newProjection)
print desc.Name + ' wurde neu definiert.'
else:
print desc.Name + ' wurde nicht neu definiert.'
def Logging(myLog, writeFormat, runDate, headers, list1, list2, colWdth):
""" Function will generates a log file composed of two columns (list1 and list2) with defined
headers and date of execution. Parameters: full log filepath, write format, date of execution,
headers, list1, list2, column width
"""
with open(myLog, writeFormat) as myLog:
myLog.write(runDate)
myLog.write(headers)
for item in zip(list1, list2):
myLog.write(colWdth.format(*item))
# ################# #
# MAIN #
# ################# #
def main():
print 'Processing geodatabase...'
workspace = arcpy.env.workspace = r'C:\Scripts\Redefine_Projection\Thomas\2016-01-25_GeoDB03_gd_Export.gdb'
toRedefine = 'ETRS_1989_UTM_Zone_32N_6stellen'
defineProjection(workspace, toRedefine)
datasets = recursiveDatasets(workspace)
print 'Logging results...'
# list of projections
projections = []
for dataset in datasets:
desc = arcpy.Describe(dataset)
projections.append(desc.spatialReference.Name)
# logging
myLog = r"C:\Scripts\Redefine_Projection\Log\RedefineProjection.log"
today = date.today()
runDate = 'Tag der Durchführung: ' + today.strftime("%Y.%m.%d") + '\n'
# first column header is 'Feature Class' justified left w/125 character buffer before 'Neue Spatial Reference' header
headers = '{0: <125}'.format('Pfad der Datensatz') + 'Spatial Reference' + '\n'
colWdth ="{:<125}"*2 + "\n" # 2 columns with 125 character width
Logging(myLog, 'a', runDate, headers, datasets, projections, colWdth)
if __name__ == '__main__':
main()
... View more
03-18-2016
02:16 AM
|
0
|
0
|
581
|
POST
|
Hello All, I'm running into an issue with a Python Addin. It's a button with functionality that makes use of the os module. Naturally I have 'import os' at the top of the button script in the install folder, but when I press the button in Arcmap, I'm getting the following error: Anyone else have this issue? Anyone have any ideas? Feedback greatly appreciated!!!
... View more
03-07-2016
12:19 AM
|
0
|
0
|
1937
|
POST
|
Hi Joshua, yeah, that's exactly what I was looking for, I was missing the [1] in there. Thanks!
... View more
02-29-2016
06:54 AM
|
0
|
0
|
1020
|
POST
|
Hi Mitch, thanks for the quick feedback. When I run that I get an error: 'row' is not defined.
... View more
02-29-2016
06:23 AM
|
0
|
2
|
1020
|
POST
|
Hello All, I'm trying to update the value in a specific field ('uid_n') in the last row of a table with a value read out of a text file. I've figured out how to return the last value in the table for the uid_n field, but am struggling with the actual update bit. Does anyone have any ideas? Any feedback is greatly appreciated! My code so far: import arcpy
from arcpy import env
import os
# open arcpar.txt
arcpar = open(r'C:\Users\admin\Desktop\ToeB 10.2\arcpar.txt')
# read UID line
line = arcpar.readlines()[1]
UID = line[4:-1]
# set workspace for arcpy
env.workspace = r'C:\Users\admin\Desktop\ToeB 10.2\Data Svenja\Toeb Svenja.gdb'
# possible feature classes
punkte = 'Punktobjekt'
# field to use to find last record in table
objectId = 'OBJECTID_1'
returnField = ["OBJECTID_1", "uid_n"]
sql_clause = (None,'ORDER BY {} DESC'.format(objectId))
last_row = ''
last_OID = ''
# function to copy text to clipbard
def addToClipBoard(text):
command = 'echo ' + text.strip() + '| clip'
os.system(command)
# call function to copy UID from arcpar.txt to clipboard
addToClipBoard(UID)
with arcpy.da.UpdateCursor(punkte, returnField, where_clause=None, sql_clause=sql_clause) as cursor:
last_row = cursor.next()
lastUID = last_row[1]
... View more
02-29-2016
06:16 AM
|
0
|
4
|
2855
|
POST
|
So I have a workable sollution to this based on everyone's feedback (see code below). The only nagging issue is that when I run recursiveDatasets in main() after redefining all feature classes and datasets, when I print spatialReference.name, it's still printing the old spatial reference I checked the SR in ArcCatalog for each FC and FD, and they have indeed been redefined: So why is it still printing the old SR? Is that output being drawn from a different parameter than that being displayed in the XY Coordinate System tab? I have also tried refreshing the geodatabase following the redefinition, but that makes no difference. Code: # -*- coding: utf-8 -*-
import os
from os import path
import arcpy
from arcpy import env
from sets import Set
import time, datetime
from datetime import date
arcpy.env.overwriteOutput = True
def recursiveDatasets(workspace):
""" Function iterates through a file geodatabase using arcpy.da.walk and returns a tuple
containing three lists: 1) uniqueFD, containing paths to each feature dataset in the geodatabase;
2) miscDatasets, containing all feature classes in a geodatabase not inside a feature dataset;
3) descriptions, containing description objects for every feature class and feature dataset in
the target geodatabase. Parameter: Workspace
"""
miscDatasets = []
featureDatasets = []
descriptions = []
for dirpath, path, filenames in arcpy.da.Walk(workspace):
for filename in filenames:
desc = arcpy.Describe(os.path.join(dirpath, filename))
if hasattr(desc, 'path'):
descPth = arcpy.Describe(desc.path)
descriptions.append(desc)
if hasattr(descPth, 'dataType'):
if descPth.dataType == 'FeatureDataset':
featureDatasets.append(dirpath)
else:
miscDatasets.append(os.path.join(dirpath, filename))
uniqueFD = list(set(featureDatasets))
return uniqueFD, miscDatasets, descriptions
def defineProjection(workspace):
""" Function redefines the existing projection for feature datasets and feature classes not residing in feature
datasets in a geodatabase. Parameter: workspace
"""
uniqueFD, miscDatasets, descriptions = recursiveDatasets(workspace)
for FC in miscDatasets:
desc = arcpy.Describe(FC)
if desc.datasetType == 'FeatureClass':
arcpy.DefineProjection_management(FC, newProjection)
for FD in uniqueFD:
arcpy.DefineProjection_management(FD, newProjection)
def main():
workspace = arcpy.env.workspace = os.path.join(r'C:\Scripts\Redefine Projection\MyGeodatabase.gdb')
newProjection = arcpy.SpatialReference(25832) # wkid for 'ETRS_1989_UTM_Zone_32N'
defineProjection(workspace)
uniqueFD, miscDatasets, newDescriptions = recursiveDatasets(workspace)
FCs = []
newSRs = []
for dataset in newDescriptions:
if dataset.datasetType == 'FeatureClass':
FCs.append(os.path.join(dataset.Path, dataset.Name))
newSRs.append(dataset.spatialReference.name)
print newSRs
if __name__ == '__main__':
main()
... View more
12-04-2015
01:45 AM
|
0
|
0
|
581
|
POST
|
Sorry for the delay, I was just now able to try Neil's sollution. According to the Help: All feature classes in a geodatabase feature dataset will be in the same coordinate system. The coordinate system for a geodatabase dataset should be determined when it is created. Once it contains feature classes, its coordinate system cannot be changed. This is not the case, however -- a feature dataset can indeed be redefined if it already contains feature classes (which will also be redefined along with the FD). The redefine tool simply generates a warning, but it still works. ESRI needs to update their help.
... View more
12-03-2015
03:00 AM
|
0
|
0
|
581
|
POST
|
So basically to get this to work, I used a couple of lines from Freddie's code -- my code now looks like this: workspace = os.path.join(os.path.dirname(__file__), "MyGeodatabase.gdb")
for k, v in FCFDdict.items():
try:
arcpy.conversion.FeatureClassToFeatureClass(k, v, os.path.basename(k) + "_trillium")
except arcpy.ExecuteError as e:
print(e.message)
... View more
11-26-2015
01:08 AM
|
1
|
0
|
1864
|
POST
|
Hi Freddie, Thanks so much for for your detailed and lengthy response, I realized that naming problem as I was playing with this. I guess once the FC's are done transferring I'll have to first delete the old origin FD's and then rename the new FC's...annoying, but I guess that's the clearest path.
... View more
11-26-2015
12:43 AM
|
0
|
1
|
1864
|
POST
|
From what I can tell from the help, you're right -- it looks like the in and out just require names, while the only parameter requiring a path is the destination. Also looks like there should be forward slashes in the destination path. I'm trying to export each Feature Class designated by the key to the Feature Dataset designated by the value. Right now I've got: for key, value in FCFDdict.iteritems():
destination = env.workspace = str(value.replace('\\', '/'))
print 'destination: ' + destination
inFC = str(os.path.basename(key))
print 'inFC: ' + inFC
inFCpath = str(key)
print 'inFCpath: ' + inFCpath
outFC = inFC
print 'outFC: ' + outFC
## arcpy.FeatureClassToFeatureClass_conversion(inFC, destination, outFC) which gives me: inFCpath is not being used, it's just for my reference to make sure it's correct. Nevertheless, when I uncomment the last line, I'm still getting:
... View more
11-25-2015
08:18 AM
|
0
|
1
|
1864
|
Title | Kudos | Posted |
---|---|---|
1 | 11-05-2015 05:33 AM | |
1 | 11-12-2015 01:59 AM | |
1 | 11-12-2015 03:27 AM | |
1 | 03-25-2015 03:18 AM | |
1 | 05-22-2015 01:45 AM |
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:23 AM
|