2 Replies Latest reply on Apr 3, 2017 11:19 AM by Josh Pritt

    Editing in an ArcFM session using Python

    Richard Eyre-Todd

      Hi All,

       

      I'm writing a Python toolbox that will do some feature attribute edits in the currently active ArcFM Session Manager edit session i.e. in the session's version, not SDE.DEFAULT. The code looks like this:

       

      workspace = ???  # currently active ArcFM Session Manager edit session
      arcpy.env.workspace = workspace
      editor = arcpy.da.editor(workspace)
      editor.startEditing(with_undo=True, multiuser_mode=True)
      editor.startOperation()
      # do feature edits here
      editor.stopOperation()
      editor.stopEditing(True)

       

      The question is - what value should be used to initialise 'workspace'?

       

      Thanks very much!

       

      Richard

        • Re: Editing in an ArcFM session using Python
          Josh Pritt

          First, you'll want to make sure to check out the ArcFM license to deal with ArcFM objects:

          How-To - Work with ArcFM features in Python

           

          Then as far as getting the current workspace goes, what does it show when you try to print arcpy.env.workspace without setting it yet?  There is a such thing as the CurrentWorkspace but I'm not sure if that gets automatically set to the actual current workspace in ArcMap, or if that's just the workspace that's passed in to the GP tool.  Normally the user has to choose the workspace as one of the inputs to a GP tool.

          One of the ways I've seen it done is to save a separate .sde connection file in ArcCatalog with the session's version set as the version for the connection.

          Then you just pass in that .sde file path to the workspace and it will be making its edits to that specific version instead of SDE.Default.

          geodatabaseConnection = r'Database Connections\gis@gisprd01.sde'

          arcpy.env.workspace = geodatabaseConnection

           

          I don't know of a way for python code to be able to get at the currently open workspace.  Not even ESRI's own arcpy.Editor class has any methods or properties to get at the currently open workspace:  Editor—Help | ArcGIS for Desktop

           

          I think it boils down to the fact that all GP tools can be run on their own so they need the workspace to always be passed in as an input parameter.

           

          Feel free to correct me if I'm wrong!

            • Re: Editing in an ArcFM session using Python
              Josh Pritt

              It seems you can load up our ArcFM COM libraries in python.

              So you just need to load up the MMEditor (mmGeodatabase.MMEditor) by finding the "Miner Object Editor" extension.

               

              Here's what it looks like in C# but you can create instances of COM objects in Python too:

               

              var extensionMan = Activator.CreateInstance(Type.GetTypeFromProgID("esriSystem.ExtensionManager")) as IExtensionManager;

              var mmEditor = extensionMan.FindExtension("Miner Object Editor") as IMMEditor;

               

              Then just look for the EditWorkspace property on the mmEditor object.

               

              Note that this object editor extension and extension manager only works if ArcMap is running.