arcpy.management.ChangeVersion(in_features, version_type, {version_name}, {date}, {include_participating})
|
Name
|
Explanation
|
Data type
|
|
in_features
|
The layer or table view that will connect to the specified version.
Note:
The sublayers of a topology layer, parcel layer, utility network layer, or trace network layer are not valid inputs.
|
Feature Layer; Table View; Topology Layer; Parcel Layer; Utility Network Layer; Trace Network Layer
|
|
version_type
|
Specifies the type of version to which the input feature layer will connect.
TRANSACTIONAL—Connect to a defined state of the database (traditional version).
HISTORICAL—Connect to a version representing a defined moment in time, often specified by a time or historical marker.
BRANCH—Connect to a branch version.
|
String
|
|
version_name
(Optional)
|
The name of the version to which the input feature layer will connect. This parameter is optional if you're using a historical version.
|
String
|
|
date
(Optional)
|
The date of the historical version to which the input feature layer will connect.
|
Date
|
|
include_participating
(Optional)
|
Specifies whether the workspace of participating classes will also change.
The parameter is only applicable when the input layer is a topology layer, parcel layer, utility network layer, or trace network layer.
INCLUDE—The version of the participating classes of the controller dataset will change if they are from the same workspace as the controller dataset.
EXCLUDE—Only the version of the controller dataset will change.
|
Boolean
|
Derived output
|
Name
|
Explanation
|
Data type
|
|
out_feature_layer
|
The updated input dataset.
|
Feature Layer
|
Code sample
ChangeVersion example 1 (Python window)
The following Python window script demonstrates how to use the ChangeVersion function in immediate mode.
import arcpy
arcpy.env.workspace = r'c:\Connections\toolbox.sde'
arcpy.management.MakeFeatureLayer(r'TOOLBOX.Redlands\TOOLBOX.street','RedlandsStreets')
arcpy.management.MakeFeatureLayer(r'TOOLBOX.Redlands\TOOLBOX.streams','RedlandsStreams')
arcpy.management.MakeFeatureLayer(arcpy.management.SelectLayerByLocation("RedlandsStreams","WITHIN_A_DISTANCE","RedlandsStreets","100 Meters","NEW_SELECTION",'#'),
'StreamsNearStreets','','','')
arcpy.management.ChangeVersion('RedlandsStreets','TRANSACTIONAL', 'TOOLBOX.proposedStreets2k9','')
arcpy.management.MakeFeatureLayer(arcpy.management.SelectLayerByLocation("RedlandsStreams","WITHIN_A_DISTANCE","RedlandsStreets","100 Meters","NEW_SELECTION",'#'),
'NewStreamsNearStreets','','','')
ChangeVersion example 2 (stand-alone script)
Use the ChangeVersion function in a typical versioned analysis workflow.
# Name: ChangeVersion.py
# Description: Use the ChangeVersion tool in a typical versioned analysis workflow.
# Quick check of additional streams within a pre-determined distance
# of new proposed street development.
# Import system modules
import arcpy
import sys
import os
# Set environments
arcpy.env.workspace = sys.path[0] + os.sep + "toolbox.sde"
# Create the layers
arcpy.management.MakeFeatureLayer(r'TOOLBOX.Redlands\TOOLBOX.street','RedlandsStreets')
arcpy.management.MakeFeatureLayer(r'TOOLBOX.Redlands\TOOLBOX.streams','RedlandsStreams')
# Perform analysis on the Default version to determine
# current number of streams within 100 meters of streets.
selection1 = arcpy.management.SelectLayerByLocation("RedlandsStreams",
"WITHIN_A_DISTANCE",
"RedlandsStreets",
"100 Meters",
"NEW_SELECTION",
'#')
arcpy.management.MakeFeatureLayer(selection1,'StreamsNearStreets','','','')
print("Streams within 100 Meters of current streets: {}".format(
arcpy.management.GetCount("StreamsNearStreets")[0]))
# Change to the development version
arcpy.management.ChangeVersion('RedlandsStreets',
'TRANSACTIONAL',
'TOOLBOX.proposedStreets2k9',
'')
# Perform the same analysis on the development version to see the effect of the proposed changes.
selection2 = arcpy.management.SelectLayerByLocatio("RedlandsStreams",
"WITHIN_A_DISTANCE",
"RedlandsStreets",
"100 Meters",
"NEW_SELECTION",
'#')
arcpy.management.MakeFeatureLayer(selection2,'NewStreamsNearStreets','','','')
print("Streams projected to be within 100 Meters of streets after proposed street additions: {}".format(
arcpy.management.GetCount("NewStreamsNearStreets")[0]))
ChangeVersion example 3 (stand-alone script)
Use the ChangeVersion function to change a feature service layer to a named branch version.
# Name: ChangeVersionBranchVersioning.py
# Description: Use the ChangeVersion tool to change the branch version of a feature service
# layer that has the version management capability enabled.
# Import system modules
import arcpy
# Sign into ArcGIS Enterprise
arcpy.SignInToPortal("https://myserver.mydomain.com/portal", 'portaladmin', 'my.password')
# Create a variable for the feature service URL
myFS = "https://myserver.mydomain.com/server/rest/services/BranchVersioningData/FeatureServer/0"
# Create the layers
arcpy.management.MakeFeatureLayer(myFS, 'myFSLayer')
# Change to a branch version named myVersion
arcpy.management.ChangeVersion('myFSLayer', "BRANCH", "portaladmin.myVersion")