Select to view content in your preferred language

Using dynamic text or python to lookup username and return a full name

4380
6
06-01-2016 11:00 PM
LindsayRaabe
Occasional Contributor

I've googled and experimented and continue to fail. All I'm trying to do is display our Full Name in the Map Layout (a text box) but Arcs dynamic text only returns username (ie "usern" instead of "User Name"). Is there any way of writing a lookup list or If/Else logic script for or python code that will allow me to have a Text box display a users full name?

I'm happy if I need to write a list of users for it to return and will be even happier if it can be done to return someones full name based on windows login or something.

6 Replies
FC_Basson
MVP Alum

Have you investigated the text box's dynamic text string?

It should be  User Name: <dyn type="user"/>

And with Python you can get the Windows username like this:

os.getenv('username')
0 Kudos
LindsayRaabe
Occasional Contributor

This isn't quite what I'm looking for. The username doesn't come in formatted correctly (for instance a user name is "johnd" but I want to display "John Doe") Can this be done using either the python dictionary sort of setup or by reading the dynamic text field?

Also, when I tried your python script, it just returned the script as text. Text Box.JPG

FC_Basson
MVP Alum

Ok, you're results are as expexted.  The Python code can't go in the dynamic text.  You will need to run it seperately or as a tool.  You can look at this post at StackOverflow that works for getting the full username.  It works well, so maybe you can run the code and write the username to the text box at startup if you are using a fixed layout template by creating a Add-in that runs at startup (ArcGIS Help 10.1).

0 Kudos
LindsayRaabe
Occasional Contributor

I found that page during my googles. What do you mean by run it separately or as a tool? Is there another way of displaying information (text, lists, etc) in Layout View besides as a Live Legend, Image or Text Element?

0 Kudos
FC_Basson
MVP Alum

I don't think there is any other way of adding the text to your layout.  You can let the user run a script tool from the toolbox to set the dynamic text of an layout element.  For this you must create a Python scipt and add it to your ArcToolbox (Adding a script tool—Help | ArcGIS for Desktop ), which the user can just run, but that is still too manual and defies the purpose of dynamic text.   The other option is an Add-in that runs at startup.

WesMiller
Deactivated User

You could create a dictionary and return the names. And a text element it would be a little extra work to keep up the list and either run the script or create an Addin

TextElement—Help | ArcGIS for Desktop

users= {'uname':'User Name','oname':'Other Name','yName':'Use Your Name'}
users[os.getenv('username')]
0 Kudos