POST
|
I have a script which remaps broken feature class layers from file geodatabase to sde. It works fine, but there's something weird in the string for the remapped layers that I cannot figure out. These are the broken file geodatabase layers: The script remaps them correctly to sde, but I'm seeing this: And what I want is this: Does anyone have any idea why the file geodatabase path is on the end? These are the properties I'm setting to remap the layers to sde: Note that I have replaced the following properties with dummy values for the purposes of this thread: db_connection_properties; instance; server; user; dataset Here is the procedure that is doing the work: def UpdateSdeConnectionProperties(self, fcName, brokenLayer, userN=None):
new_conn_prop = brokenLayer.connectionProperties
new_conn_prop['connection_info']['authentication_mode'] = self.sdeAuthMode
new_conn_prop['connection_info']['db_connection_properties'] = self.sdeDbConnProps
new_conn_prop['connection_info']['dbclient'] = self.sdeDbClient
new_conn_prop['connection_info']['instance'] = self.sdeInstance
new_conn_prop['connection_info']['projectInstance'] = self.sdeProjInstance
new_conn_prop['connection_info']['server'] = self.sdeServer
if userN is not None:
new_conn_prop['connection_info']['user'] = userN
new_conn_prop['connection_info']['version'] = self.sdeVersion
new_conn_prop['dataset'] = fcName
new_conn_prop['workspace_factory'] = self.sdeWsFactory
# Update the connection properties dictionary of the layer
brokenLayer.updateConnectionProperties(brokenLayer.connectionProperties,new_conn_prop) Thanks for looking everyone!
... View more
04-20-2021
10:34 AM
|
0
|
0
|
248
|
POST
|
Ok. Thanks Jayanta. I find that interesting... but good to know. Now when I deploy my Pro toolbox (which replaces a ArcMap toolbox) I can tell the endusers that the p20 folder is there by Esri's design. I wonder if it works like this in ArcMap? My toolbox in ArcMap doesn't use ExtractPackage so I can't say.
... View more
04-07-2021
01:58 PM
|
0
|
2
|
2256
|
POST
|
Hi Dan, I guess I wrote my question as pseudo code to be quicker (or lazier?). No, thankfully there are not 19 previous to 20. I am using os.mkdir to create projectFolder before calling extract package. After reading your comment I did a quick test without making the folder first and you're right it does create the folder while extracting the template. But it still works the same and add the \p20 folder. In a nutshell, I'm expecting: X:\Projects\Project1\blankProject.aprx but what I'm getting is: X:\Projects\Project1\p20\blankProject.aprx Thanks 😊
... View more
04-07-2021
01:03 PM
|
0
|
0
|
2262
|
POST
|
If I run the following: arcpy.ExtractPackage_management(prjTemplate, projectFolder) Where: prjTemplate = X:\Dev\BrokenLinks\ProjectTemplate\blankProject.aptx projectFolder = X:\Projects\Project1 The template will be extracted to: X:\Projects\Project1\p20\blankProject.aprx What's this 'p20'? thanks
... View more
04-07-2021
09:54 AM
|
0
|
7
|
2279
|
POST
|
Hi Jeff, Does updateConnectionProperties require that feature class name in old and new be the same? I have the situation where we have moved a number of feature classes from file geodatabase to sde, but the feature classes have also been renamed in sde to conform to corporate standards. So, for example: before: Data.gdb\roads; after: database.sde\transportation before: Data.gdb\rivers; after: database.sde\hydrology Is it possible to fix these broken links using updateConnectionProperties. Seemed pretty easy to do this in arcMap, just starting to see how/if it will be possible to accomplish the same in Pro. thanks
... View more
03-11-2021
10:27 AM
|
0
|
0
|
1962
|
POST
|
Thanks Johannes. I've adjusted my example file. It's cleaner, executes about the same as before. But makes better sense. Cheers # -*- coding: utf-8 -*-
class Toolbox(object):
import arcpy
def __init__(self):
"""Define the toolbox (the name of the toolbox is the name of the
.pyt file)."""
self.label = ""
self.alias = ""
# List of tool classes associated with this toolbox
self.tools = [SomeTool, AnotherTool]
class BaseTool(object):
import arcpy
def __init__(self):
"""Define the toolbox (the name of the toolbox is the name of the
.pyt file)."""
self.label = ""
self.alias = ""
# List of tool classes associated with this toolbox
self.tools = [SomeTool, AnotherTool]
def Procedure1(self, parameter1, parameter2):
#This is a procedure used by multiple tools in the pyt file.
#code goes here...
arcpy.AddMessage('hi from Procedure1. parameter1: {}; parameter2: {}'.format(parameter1,parameter2))
def Procedure2(self, parameter1):
#This is a procedure used by multiple tools in the pyt file.
#code goes here...
self.Procedure3(parameter1)
def Procedure3(self, parameter1):
#This is a procedure used by multiple tools in the pyt file.
#code goes here...
arcpy.AddMessage('message from Procedure2: {}'.format(parameter1))
class SomeTool(BaseTool):
def __init__(self):
"""Define the tool (tool name is the name of the class)."""
self.label = "Some Tool"
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."""
def Procedure4(inParameter):
#This procedure is just for SomeTool
return('phrase passed into Procedure4: {}'.format(inParameter))
#code goes here...
aVariable = Procedure4('blah')
self.Procedure1(aVariable,'something else')
self.Procedure2('hi there')
return
class AnotherTool(BaseTool):
def __init__(self):
"""Define the tool (tool name is the name of the class)."""
self.label = "Another Tool"
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):
self.Procedure2('whatever')
return
... View more
02-25-2021
01:30 PM
|
0
|
0
|
1494
|
POST
|
I think you're on the right track. Here's what I came up with, which is working and is executing in an acceptable amount of time. The actual .pyt file is quite long so I set up an 'example.pyt' which shows how the code class Toolbox(object):
import arcpy
def __init__(self):
"""Define the toolbox (the name of the toolbox is the name of the
.pyt file)."""
self.label = ""
self.alias = ""
# List of tool classes associated with this toolbox
self.tools = [SomeTool, AnotherTool,]
def Procedure1(self, parameter1, parameter2):
#This is a procedure used by multiple tools in the pyt file.
#code goes here...
def Procedure2(self, parameter1):
#This is a procedure used by multiple tools in the pyt file.
#code goes here...
self.Procedure3('something')
def Procedure3(self, parameter1):
#This is a procedure used by Procedure2
#code goes here...
class SomeTool(object):
def __init__(self):
"""Define the tool (tool name is the name of the class)."""
self.label = "Some Tool"
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."""
def Procedure4(inParameter):
#This procedure is just for SomeTool
#code goes here...
aVariable = Procedure4('blah')
sT = Toolbox()
sT.Procedure1(aVariable,'something else')
sT.Procedure2('something else')
del sT
return
class AnotherTool(object):
def __init__(self):
"""Define the tool (tool name is the name of the class)."""
self.label = "Another Tool"
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):
aT = Toolbox()
aT.Procedure2('something else')
del aT
return flows.
... View more
02-24-2021
03:26 PM
|
0
|
2
|
1525
|
POST
|
Ya, that's kind of what I was thinking. Thanks. Still searching around a bit for a proper way of doing this 🙂
... View more
02-23-2021
11:53 AM
|
1
|
0
|
1537
|
POST
|
Hello, I have a python toolbox, that has the following tools: Some of these scripts use the same procedures, so I moved those procedures to the top of the file above all of the individual classes. Which seems to make sense, I don't have exact copies of the same procedure inside each class, fewer lines of code, smaller file... The top of the file looks like this (this is not all the procedures that are at the top just the first few): import arcpy
import os
import re
import shutil
import configparser
import subprocess
from time import gmtime, strftime
def OpenAprx(aprx):
#open the passed in mxd file in a new arcmap instance
arcpy.AddMessage('Opening: {}'.format(aprx))
subprocess.Popen([r'C:\Program Files\ArcGIS\Pro\bin\ArcGISPro.exe',aprx])
def CreateImage(prj, mapName, lyrsOn, lyrsOff, lyrExtent, lytName, mapScale, pngFilePath):
arcpy.AddMessage('CreateImage start {}'.format(strftime("%H:%M:%S", gmtime())))
arcpy.AddMessage('prj: {}'.format(prj))
SetLayers(prj, mapName, lyrsOn, 'on')
arcpy.AddMessage('SetLayers ON completed {}'.format(strftime("%H:%M:%S", gmtime())))
arcpy.AddMessage('len lyrsOff: {}'.format(len(lyrsOff)))
if len(lyrsOff) > 0:
SetLayers(prj, mapName, lyrsOff, 'off')
arcpy.AddMessage('SetLayers OFF completed {}'.format(strftime("%H:%M:%S", gmtime())))
ExportImage(prj, mapName, lyrExtent, lytName, mapScale, pngFilePath)
arcpy.AddMessage('ExportImage completed {}'.format(strftime("%H:%M:%S", gmtime())))
def SetLayers(prj, mapName, lyrs, status):
arcpy.AddMessage('SetLayers prj = {}'.format(prj))
aprx = arcpy.mp.ArcGISProject(prj)
m = aprx.listMaps(mapName)[0]
for lyr in m.listLayers():
if lyr.name.upper() in lyrs:
if status == 'on':
lyr.visible = True
else:
lyr.visible = False
#aprx.save()
del aprx This all seems great to me but the problem is the code executes way slower than when the procedures are all copied in the individual classes. Why is this? Thanks
... View more
02-22-2021
07:34 AM
|
0
|
6
|
1622
|
POST
|
The workaround I'm using for this for my use case is to create a project template in Pro. Then using arcpy I can extract the project template to a new location on the network as a "new project". It works for me, not sure if it would work for your use case.
... View more
02-22-2021
07:21 AM
|
0
|
0
|
430
|
POST
|
I'm assuming though if there is a need to save the project at the end of a script that works with 'CURRENT', you will still need to do a .save()?
... View more
02-16-2021
09:19 AM
|
0
|
0
|
899
|
POST
|
That is completely correct and actually I remember reading this link in the past. SetLayers is used to turn layers on/off before running a procedure to create images. As a test I ran it how it currently works (using a passed in path to a project), I set it to create 4 images but killed the script after 12 minutes and having created 2 of the images. I then changed my code to use 'CURRENT', reran the test and it created all 4 images in 35 seconds! Thanks for the reminder. 🙂
... View more
02-16-2021
09:15 AM
|
1
|
0
|
899
|
POST
|
Hello, I have the following procedure which turns layers on or off on a mapview. But I find that the changes only apply if I save the project but I find saving the project adds alot of time onto the execution of the script. Is there something different I can do, possibly some way that will just update the mapview where the layers have been turned on/off? Thanks! def SetLayers(prj, mapName, lyrs, status):
aprx = arcpy.mp.ArcGISProject(prj)
m = aprx.listMaps(mapName)[0]
for lyr in m.listLayers():
if lyr.name.upper() in lyrs:
if status == 'on':
lyr.visible = True
else:
lyr.visible = False
aprx.save()
del aprx
... View more
02-11-2021
01:22 PM
|
0
|
3
|
1017
|
POST
|
As Joshua mentioned and as far as I can see you can only zoom on the active map view. Otherwise it must be done on a layout/map frame.
... View more
12-17-2020
08:55 AM
|
0
|
0
|
2881
|
POST
|
Having spent some time with the layout and mapframe I am now using zoom to extent and set scale on the map frame which works well. Having said that the end use will still need to manually zoom to extent in the map view to do their work. Ideally I would have liked to loop through all map views using arcpy and complete the zoom to extent before the aprx file opens so that all map views would be focused on the appropriate parcel when it opens, but this will have to do.
... View more
12-14-2020
08:29 AM
|
0
|
1
|
3911
|
Title | Kudos | Posted |
---|---|---|
1 | 11-10-2020 03:34 PM | |
1 | 02-23-2021 11:53 AM | |
1 | 02-16-2021 09:15 AM | |
1 | 12-10-2020 07:46 AM | |
1 | 01-18-2019 09:54 AM |
Online Status |
Offline
|
Date Last Visited |
04-22-2021
04:31 PM
|