Select to view content in your preferred language

Project GUID is returning null

1389
2
Jump to solution
01-12-2021 06:54 AM
DanielWatkins
New Contributor

Hey, I am trying to find a way to identify which project is loaded. Using the name or URI is proving problematic because the user can change those at anytime. I see that the Project object does have a method for retrieving a GUID, however whenever I call Project.Current.Guid it always returns null.

 

Is there something special I need to be doing to ensure my Projects have a valid GUID?

Tags (2)
1 Solution

Accepted Solutions
Wolf
by Esri Regular Contributor
Esri Regular Contributor

Sorry about the delayed reply, I tried to check with the developers before responding.  You are correct as to Project.Current.Guid doesn't return the documented: ''unique identifier for the item". I attached a project that provides a workaround for the desired unique project file identifier. In order to implement this I used the API's project's custom settings capability for that.

In essence the attached add-in adds a custom setting to each project that is opened with the add-in running.  However, there are a few caveats:

The add-in has to be autoloaded in order to catch the project open events.  The default JIT loading will not provide access to the first project open event.  To do this you have to change the autoLoad property to 'true' as shown here:

<insertModule id="TestProject_Module" className="Module1" autoLoad="true" caption="Module1">

The unique identifier created for each project will only be 'permanent' once the project is saved.  This can be mitigated by saving the project programmatically in your add-in.

View solution in original post

0 Kudos
2 Replies
Wolf
by Esri Regular Contributor
Esri Regular Contributor

Sorry about the delayed reply, I tried to check with the developers before responding.  You are correct as to Project.Current.Guid doesn't return the documented: ''unique identifier for the item". I attached a project that provides a workaround for the desired unique project file identifier. In order to implement this I used the API's project's custom settings capability for that.

In essence the attached add-in adds a custom setting to each project that is opened with the add-in running.  However, there are a few caveats:

The add-in has to be autoloaded in order to catch the project open events.  The default JIT loading will not provide access to the first project open event.  To do this you have to change the autoLoad property to 'true' as shown here:

<insertModule id="TestProject_Module" className="Module1" autoLoad="true" caption="Module1">

The unique identifier created for each project will only be 'permanent' once the project is saved.  This can be mitigated by saving the project programmatically in your add-in.

0 Kudos
RichardFairhurst
MVP Alum

@Wolf  Does the code you provided work for version 3?  If the user does a Save As of a previously saved project that had already stored a GUID in its custom settings, does this code handle assigning a new GUID to the newly created Project duplicate's custom settings?  If it does could you point out the event that ensures that happens.  Or if the new project would carry over the GUID custom setting of the original saved project under the code you provided can you extend the code to handle the Save As event or explain how that would be done?

Finally, do maps in a project need a similar custom property to retain a unique GUID that would be accessible to an Addin, or is the GUID created by esri for project items like maps accessible through an exposed property or task?

0 Kudos