Utility-Data-Management-Support-Tools icon indicating copy to clipboard operation
Utility-Data-Management-Support-Tools copied to clipboard

Error: Executing from standalone Python

Open BaptisteDlp opened this issue 1 year ago • 5 comments

I get the following error while executing this code from Pycharm:

associationResult = arcpy.AssociationSelection_udms( in_utility_network=UN_NAME, layer_payload=layer_payload, # json_payload="""[ # { # "fromLayers": [], # "fromSelectionType": "KEEP", # "associationTypes": [], # "toLayers": [], # "toSelectionType": "NEW" # } # ]""" )

where UN_NAME is the path to my main UN network

Traceback (most recent call last): File "D:\Delaporte\TIGRE\Sprint3_EPSEP\tigre-epsepare\main_epsepare.py", line 160, in run(id_branc) File "D:\Delaporte\TIGRE\Sprint3_EPSEP\tigre-epsepare\main_epsepare.py", line 135, in run epSepare(id_cable, percentage) File "D:\Delaporte\TIGRE\Sprint3_EPSEP\tigre-epsepare\main_epsepare.py", line 112, in epSepare tigreUtils.SelectFeatureByAssociation("0 'Point de structure/Support' CLEAR ALL '-- All --' NEW") File "D:\Delaporte\TIGRE\Sprint3_EPSEP\tigre-epsepare\tigreUtils.py", line 60, in SelectFeatureByAssociation associationResult = arcpy.udms.AssociationSelection( File "D:\Delaporte\TIGRE\Utility-Data-Management-Support-Tools-6_1_2023_3.1.1\UtilityDataManagementSupport.atbx", line 740, in AssociationSelection File "D:\Delaporte\TIGRE\Utility-Data-Management-Support-Tools-6_1_2023_3.1.1\UtilityDataManagementSupport.atbx", line 737, in AssociationSelection File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing_base.py", line 512, in return lambda *args: val(*gp_fixargs(args, True)) arcgisscripting.ExecuteError: Executing from standalone Python Échec de l’exécution de (AssociationSelection).

I did not find any information on the internet

BaptisteDlp avatar Nov 21 '23 23:11 BaptisteDlp

I previously used a arcpy.ImportToolbox(UDMS_ATBS_PATH) where UDMS_ATBS_PATH stands for the path to the udms toolbox

BaptisteDlp avatar Nov 21 '23 23:11 BaptisteDlp

In order for the selections in this tool to work, the UN (and its participating classes) must be in a map.

For your workflow, would it be acceptable if you had a saved Pro Project (aprx) with a map containing the UN? I think we could make this work, I'd need to investigate further.

I assume the tool works correctly when you run it from Pro?

pLeBlanc93 avatar Nov 21 '23 23:11 pLeBlanc93

It works perfectly fine in Pro and in toolboxes.

For your workflow, would it be acceptable if you had a saved Pro Project (aprx) with a map containing the UN? It would be acceptable, but how can we "link" this potential saved aprx into our standalone script in order to use UDMS ?

BaptisteDlp avatar Nov 22 '23 00:11 BaptisteDlp

If you are scripting, you can use the internal class that the GP tool is calling. The function takes in an aprx and map name. We will look at exposing this in the GP tool `

import sys
atbx = r"C:\tools\UtilityDataManagementSupport.atbx"
sys.path.insert(0, atbx)
import udms
target_network = r"PathToUN"
pro_project = r"PathtoAPRX"
pro_map = "NameOfMapWithLayersToSelectInAPRX"
results = udms.logic.expand_selection(
    utility_network=str(target_network),
    payload=[
        {
            "fromLayers": ["Electric Distribution Device/Circuit Breaker"],
            "fromSelectionType": "KEEP",
            "associationTypes": [],
            "toLayers": [],
            "toSelectionType": "NEW",
        }
    ],
    project=pro_project,
    map_name=pro_map,
)

MikeMillerGIS avatar Nov 27 '23 16:11 MikeMillerGIS

I discussed with Paul. We need to update the code so you can access the project/map with the selection after the execution of the code. Right now, if you pass a project in, it is closed and not saved with the selection.

MikeMillerGIS avatar Nov 27 '23 17:11 MikeMillerGIS