How can i get the value of the "UUID" field?

2013
7
Jump to solution
01-26-2021 08:13 AM
ChristianJ1979
New Contributor II

Hello,

in an enterprise geodatabase there is a table "GDB_ITEMS" containing a field named "UUID". How can i get the value of the "UUID" field in ArcGIS Pro?

To start a process in ArcGIS Pro i created a custom button in the context menu of geodatabase featureclasses like so:

<modules>
<insertModule id="MetadataAddIn" className="HandleExportDocuments" autoLoad="true" caption="MetadataAddIn">
<controls>
<button id="MetadataAddIn_CreateMetadataPDF" caption="CreateMetadataPDF" className="CreateMetadataPDF" loadOnClick="true" smallImage="pack://application:,,,/ArcGIS.Desktop.Resources;component/Images/GenericButtonBlue16.png" largeImage="pack://application:,,,/ArcGIS.Desktop.Resources;component/Images/GenericButtonBlue32.png">
<tooltip heading="Tooltip Heading">Tooltip text<disabledText /></tooltip>
</button>
</controls>
</insertModule>
<updateModule refID="esri_geodatabase_module">
<menus>
<updateMenu refID="fgdbItemFeatureClassTypeMenu">
<insertButton refID="MetadataAddIn_CreateMetadataPDF" placeWith="esri_projectItemEditMetadata" />
</updateMenu>
<updateMenu refID="egdbItemFeatureClassTypeMenu">
<insertButton refID="MetadataAddIn_CreateMetadataPDF" placeWith="esri_projectItemEditMetadata" />
</updateMenu>
<updateMenu refID="fgdbItemTableTypeMenu">
<insertButton refID="MetadataAddIn_CreateMetadataPDF" placeWith="esri_projectItemEditMetadata" />
</updateMenu>
<updateMenu refID="egdbItemTableTypeMenu">
<insertButton refID="MetadataAddIn_CreateMetadataPDF" placeWith="esri_projectItemEditMetadata" />
</updateMenu>
</menus>
</updateModule>
</modules>

For the button "CreateMetadataPDF" there is an OnClick event. In this method i need the "UUID" value of the current featureclass or table from the geodatabase in the table "GDB_ITEMS". Currently i have the following code:

internal class CreateMetadataPDF : Button
{
protected override void OnClick()
{
GDBItem item = ProApp.ContextMenuDataContext as GDBItem;
}
}

How can i get the UUID here?

Which is the correct class to use here because GDBItem is marked as ESRI internal only?

 

Thank you!

 

Regards

 

Christian

0 Kudos
1 Solution

Accepted Solutions
by Anonymous User
Not applicable

Hi @ChristianJ1979 ,

Here is the codesnippet  and some useful help link for you.

https://github.com/Esri/arcgis-pro-sdk/wiki/ProSnippets-Geodatabase

The codesnippet cover for egdb and fgdb.

 

ArcGIS.Desktop.Core.IProjectWindow currentProjectWindow = Project.GetCatalogPane(true);
           
            if (currentProjectWindow == null)
            {
                MessageBox.Show("Please select a geodatabase from catalog");
                return;
            }

            int selectionCount = currentProjectWindow.SelectionCount;
            
            if (selectionCount <= 0)
            {
                MessageBox.Show("Please select a geodatabase from catalog");
                return;
            }
           
            Item SelectedConnection = currentProjectWindow.SelectedItems.First();
            
            string _gdbPath = this.SelectedConnection.Path;

            Geodatabase geodatabase = null;
            Uri gdbPath = new Uri(_gdbPath);
            ProgressorSource ps = new ProgressorSource("Processing search");
            List<string> outputFeatureclassNameList = new List<string>();
            
            bool process = await QueuedTask.Run(() =>
            {
                //check gdb or sde connection
                //apart from that it is handled by user and the properties need to setup manually

                if (gdbPath.AbsoluteUri.EndsWith(".gdb", StringComparison.OrdinalIgnoreCase))
                {
                    geodatabase = new Geodatabase(new FileGeodatabaseConnectionPath(gdbPath));
                }

                else if (gdbPath.AbsoluteUri.EndsWith(".sde", StringComparison.OrdinalIgnoreCase))
                {
                    geodatabase = new Geodatabase(new DatabaseConnectionFile(gdbPath));
                }
                else 
                { 
                    return;
                }

                if (geodatabase == null)
                {
                    return;
                }
                //Now lets search
                IReadOnlyList<FeatureClassDefinition> fcd = geodatabase.GetDefinitions<FeatureClassDefinition>();//Get all feature class definition <== here you can get the feature class definition
// for your case specific table 
                using (Table featureClassAsTable = geodatabase.OpenDataset<Table>("GDB_ITEMS")) {
        // But it is really a FeatureClass object.
        FeatureClass featureClassOpenedAsTable = featureClassAsTable as FeatureClass;
FeatureClassDefinition featureClassDef = featureClassOpenedAsTable.GetDefinition();// you can get your desire field from here
IReadOnlyList<Field> fieldList = featureClassDef.GetFields();
                        var UUIDField = fieldList.FirstOrDefault(x => x.Name.Equals("UUID")); //for uuidfield ***
      }
               

            }, ps.Progressor);

 

  

View solution in original post

7 Replies
KirkKuykendall1
Occasional Contributor III

I'm able to create a standalone table using the Make Query Layer tool.

KirkKuykendall1_0-1611694059589.png

