|
POST
|
Hi. I'm trying to create a project package in which the ArcGIS Pro project consists of one map with several featurelayers, standalone tables, a task and a python toolbox. The python toolbox consists of 21 tools each in it's own .py file. The task and the tools within the python toolbox works ok. When I try to create a project package, I get an error which says ERROR 001659: Consolidating toolbox. I've ran the "Analyze Tool for Pro" for all of the tools in the python toolbox, and there are no problems. When trying to run the "Consolidate Toolbox"-tool, I get an error saying ModuleNotFoundError: No module named 'AndelerTilExcelTool', even though the module (tool) exists. Does anyone know what might be wrong? Here's how I import the modules in the python toolbox (.pyt), the list of modules as been shortened. # -*- coding: utf-8 -*-
import arcpy
import os
import sys
geovegScripts = os.path.join(os.path.dirname(__file__), "Scripts")
geovegSymbology = os.path.join(os.path.dirname(__file__), "Symbology")
sys.path.append(geovegScripts)
geovegModules = ['AndelerTilExcelTool',
'BearbeidAR5Tool',
'BearbeidBygningerTool',
'BeregnAndelerTool']
for module in geovegModules:
if module in sys.modules:
del(sys.modules[module])
from AndelerTilExcelTool import AndelerTilExcel
from BearbeidAR5Tool import BearbeidAR5
from BearbeidBygningerTool import BearbeidBygninger
from BeregnAndelerTool import BeregnAndeler
class Toolbox(object):
def __init__(self):
"""Define the toolbox (the name of the toolbox is the name of the
.pyt file)."""
self.label = "Geoveg PythonToolbox"
self.alias = "Geoveg verktøy"
# List of tool classes associated with this toolbox
self.tools = [AndelerTilExcel, BearbeidAR5, BearbeidBygninger, BeregnAndelerTool] Here are some of the code from AndelerTilExcel, which is saved in the file AndelerTilExcelTool.py class AndelerTilExcel(object):
def __init__(self):
"""Define the tool (tool name is the name of the class)."""
self.label = "Andeler til Excel"
self.description = ""
self.canRunInBackground = False
def getParameterInfo(self):
"""Define parameter definitions"""
params = None
return params
def isLicensed(self):
"""Set whether tool is licensed to execute."""
return True
def updateParameters(self, parameters):
"""Modify the values and properties of parameters before internal
validation is performed. This method is called whenever a parameter
has been changed."""
return
def updateMessages(self, parameters):
"""Modify the messages created by internal validation for each tool
parameter. This method is called after internal validation."""
return
def execute(self, parameters, messages):
"""The source code of the tool."""
try:
fc_resultat = r"vegsone_bygninger"
tittel = "Rapport andelsfordeling"
rapport = r"C:\temp\Andelsfordeling.xlsx"
#Oppretter ny excel-fil og legger til arbeidsark
wb = openpyxl.Workbook()
ws = wb.create_sheet("Andelsfordeling")
#Legger inn overskrifter i arbeidsarket
ws['A1'] = tittel
ws['A2'] = "GNR/BNR"
ws['B2'] = "Partsnummer"
ws['D2'] = "Andel"
#Henter informasjon om andelsfordelingen
felter = ["SAK", "KOMM", "GNR", "BNR", "FNR", "SNR",
"PARTSNUMMER", "ANDEL"]
with arcpy.da.SearchCursor(fc_resultat, felter, sql_clause=(None, 'ORDER BY PARTSNUMMER DESC')) as cursor:
linjeNr = 3
for row in cursor:
sak = row[0]
kommune = row[1]
gnr = row[2]
bnr = row[3]
fnr = row[4]
snr = row[5]
partsnummer = row[6]
andel = row[7]
ws['A'+str(linjeNr)] = "{0}/{1}/{2}/{3}".format(gnr, bnr, fnr, snr)
ws['B'+str(linjeNr)] = partsnummer
ws['C'+str(linjeNr)] = andel
linjeNr += 1
#Lagrer Excel-filen
wb.save(filename=rapport)
except:
# Get the traceback object
tb = sys.exc_info()[2]
tbinfo = traceback.format_tb(tb)[0]
# Concatenate information together concerning the error into a message string
pymsg = "PYTHON ERRORS:\nTraceback info:\n" + tbinfo + "\nError Info:\n" + str(sys.exc_info()[1])
msgs = "ArcPy ERRORS:\n" + arcpy.GetMessages(2) + "\n"
# Return Python error messages for use in script tool or Python window
arcpy.AddError(pymsg)
arcpy.AddError(msgs)
# Print Python error messages for use in Python / Python window
logging.error(pymsg)
logging.error(msgs)
return
def postExecute(self, parameters):
"""This method takes place after outputs are processed and
added to the display."""
return As mentioned the python toolbox works ok, but not when consolidated or packaged.
... View more
03-09-2023
05:27 AM
|
0
|
6
|
1654
|
|
POST
|
Hi. I've created an ArcGIS Pro Add-in which contains some buttons, that I'd like to enable/disable based on a condition. I've read about conditions and states in the ArcGIS Pro SDK Wiki, but I'm not quite sure on which event to subscribe to. The add-in is dependent on the existence of three layers in the map and two tables (all in the same filegeodatabase). I've already made a method that checks if the layers exists (when the buttons are clicked), but I'd like my buttons to be enabled if the layers exists in the map, and disabled if one or more of the layers are missing. How do I proceed with this? Which events should I be subscribing to?
... View more
03-01-2023
06:20 AM
|
0
|
2
|
1378
|
|
IDEA
|
@AmirBar-Maor Since I want to use the value recieved from the "Get Attributes" action when doing the calculation, the only possibility to is to use action when exiting the step; since the value does not exists neither when starting the step or prior to execution. When adding another step to the palette, after the "Get Attributes step", the variable created in the "Get Attribute step" is not accessible. The variable is only accessible in the palette step where it's created or in the later steps outside the palette.
... View more
02-20-2023
11:54 PM
|
0
|
0
|
2370
|
|
IDEA
|
@AmirBar-Maor You're almost right, I want the user to view the attribute and modify it. Since I'm doing the calculate field action, I don't need to copy the attribute. Just to view and edit. It could be done by opening the attribute pane, but I don't want the user to view or modify any of the other fields. If I expose the other fields to the user, I'm pretty sure some of them would end up editing the wrong attribute 🙂 One workaround is creating a pythonscript that changes the visibility of the field. I'll probably go for that solution.
... View more
02-20-2023
11:32 PM
|
0
|
0
|
1789
|
|
IDEA
|
Hi @AmirBar-Maor . There might be some misunderstanding here. I'm aware that it's possible to copy attributes with the additional action, but that's not what I was describing (or trying to describe). I've selected a feature and have created a task with the action Get Attributes, where the user can change the attributes. Here you can see that the action "Get Attribute" shows the default value of <Null> on the attribute values, but the selected feature has already values in these fields. The idea is to show these values. I can't see that it's possible to assign the "Get Attribute"-preset value to the feature's value (or value from Copy Attributes as you mentioned).
... View more
02-20-2023
06:00 AM
|
0
|
0
|
1804
|
|
IDEA
|
Hi @AmirBar-Maor . When setting up a palette with a palette-step with the action Get Attributes, it seems that "Calculate Field" (with the result of Get Attributes) is only available as an action when exiting the step. This means that the task moves to the next step (out of the palette step). The idea might be to do this within the palette.
... View more
02-20-2023
05:48 AM
|
0
|
0
|
2384
|
|
IDEA
|
When creating a ArcGIS Pro task, it's possible to create a task step with the action "Get Attributes" which allows the user to input values. This might be used later, for example in a task step which uses the action Calculate Attribute. Today it's possible to specify a preset value for the input field, but not a dynamic value. In the configuration of the "Get Attributes" action, we already define the related table and field, so this is already done. The idea is to be able to use the existing value from this field as an alternative to manually specifying the preset value.
... View more
02-20-2023
01:12 AM
|
0
|
5
|
1843
|
|
IDEA
|
When creating a task, you might have several task steps and today all of these steps are sequential. A nice feature would be to be able to repeat some of the steps in the task several times. It might be usefull in case you'd like to select a feature and edit it's properties, and then repeat the process with another feature. As shown in the attached image, the button should be enabled when step 5 has been run and take the user back to the configured step (in this case nr 4).
... View more
02-20-2023
12:44 AM
|
2
|
5
|
2434
|
|
POST
|
In my organization we're about to move GIS-users from ArcMap to ArcGIS Pro (3.X). The users are doing a lot of editing and I have a question about the function "On-screen contraints" and how to set the direction unit. The On-Screen Contraints is very useful, but I'd really like the direction units to be set to the unit Gon. Does anyone know if it's possible? I've tried changing the angular units in both the application- and project-options, with no luck and the direction units seems to only allow polar, azimuth, or quadrant bearing units.i
... View more
02-10-2023
04:49 AM
|
0
|
1
|
1162
|
|
POST
|
Hi @MarcusFrankNielsen . I don't think there are any sort-capabilities within the append-tool, but there might be some other ways to do it. I have not tried it on a hosted feature class, but you might use the Sort tool to sort the features based on one or more attributes and have the hosted layer as output (if there's no data there already). One other option might be using Python.
... View more
01-20-2023
01:49 AM
|
1
|
1
|
1310
|
|
POST
|
Thank you for your quick reply! I'll try your solution 🙂 I've also done some changes in my script that seems to make it work better. It's to define the logger in the .pyt as the rootlogger (line 13) and make the handler to be the only one connected to the logger (line 15). import logging
from CreateProjectTool import CreateProject
class Toolbox(object):
def __init__(self):
self.label = "Geoveg Toolbox"
self.alias = ""
handler = logging.FileHandler(filename='/temp/Geoveg.log')
formatter = logging.Formatter('%(asctime)s %(name)s %(levelname)s %(message)s')
handler.setFormatter(formatter)
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
logger.handlers = [handler]
self.tools = [CreateProject]
... View more
01-17-2023
11:45 PM
|
1
|
0
|
3995
|
|
POST
|
Hi. I've created a pythontoolbox which consists of several scripts, each in it's own python-file. The toolbox works fine, and now I'm going to implement some logging. I've tried using the standard python module logging, but I'm not getting the results I'm expecting. Some times the logging works fine within the pythontoolbox, and other times nothing gets written to the logfile. If I restart ArcGIS Pro when the logging works, it stops working. Does anyone have experience in using the logging-module? What is the best practice for using the logging module while working with pythontoolboxes? I've also tried using just the logging.basicConfig. Using basicConfig works, but if there are any other pythontoolboxes also using basicConfig, everything gets written the same logfile even if filename in the basicConfig is different in the pythontoolboxes. This is from my pyt, where I've created a new logger: import logging
from CreateProjectTool import CreateProject
class Toolbox(object):
def __init__(self):
self.label = "Geoveg Toolbox"
self.alias = ""
handler = logging.FileHandler(filename='/temp/Geoveg.log')
formatter = logging.Formatter('%(asctime)s %(name)s %(levelname)s %(message)s')
handler.setFormatter(formatter)
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
logger.addHandler(handler)
self.tools = [CreateProject] In my other script (module), I have this code: import logging
import traceback
import os
import sys
import zipfile
import arcpy
from pathlib import Path
logger = logging.getLogger(__name__)
class OpprettProsjekt(object):
def __init__(self):
"""Define the tool (tool name is the name of the class)."""
self.label = "Create new project"
self.description = ""
self.canRunInBackground = False
def getParameterInfo(self):
"""Define parameter definitions"""
workfolder = arcpy.Parameter(
displayName="Workfolder",
name="workfolder",
datatype="DEFolder",
parameterType="Required",
direction="Input")
params = [workfolder]
return params
def isLicensed(self):
"""Set whether tool is licensed to execute."""
return True
def updateParameters(self, parameters):
"""Modify the values and properties of parameters before internal
validation is performed. This method is called whenever a parameter
has been changed."""
return
def updateMessages(self, parameters):
"""Modify the messages created by internal validation for each tool
parameter. This method is called after internal validation."""
return
def execute(self, parameters, messages):
"""The source code of the tool."""
destinationFolder = "Geoveg"
folder = parameters[0].valueAsText
workfolder = os.path.join(folder, destinationFolder)
geovegTemplate = os.path.join(os.path.dirname(__file__), "Template")
try:
if os.path.exists(workfolder):
arcpy.AddMessage("Workfolder already exists")
logger.warning("Workfolder already exists.")
return
else:
# pakker ut innholdet i zip-filen med geoveg-mal
with zipfile.ZipFile(file=os.path.join(geovegMal, "Vegdata.zip"), mode='r') as archive:
archive.extractall(path=arbeidsMappe)
arcpy.AddMessage("Zip-file extracted at {0}".format(workfolder))
logger.info("Zip-file extracted at {0}".format(workfolder))
except:
# Get the traceback object
tb = sys.exc_info()[2]
tbinfo = traceback.format_tb(tb)[0]
# Concatenate information together concerning the error into a message string
pymsg = "PYTHON ERRORS:\nTraceback info:\n" + tbinfo + "\nError Info:\n" + str(sys.exc_info()[1])
msgs = "ArcPy ERRORS:\n" + arcpy.GetMessages(2) + "\n"
# Return Python error messages for use in script tool or Python window
arcpy.AddError(pymsg)
arcpy.AddError(msgs)
# Print Python error messages for use in Python / Python window
logger.error(pymsg)
logger.error(msgs)
return
def postExecute(self, parameters):
"""This method takes place after outputs are processed and
added to the display."""
return
... View more
01-17-2023
03:13 AM
|
1
|
2
|
4046
|
|
POST
|
Hi @RVG296 . I know it's been a long time since you posted this, but I'll give it a go. In one my projects I'm having almost the same situation as you (computing distances from a fixed point on a trace network), but I'm using several "starting points". I'm using python to iterate the points, just as you mentioned. Here are some ideas on how you can acheive your goal using python, if all your point-features are contained within one featureclass. The output is a featureclass for each of the dams, containing the shortest path. Be aware that I haven't actually tested this code, but it might give you some insights. #Get ID for Site
fixed_point = None
sql_clause = "NAME = 'START_SITE'
with arcpy.da.SearchCursor(fc_dams, ["OBJECTID"], sql_clause=sql_clause") as cursor:
for row in cursor:
fixed_point = row[0]
#Get geometries from the other points
list_dams = []
sql_clause = "NAME != 'START_SITE'"
with arcpy.da.SearchCursor(fc_dams, ["OBJECTID"], sql_clause=sql_clause) as cursor:
for row in cursor:
list_dams.append(row[0])
#loop through list of dams
for damid in list_dams:
fl_dams = "fl_dams"
point_ids = str(fixed_point) + "," + str(damid)
where = '"OBJECTID" IN ('+point_ids+')'
#select the fixed site and the dam
arcpy.SelectLayerByAttribute_management(in_layer_or_view=fl_dams,
selection_type="NEW_SELECTION",
where_clause=where)
fc_points = "points"
fl_points2 = "fl_points2"
fl_shortestpath = "ShortestPath"+damid
arcpy.CopyFeatures_management(in_features=fl_dams, out_feature_class=fc_points)
arcpy.MakeFeatureLayer_management(fc_points, fl_points2)
arcpy.tn.Trace(r"Dam Trace Network", "SHORTEST_PATH", fl_points2, None,
"NO_DIRECTION", "Shape length", "INCLUDE_BARRIERS", "VALIDATE_CONSISTENCY",
"DO_NOT_IGNORE_BARRIERS_AT_STARTING_POINTS", "IGNORE_INDETERMINATE_FLOW",
None, None, "BOTH_JUNCTIONS_AND_EDGES", None, None, "AGGREGATED_GEOMETRY",
"NEW_SELECTION", "CLEAR_ALL_PREVIOUS_TRACE_RESULTS", "KortesteVei",
"Trace_Results_Aggregated_Points", fl_shortestpath, None,
"DO_NOT_USE_TRACE_CONFIGURATION", '', None)
... View more
12-02-2022
03:19 AM
|
0
|
0
|
953
|
|
POST
|
Hi @LSaunders. Yes, I did solve the issue some time ago. As far as I remember, I solved this by copying the arcgispro-py3 environment from another machine and adding it to the environments (with a new name) on the machine where this error occurs. You need to be sure that you sign into the ArcGIS Server machine as the ArcGIS Server Account, as mentioned here https://enterprise.arcgis.com/en/server/latest/publish-services/windows/deploying-custom-python-packages.htm I think that not using the correct user, might be one of the reasons I got the error in the first place.
... View more
08-22-2022
01:59 AM
|
0
|
0
|
1931
|
|
POST
|
Hi @SimonSchütte_ct . I just recieved a message from ESRI saying that the bugs now are closed without being fixed. The reason for that is that the dashboard-module was using the ArcGIS Dashboard Classic, which is retired and the dashboard-module will also be deprecated from version 2.0.1. ArcGIS Dashboards Classic is Retiring
... View more
08-22-2022
01:24 AM
|
1
|
0
|
1399
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 05-27-2025 05:20 AM | |
| 1 | 01-17-2023 03:13 AM | |
| 1 | 01-17-2023 11:45 PM | |
| 1 | 03-30-2023 08:09 AM | |
| 1 | 08-23-2024 05:01 AM |
| Online Status |
Offline
|
| Date Last Visited |
11-03-2025
01:23 AM
|