1

Is there a way to switch the version a .mxd data source is pointing at without using arcpy.mapping.findAndReplaceWorkspacePaths?

I have a script that automates map book production that works very nicely. The source .mxd used by this script points as SDE.Default. Occasionally editors want to see how their edits will look in the final product before they rec and post changes to SDE.Default. To do this I want to call the existing script but have it's .mxd point to the same version that the editor is currently working on. I can't use the editors .mxd because it will not have the correct layout elements and data driven pages.

The only way I can think of to do this is to pragmatically create a new .sde connection file pointing at the edit version and use arcpy.mapping.findAndReplaceWorkspacePaths with this new file to change the source.

But it would be easier and cleaner to just switch version on the map layers. Is this possible? Or is there another approach that I'm missing.

4

Have you considered using the arcpy ChangeVersion_management() tool?

From the ESRI Help page:

"Each input feature layer or table view will have its workspace modified to connect to the requested version."

It's pretty straightforward and doesn't require a new connection file or modify the existing connection file. You just pass the features you want to change and the version you want to the function and it updates the connection. There's a pretty good example script on the help page.

  • I have seen this tool but disguarded it because I didn't think you could convert an arcpy.mapping.layer class to an arcpy.FeatureLayer class. Is it possible? – Dowlers Apr 21 '16 at 21:05
  • @Dowlers have you tried it? What was the result? – Midavalo Apr 22 '16 at 3:31
  • 2
    @Midavalo and Kevin this worked great, thanks so much. I never would have thought the 2 classes were the same. – Dowlers May 24 '16 at 18:32
0

You're almost there. I think two SDE connection files with the same name should work (each pointing to the desired version.) In the mxd, make sure the data is pointing to the data using the local SDE connection file. When they want to see the other version, just switch out the SDE connection file in the OS. You won't need to edit the source if the SDE files have the same name.

  • The problem is version name will be unknown until the user wants to run it so I can't preconfigure an .sde connection. And as far as I know arcpy cannot modify existing .sde file (although I'd love to wrong about this.) – Dowlers Apr 21 '16 at 20:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.