After doing that you should have a standalone table like this:

KirkKuykendall1_1-1611694108788.png

 

You should be able to read it as you would any standalone table.

If you don't want a standalone table, you could use OpenQueryTable

0 Kudos
ChristianJ1979
New Contributor II

Sorry for my late reply but this is not what i was looking for. Thanks anyway.

0 Kudos
by Anonymous User
Not applicable

Hi @ChristianJ1979 ,

Here is the codesnippet  and some useful help link for you.

https://github.com/Esri/arcgis-pro-sdk/wiki/ProSnippets-Geodatabase

The codesnippet cover for egdb and fgdb.

 

ArcGIS.Desktop.Core.IProjectWindow currentProjectWindow = Project.GetCatalogPane(true);
           
            if (currentProjectWindow == null)
            {
                MessageBox.Show("Please select a geodatabase from catalog");
                return;
            }

            int selectionCount = currentProjectWindow.SelectionCount;
            
            if (selectionCount <= 0)
            {
                MessageBox.Show("Please select a geodatabase from catalog");
                return;
            }
           
            Item SelectedConnection = currentProjectWindow.SelectedItems.First();
            
            string _gdbPath = this.SelectedConnection.Path;

            Geodatabase geodatabase = null;
            Uri gdbPath = new Uri(_gdbPath);
            ProgressorSource ps = new ProgressorSource("Processing search");
            List<string> outputFeatureclassNameList = new List<string>();
            
            bool process = await QueuedTask.Run(() =>
            {
                //check gdb or sde connection
                //apart from that it is handled by user and the properties need to setup manually

                if (gdbPath.AbsoluteUri.EndsWith(".gdb", StringComparison.OrdinalIgnoreCase))
                {
                    geodatabase = new Geodatabase(new FileGeodatabaseConnectionPath(gdbPath));
                }

                else if (gdbPath.AbsoluteUri.EndsWith(".sde", StringComparison.OrdinalIgnoreCase))
                {
                    geodatabase = new Geodatabase(new DatabaseConnectionFile(gdbPath));
                }
                else 
                { 
                    return;
                }

                if (geodatabase == null)
                {
                    return;
                }
                //Now lets search
                IReadOnlyList<FeatureClassDefinition> fcd = geodatabase.GetDefinitions<FeatureClassDefinition>();//Get all feature class definition <== here you can get the feature class definition
// for your case specific table 
                using (Table featureClassAsTable = geodatabase.OpenDataset<Table>("GDB_ITEMS")) {
        // But it is really a FeatureClass object.
        FeatureClass featureClassOpenedAsTable = featureClassAsTable as FeatureClass;
FeatureClassDefinition featureClassDef = featureClassOpenedAsTable.GetDefinition();// you can get your desire field from here
IReadOnlyList<Field> fieldList = featureClassDef.GetFields();
                        var UUIDField = fieldList.FirstOrDefault(x => x.Name.Equals("UUID")); //for uuidfield ***
      }
               

            }, ps.Progressor);

 

  

ChristianJ1979
New Contributor II

Sorry for my late reply. This is what im looking for. Thank you very much! This is my code now:

        private string _SDEextension = ".sde";


        protected async override void OnClick()
        {
            GDBItem item = ProApp.ContextMenuDataContext as GDBItem;

            if (!string.IsNullOrWhiteSpace(item.Path))
            {
                if (!item.Path.Contains(_SDEextension))
                    MessageBox.Show("Only SDE databases.");
                else
                {
                    //Clear the path until it ends with .sde (only for SDE required).
                    string geodatabasePath = item.Path;

                    while (!geodatabasePath.EndsWith(".sde", StringComparison.OrdinalIgnoreCase))
                    {
                        string[] split = geodatabasePath.Split(new string[] { "\\" }, StringSplitOptions.None);
                        geodatabasePath = geodatabasePath.Replace(string.Concat("\\", split.Last()), string.Empty);
                    }

                    await QueuedTask.Run(() =>
                    {
                        //Open the SDE database and access the table where all items are defined.
                        using (Geodatabase geodatabase = new Geodatabase(new DatabaseConnectionFile(new Uri(geodatabasePath))))
                        {
                            using (Table table = geodatabase.OpenDataset<Table>("GDB_ITEMS"))
                            {
                                //Retrieve the UUID value for the selected feature class.
                                string oUUID = null;

                                using (RowCursor rowCursor = table.Search(new QueryFilter() { WhereClause = $"Name = '{item.Name}'" }, false))
                                    while (rowCursor.MoveNext())
                                    {
                                        oUUID = rowCursor.Current["UUID"].ToString();
                                        break;
                                    }

                                if (!string.IsNullOrWhiteSpace(oUUID))
                                    MessageBox.Show(oUUID);
                            }
                        }

                    });
                }
            }
        }

 

0 Kudos
by Anonymous User
Not applicable

That great @ChristianJ1979 ,

GDBItem item = ProApp.ContextMenuDataContext as GDBItem;


Good idea that => from context menu item, retrieve as GDBitem and use item.Path to process.

You might want to wrap with try catch, not to get uncaught error. at conversion part at GDBitem.

Best Regards,

Than

ChristianJ1979
New Contributor II

Ohh, i would add something like this:

if (item != null)
{
//... the other code
}

because if the object cannot be converted with "as" the result is a null value.

Regards

Christian

 

0 Kudos
by Anonymous User
Not applicable

That is a good idea @ChristianJ1979 

0 Kudos