3

I'm trying to modify the scale of the map so I can further export to pdf.

The mxd document has a fixed map scale option set. The initial value is 250 and final is still 250 unchanged. The code looks like this:

mxdPath = GetResPath() + "\\Template.mxd"
mapDoc = NewObj(esriCarto.MapDocument, esriCarto.IMapDocument)
mapDoc.Open(mxdPath)

pActiveView = mapDoc.ActiveView
pFeatureLayer = pGPUtil.OpenFeatureLayerFromString(path)
pLayer = CType(pFeatureLayer, esriCarto.ILayer)

pMap = mapDoc.Map[0]
pMap.MapScale = 500.0 #this will change the value, but the mxd just doesn't care
pMap.AddLayer(pLayer)
pActiveView.Refresh()
outDocumentPath = GetTempPath() + "\\Document.mxd"
mapDoc.SaveAs(outDocumentPath)
mapDoc.Close()

I also want to mention that setting the Extent through pActiveView.Extent works, but it's harder to get an extent out of a scale

EDIT 1: I have already tried with both Automatic and fixed, on Automatic if I try to get the property it will throw and Exception and if I try to set the property nothing happens also.

EDIT 2: It seems the ArcObjects does actually modify the MapScale when setting the property, but it won't save this option when calling mapDoc.Close(). The workaround was to load the .mxd again using ArcPy and setting the .activeDataFrame.scale property.

I hope this is helpful for people having related problems!

  • Have you tried setting the value on directly on the IDisplayTransformation object. Perhaps that will work despite supposedly referring to the same data: edndoc.esri.com/arcobjectsonline/componenthelp/esricore/… – danielm Mar 13 '18 at 15:46
  • I have just tried it and that doesn't work either – Damian Radinoiu Mar 13 '18 at 15:57
  • Can you just disable the fixed map scale option for that mxd? That should allow you to set the scale as shown in your code. – amasephy Mar 13 '18 at 16:03
  • 1
    Are you running this code from Python? – amasephy Mar 13 '18 at 18:29
  • 1
    Not python, VB.net. Your code is ArcObjects. If you're doing this in python try opening the MXD with arcpy.mapping.MapDocument(outDocumentPath) and set DataFrame.scale then re-save the document resources.arcgis.com/en/help/main/10.2/index.html#/DataFrame/… I know it's double handling but I suspect the object isn't completely ready to set the map scale; I had a similar problem opening a map document from IGXObject, I had to DoEvents() to allow the document to fully open before setting any map elements. – Michael Stimson Mar 14 '18 at 21:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.