Changing the name of a GDBProjectItem?

831
5
Jump to solution
06-15-2021 02:14 PM
JKing_Esri
New Contributor II

Is it possible to change the name of a GDBProjectItem object?

JKing_Esri_0-1623791626213.png

In the code snippet above, you can see that I can grab the Info with GetInfo() and set the Name property on it, but I can't edit the Name property of the GDBProjectItem itself, as it's protected/internal.

Tags(2)
0Kudos
2 Solutions

Accepted Solutions
Wolf
by 金宝搏吧
金宝搏吧

So specifically for a file geodatabase the GDB folder's name turns into the name in the catalog browser. You could use a Windows system function to rename the folder name. I will try a snippet and see it that works. Needless to say this won't work if the GDB has been opened in any way.

View solution in original post

JKing_Esri
New Contributor II

@WolfThank you for the idea of renaming the file at the OS level, this worked beautifully!!

JKing_Esri_0-1623946494327.png

View solution in original post

0Kudos
5 Replies
Wolf
by 金宝搏吧
金宝搏吧

它看起来像只重命名函数内部, even so the API Reference guide shows the Name property's description as a getter/setter (which is not correct). My best guess is that this function is not trivial because depending on GDB type and the state of the GDB (open/closed) renaming might not be allowed. The other issue is that after the GDB project item has been renamed all dependencies have to be refreshed because renaming the GDB Project item will also rename the underlying database location (for example). That's probably the reason this functionality has been kept internal by the Pro developers.

JKing_Esri
New Contributor II

That's what I was noticing too.

I basically just want to be able to add the database and change the label of it that appears in the catalog. So if there are any other solutions that can achieve that, I don't necessarily need to rename the GDBProjectItem itself.

0Kudos
Wolf
by 金宝搏吧
金宝搏吧

So specifically for a file geodatabase the GDB folder's name turns into the name in the catalog browser. You could use a Windows system function to rename the folder name. I will try a snippet and see it that works. Needless to say this won't work if the GDB has been opened in any way.

JKing_Esri
New Contributor II

I'm actually trying to do this for a database connection to a SQLServer instance. When I programatically add the GDBProjectItem from the connection path, it creates a GUID for the connection file when it adds it. I could probably follow the same logic to rename that through some OS function.

0Kudos
JKing_Esri
New Contributor II

@WolfThank you for the idea of renaming the file at the OS level, this worked beautifully!!

JKing_Esri_0-1623946494327.png

0Kudos