Setting Layout view scale

Discussion created by yellow_rose on Dec 10, 2013
I have a requirement to set the layout view scale as data view in order to be able to print the same layer shown at the data view scale

so i tried the following code to set the layout view scale

Public Shared Sub SetLayoutViewScale(ByVal newScale As Double)
        Dim pActiveView As ESRI.ArcGIS.Carto.IActiveView
        Dim pMap As ESRI.ArcGIS.Carto.IMap
        Dim dblDiff As Double
        Dim dblMapScale As Double

            pActiveView = CType(My.ArcMap.Document.PageLayout, ESRI.ArcGIS.Carto.IActiveView)
            pMap = pActiveView.FocusMap
            pMap.MapScale = newScale            ' The problem is in this line
        Catch ex As Exception
            MsgBox("Can't set layout scale")

        End Try
    End Sub

but the problem occurs in this line
pMap.MapScale = newScale 

The MapScale property does not accept the value of newScale and may take different scale.

I have found this issue as a bug in Arc9 but i am currently using 10.1

I have tried to setup arc10.1 sp1 for arcdesktop and ard10.1 sp1 for .net framework sdk

But the same error still occurs.

I have also tried to use the following code
Public Shared Sub SetMapExtentFromScale(ByVal newScale As Double)
        'Get coordinates of current map extent
        Dim pExtent As ESRI.ArcGIS.Geometry.IEnvelope
        Dim dblXMin As Double, dblXMax As Double, dblYMin As Double, dblYMax As Double
        Dim pActiveView As ESRI.ArcGIS.Carto.IActiveView
        Dim pCenterPoint As ESRI.ArcGIS.Geometry.IPoint
        Dim pCenterScale As ESRI.ArcGIS.Carto.ICenterAndScale


            pActiveView = CType(My.ArcMap.Document.PageLayout, ESRI.ArcGIS.Carto.IActiveView)
            pExtent = pActiveView.Extent
            dblXMin = pExtent.XMin
            dblXMax = pExtent.XMax
            dblYMin = pExtent.YMin
            dblYMax = pExtent.YMax

            'Calculate center point of current map extent

            pCenterPoint = New ESRI.ArcGIS.Geometry.Point
            pCenterPoint.SpatialReference = pActiveView.FocusMap.SpatialReference
            pCenterPoint.X = dblXMin + (dblXMax - dblXMin) / 2
            pCenterPoint.Y = dblYMin + (dblYMax - dblYMin) / 2

            'Assign center point and map scale to new CenterAndScale object

            pCenterScale = New ESRI.ArcGIS.Carto.CenterAndScale
            pCenterScale.Center = pCenterPoint
            pCenterScale.MapScale = newScale

            'Assign new CenterAndScale object to MapDescription 
            pActiveView.Extent = CType(pCenterScale, ESRI.ArcGIS.Carto.IMapArea).Extent

        Catch ex As Exception
            MsgBox("Can't set layout scale")

        End Try

    End Sub
but  CType(pCenterScale, ESRI.ArcGIS.Carto.IMapArea).Extent throws an exception

So any help to set the layout scale or workaround would be appreciated.