Graphic Element Table Placement

2427
5
09-01-2010 05:04 PM
TedCronin
MVP Honored Contributor
When trying to set the elementPositionX and elementPositionY with Tables in a layout, the bounding box is larger than the table and thus the element is not being placed as expected.  If I move the bounding box right on the table (Note: There are bugs with doing this in Layout (Nims have been created)), when a script is run, the bounding box is expanded back out to its original location thus does not get placed as one would expect.

I can create a video and upload to YouTube for a better explanation, if you want.

Video here:
http://www.youtube.com/watch?v=lKK8YZ-pd7Y
0 Kudos
5 Replies
JeffMoulds
Esri Contributor
Hey Ted,

I couldnt make out your code in the video, but I was able to get this basic script to work. Can you let me know if it works for you?

import arcpy
mxd = arcpy.mapping.MapDocument(r"C:\temp\forum\table.mxd")
elm = arcpy.mapping.ListLayoutElements(mxd, "GRAPHIC_ELEMENT")[0]
elm.elementPositionY = 1
mxd.save()
del mxd


I created a table layout element that had a buch of space under it, resized the layout element to match the bottom of the table, then ran the code.
0 Kudos
TedCronin
MVP Honored Contributor
Hey Ted,

I couldnt make out your code in the video, but I was able to get this basic script to work. Can you let me know if it works for you?

import arcpy
mxd = arcpy.mapping.MapDocument(r"C:\temp\forum\table.mxd")
elm = arcpy.mapping.ListLayoutElements(mxd, "GRAPHIC_ELEMENT")[0]
elm.elementPositionY = 1
mxd.save()
del mxd
I created a table layout element that had a buch of space under it, resized the layout element to match the bottom of the table, then ran the code.


Basically, the resize is not what I would want to have to do manually.  When the Table is added, it should behave like a Report in that the bounding box is on top of the outside extent.

import arcpy
import os
import datetime
from arcpy import env as ENV
from arcpy import mapping as MAP

ENV.overwriteOutput = True

ENV.workspace = r"C:\1GIS\Test"

wrksp = ENV.workspace

mxd = MAP.MapDocument (r"C:\1GIS\Test\MappingModule.mxd")

for elm in MAP.ListLayoutElements (mxd):
    print elm.name
    if elm.name == "ReportMap":
        elm.elementHeight = 2
        elm.elelmentWidth = 2
        elm.elementPositionX = 6.5
        elm.elementPositionY = .5
    if elm.name == "TableMap":
        elm.elementHeight = 2
        elm.elelmentWidth = 2
        elm.elementPositionX = .5
        elm.elementPositionY = .5

mxd.save ()

del mxd



This is really just test code for playing with the mapping module.
0 Kudos
HeatherEisan
Esri Contributor
Ted,

What are the format setting you are using when creating your table? (Expand Cells, Auto Fit Cells etc...)  Any details on how you created your table is helpful in figuring out why the GTE envelope is not matching the table extent.  Also, maybe look into using the Layout Rules, its similar to Show Element Rule Manager.  You can define the relative placement of surround elements on your page layout.
0 Kudos
TedCronin
MVP Honored Contributor
Ok, I think I understand Heather.  You threw me a curve, I think (Good Pitch).  You are referring to GTE from Production Mapping Correct, if so, I am referring to Core Tables using arcpy.mapping, but you do bring up an interesting point, perhaps using GTE is better than normal tables in Layouts, especially with all of the 10 idiosyncrasies with normal tables.  Hopefully some of these will be fixed with SP1, though, but definitely worth a test case for sure.

@Jeff, I still need to try out your code, every other week I am working with the mapping module, but thanks for your snippet, you only align Position Y, and only with a single Graphic Element.  Python is a lot more fun to work with than my other week which is straight server, too bad the two could not be more integrated, hint Python API 😛
0 Kudos
HeatherEisan
Esri Contributor
Hi Ted,

That is what I assumed you were using (GTE).  It would be useful to use when creating tables in your map layout.  You may want to consider it or at least play around with it to see if it suits you needs.
0 Kudos