0

I'm building an application to automate the production of MXDs for printing. I can add the layers from the database just fine, and configure the page layout. Now I want to set a particular scale to show in the layout data frame view, but I'm running into a problem.

Problem: the Data View scale is different than the Layout View scale.

I am successfully setting the scale of the map with:

map = map_doc.Map(0)
map.MapScale = scale_variable

However, that sets the Data View scale to whatever I want it to be, but in the layout the scale is changed, and I have no idea which scale to set in the Data View so I get the scale I want in the layout. I could do an ugly h4x and multiply my scale variable to the ratio of scale change between Data View and Layout, but this ratio changes with each MXD (as it focus on different regions).

Now, IMapFrame also has a scale property, but setting the scale through IMapFrame does nothing. This following code should work, but doesn't:

map = map_doc.Map(0)
page_layout = map_doc.PageLayout
graphics_cont = page_layout.QueryInterface(esriCarto.IGraphicsContainer)
frame_elem = graphics_cont.FindFrame(map)
map_frame = frame_elem.QueryInterface(esriCarto.IMapFrame)

map_frame.MapScale = scale_variable

It's not that it's not being assigned. There is no error message, and if I print the values it gives me the correct values:

>>> scale_variable = 100000
>>> print scale_variable
100000
>>> map_frame.MapScale = scale_variable
>>> print map_frame.MapScale
100000.0

However, this is not reflected in the map or the layout. Thus, I'm somewhat unsure of what to do next.

1

1 Answer 1

0

Ok, I found out what was giving the error. The scale was being set correctly, but was being done so in an empty map. When I started populating it with layers, each new layer loaded would reset the scale to some other value.

Thus, the way to fix it was to first populate the Data Frame with all the layers, then set the desired scale.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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