Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I need to put in a specific text into a text element. The initials of the user who built the map.

With arcpy I am trying to set the text element with dynamic text. If I put

<dyn type="user"/> 

in the user text element it gives me, correctly, the user's user name. I want to use the user name in a python dictionary to put the users initials instead.

dictUserElmt = { "jperez" : "JP" }

Using arcpy to read the text of my text element, textElement.text, returns (again correctly)

u'<dyn type="user"/>'.  

How do I get the actual output of the dynamic text "jperez" so I can use my dictionary to have the text element set to "JP".

I'm sure my wording is confusing because I am confused on how to approach. Thanks.

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

Is something like below what you are looking to do? For a given username look up and return their initials from the dictionary?

>>> d = {"jperez":"JP", "cooperc":"CC"}
>>> user = "jperez"
>>> if user in d.keys():
...     inits = d[user]
...
>>> inits
'JP'

Now, that said, are you getting the author name from the MXD properties?

>>> import arcpy
>>> mxd = arcpy.mapping.MapDocument("CURRENT")
>>> a = mxd.author
>>> print a
>>> a
u''
>>> a = mxd.author
>>> print a
Chad Cooper

If so, that has to be set by the user (you can see I got u'' on my trial before I explicitly set my name as the MXD author) and saved in the MXD I believe. In your code, you have your name as jperez, which looks like a Windows login maybe? I wonder how using the getpass module to get the current login name would work? That way you could go by those, which pretty much stay the same.

>>> import getpass
>>> getpass.getuser()
'chad'
>>> 
share|improve this answer
    
That will work for my question. Thanks. I'd still be interested if anyone could supply the answer on the dynamic text specific question. How to read into python the output that the dynamic text tags would produce in ArcMap? I bet I'll have to do that someday soon with something else..and it will polish my automation! Thanks Chad! –  Justin Mar 2 '12 at 18:31
    
Sorry, I misunderstood the question, your edits cleared it up. That's interesting, because if you look at the text properties dialog box for the dynamic author element, the text ends up being the dynamic text there as well, which I guess helps explain why you get that with the element.text call as well. –  Chad Cooper Mar 2 '12 at 19:44
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.