<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Getting map scale in standalone C# application. in ArcObjects SDK Questions</title>
    <link>https://community.esri.com/t5/arcobjects-sdk-questions/getting-map-scale-in-standalone-c-application/m-p/123999#M3273</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;A href="https://community.esri.com/migrated-users/4591"&gt;Carlos Piccirillo&lt;/A&gt; Did you eventually get around this issue?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 01 Mar 2016 10:52:03 GMT</pubDate>
    <dc:creator>MichielStaessen1</dc:creator>
    <dc:date>2016-03-01T10:52:03Z</dc:date>
    <item>
      <title>Getting map scale in standalone C# application.</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/getting-map-scale-in-standalone-c-application/m-p/123998#M3272</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi everyone,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am writing a standalone C# application for creating jpg maps that is being converted from VBA. With help from several people on the forums, I have been able to get everything working without having to use ArcMap at all. I am down to just one glitch and can't figure out how to get around it. At one point, I add a scalebar to the layout and depending on the map scale, I set the units of the scale bar to either esriMiles or esriFeet. The problem I am having is that since I am not running ArcMap and this is all being done in memory, I don't really have map scale to adjust. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In the code below, I get an error at &lt;/SPAN&gt;&lt;STRONG&gt;if (m_pMap.MapScale &amp;gt;= 25000)&lt;/STRONG&gt;&lt;SPAN&gt; with an error of "The data necessary to complete this operation is not yet available." &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have seen a couple of similar posts on the forums but no firm solutions. I have tried everything suggested on these threads including making sure the map has a spatial reference and units.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Later on in another method, I use the map scale also to set the scale to a rounded number (24,000 instead of 24,323) since the layout also has a scale text object.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;How can I get/set the map scale if I am not using ArcMap?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any help is greatly appreciated!!!&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Carlos&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;public static void AddScaleBar()
{
&amp;nbsp;&amp;nbsp;&amp;nbsp; try
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
 stdole.StdFont pFont = new stdole.StdFont();
 pFont.Name = "Arial";

 ITextSymbol pTextSymbol = new TextSymbolClass();
 pTextSymbol.Font = pFont as stdole.IFontDisp;
 pTextSymbol.Size = 5;

 IGraphicsContainer pGraphicsContainer = m_pPageLayout as IGraphicsContainer;
 IFrameElement pFrameElement = pGraphicsContainer.FindFrame(m_pMap);
 IMapFrame mapFrame = pFrameElement as IMapFrame;

 IUID uid = new UIDClass();
 uid.Value = "esriCarto.AlternatingScaleBar";
 IMapSurroundFrame mapSurroundFrame = mapFrame.CreateSurroundFrame(uid as UID, null);
 IElement element = mapSurroundFrame as IElement;

 IEnvelope envelope = new EnvelopeClass();
 envelope.PutCoords(1.24, 0.4, 3.58, 0.55);
 element.Geometry = envelope;

 pGraphicsContainer.AddElement(element, 0);
 IMapSurround mapSurround = mapSurroundFrame.MapSurround;
 IScaleBar pScaleBar = mapSurround as IScaleBar;
 pScaleBar.Divisions = 1;
 pScaleBar.Subdivisions = 2;
 pScaleBar.DivisionsBeforeZero = 0;
 pScaleBar.LabelSymbol = pTextSymbol;
 pScaleBar.UnitLabelPosition = esriScaleBarPos.esriScaleBarBelow;
 pScaleBar.UnitLabelSymbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHACenter;
 pScaleBar.UnitLabelSymbol = pTextSymbol;
 pScaleBar.UnitLabelSymbol.Font = pFont as stdole.IFontDisp;
 pScaleBar.UnitLabelSymbol.Size = pTextSymbol.Size;
 pScaleBar.Name = "scalebar";

 //if map scale is greater than 25000, switch the scale units to miles
 if (m_pMap.MapScale &amp;gt;= 25000)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pScaleBar.Units = esriUnits.esriMiles;
 else
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pScaleBar.Units = esriUnits.esriFeet;

 IGraphicsContainerSelect pGraphicsContainerSelect = pGraphicsContainer as IGraphicsContainerSelect;
 pGraphicsContainerSelect.UnselectAllElements();
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp; catch (Exception ex)
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
 MessageBox.Show(ex.Message);
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
}&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 23 Aug 2011 14:40:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/getting-map-scale-in-standalone-c-application/m-p/123998#M3272</guid>
      <dc:creator>CarlosPiccirillo</dc:creator>
      <dc:date>2011-08-23T14:40:48Z</dc:date>
    </item>
    <item>
      <title>Re: Getting map scale in standalone C# application.</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/getting-map-scale-in-standalone-c-application/m-p/123999#M3273</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;A href="https://community.esri.com/migrated-users/4591"&gt;Carlos Piccirillo&lt;/A&gt; Did you eventually get around this issue?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 01 Mar 2016 10:52:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/getting-map-scale-in-standalone-c-application/m-p/123999#M3273</guid>
      <dc:creator>MichielStaessen1</dc:creator>
      <dc:date>2016-03-01T10:52:03Z</dc:date>
    </item>
    <item>
      <title>Re: Getting map scale in standalone C# application.</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/getting-map-scale-in-standalone-c-application/m-p/124000#M3274</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;i have the same issue. Only when the Process runs in an background job, even if IMap is initialized. The IMap Object is not null, but the access to IMap.Mapscale aborts.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Dec 2017 10:54:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/getting-map-scale-in-standalone-c-application/m-p/124000#M3274</guid>
      <dc:creator>croemersabris</dc:creator>
      <dc:date>2017-12-14T10:54:43Z</dc:date>
    </item>
    <item>
      <title>Re: Getting map scale in standalone C# application.</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/getting-map-scale-in-standalone-c-application/m-p/124001#M3275</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This is how I solved it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #808080; font-family: Consolas; font-size: small;"&gt;///&lt;/SPAN&gt;&lt;SPAN style="color: #008000; font-family: Consolas; font-size: small;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #808080; font-family: Consolas; font-size: small;"&gt;&amp;lt;summary&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: small; font-family: Consolas;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #808080; font-size: small; font-family: Consolas;"&gt;///&lt;/SPAN&gt;&lt;SPAN style="color: #008000; font-size: small; font-family: Consolas;"&gt; Purpose: Determine map scale once you are zoomed into the desired&amp;nbsp;extent. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: small; font-family: Consolas;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #808080; font-size: small; font-family: Consolas;"&gt;///&lt;/SPAN&gt;&lt;SPAN style="color: #008000; font-size: small; font-family: Consolas;"&gt; Cannot use m_pMap.MapScale because it cannot be used outside of ArcMap. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: small; font-family: Consolas;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #808080; font-size: small; font-family: Consolas;"&gt;///&lt;/SPAN&gt;&lt;SPAN style="color: #008000; font-size: small; font-family: Consolas;"&gt; pMapFrame.MapBounds.Height is height of the DataFrame in feet and 7.8 is&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: small; font-family: Consolas;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #808080; font-size: small; font-family: Consolas;"&gt;///&lt;/SPAN&gt;&lt;SPAN style="color: #008000; font-size: small; font-family: Consolas;"&gt; the height of the DataFrame in inches. Before we calculate map scale, ground &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: small; font-family: Consolas;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #808080; font-size: small; font-family: Consolas;"&gt;///&lt;/SPAN&gt;&lt;SPAN style="color: #008000; font-size: small; font-family: Consolas;"&gt; distance needs to be in like units (inches), hence, pMapFrame.MapBounds.Height * 12.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: small; font-family: Consolas;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #808080; font-size: small; font-family: Consolas;"&gt;///&lt;/SPAN&gt;&lt;SPAN style="color: #008000; font-size: small; font-family: Consolas;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #808080; font-size: small; font-family: Consolas;"&gt;&amp;lt;/summary&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: small; font-family: Consolas;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #808080; font-size: small; font-family: Consolas;"&gt;///&lt;/SPAN&gt;&lt;SPAN style="color: #008000; font-size: small; font-family: Consolas;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #808080; font-size: small; font-family: Consolas;"&gt;&amp;lt;returns&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="color: #008000; font-size: small; font-family: Consolas;"&gt;Int32&lt;/SPAN&gt;&lt;SPAN style="color: #808080; font-size: small; font-family: Consolas;"&gt;&amp;lt;/returns&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: small; font-family: Consolas;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: small; font-family: Consolas;"&gt;private&lt;/SPAN&gt;&lt;SPAN style="font-size: small; font-family: Consolas;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: small; font-family: Consolas;"&gt;static&lt;/SPAN&gt;&lt;SPAN style="font-size: small; font-family: Consolas;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #2b91af; font-size: small; font-family: Consolas;"&gt;Int32&lt;/SPAN&gt;&lt;SPAN style="font-size: small; font-family: Consolas;"&gt; GetMapScale()&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: small; font-family: Consolas;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #2b91af; font-size: small; font-family: Consolas;"&gt;IMapFrame&lt;/SPAN&gt;&lt;SPAN style="font-size: small; font-family: Consolas;"&gt; pMapFrame = &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: small; font-family: Consolas;"&gt;new&lt;/SPAN&gt;&lt;SPAN style="font-size: small; font-family: Consolas;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #2b91af; font-size: small; font-family: Consolas;"&gt;MapFrameClass&lt;/SPAN&gt;&lt;SPAN style="font-size: small; font-family: Consolas;"&gt;();&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: small; font-family: Consolas;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #2b91af; font-size: small; font-family: Consolas;"&gt;IGraphicsContainer&lt;/SPAN&gt;&lt;SPAN style="font-size: small; font-family: Consolas;"&gt; pGraphicsContainer = &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: small; font-family: Consolas;"&gt;null&lt;/SPAN&gt;&lt;SPAN style="font-size: small; font-family: Consolas;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: small; font-family: Consolas;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: small; font-family: Consolas;"&gt;try&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: small; font-family: Consolas;"&gt; pGraphicsContainer = m_pPageLayout &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: small; font-family: Consolas;"&gt;as&lt;/SPAN&gt;&lt;SPAN style="font-size: small; font-family: Consolas;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #2b91af; font-size: small; font-family: Consolas;"&gt;IGraphicsContainer&lt;/SPAN&gt;&lt;SPAN style="font-size: small; font-family: Consolas;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: small; font-family: Consolas;"&gt; pMapFrame = pGraphicsContainer.FindFrame(m_pMap) &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: small; font-family: Consolas;"&gt;as&lt;/SPAN&gt;&lt;SPAN style="font-size: small; font-family: Consolas;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #2b91af; font-size: small; font-family: Consolas;"&gt;IMapFrame&lt;/SPAN&gt;&lt;SPAN style="font-size: small; font-family: Consolas;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: small; font-family: Consolas;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: small; font-family: Consolas;"&gt;double&lt;/SPAN&gt;&lt;SPAN style="font-size: small; font-family: Consolas;"&gt; groundDistanceInInches = pMapFrame.MapBounds.Height * 12;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: small; font-family: Consolas;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #2b91af; font-size: small; font-family: Consolas;"&gt;Int32&lt;/SPAN&gt;&lt;SPAN style="font-size: small; font-family: Consolas;"&gt; mapScale = &lt;/SPAN&gt;&lt;SPAN style="color: #2b91af; font-size: small; font-family: Consolas;"&gt;Convert&lt;/SPAN&gt;&lt;SPAN style="font-size: small; font-family: Consolas;"&gt;.ToInt32(groundDistanceInInches / 7.8);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: small; font-family: Consolas;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: small; font-family: Consolas;"&gt;return&lt;/SPAN&gt;&lt;SPAN style="font-size: small; font-family: Consolas;"&gt; mapScale;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: small; font-family: Consolas;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: small; font-family: Consolas;"&gt;catch&lt;/SPAN&gt;&lt;SPAN style="font-size: small; font-family: Consolas;"&gt; (&lt;/SPAN&gt;&lt;SPAN style="color: #2b91af; font-size: small; font-family: Consolas;"&gt;Exception&lt;/SPAN&gt;&lt;SPAN style="font-size: small; font-family: Consolas;"&gt; ex)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: small; font-family: Consolas;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #2b91af; font-size: small; font-family: Consolas;"&gt;Queries&lt;/SPAN&gt;&lt;SPAN style="font-size: small; font-family: Consolas;"&gt;.LogError(ex.StackTrace, ex.Message, &lt;/SPAN&gt;&lt;SPAN style="color: #a31515; font-size: small; font-family: Consolas;"&gt;"GetMapScale"&lt;/SPAN&gt;&lt;SPAN style="font-size: small; font-family: Consolas;"&gt;, &lt;/SPAN&gt;&lt;SPAN style="color: #a31515; font-size: small; font-family: Consolas;"&gt;"ensRegulatoryApplicationTools"&lt;/SPAN&gt;&lt;SPAN style="font-size: small; font-family: Consolas;"&gt;);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: small; font-family: Consolas;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: small; font-family: Consolas;"&gt;return&lt;/SPAN&gt;&lt;SPAN style="font-size: small; font-family: Consolas;"&gt; 0;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: small; font-family: Consolas;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: small; font-family: Consolas;"&gt;finally&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: small; font-family: Consolas;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: small; font-family: Consolas;"&gt;if&lt;/SPAN&gt;&lt;SPAN style="font-size: small; font-family: Consolas;"&gt; (pMapFrame != &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: small; font-family: Consolas;"&gt;null&lt;/SPAN&gt;&lt;SPAN style="font-size: small; font-family: Consolas;"&gt;) { &lt;/SPAN&gt;&lt;SPAN style="color: #2b91af; font-size: small; font-family: Consolas;"&gt;Marshal&lt;/SPAN&gt;&lt;SPAN style="font-size: small; font-family: Consolas;"&gt;.ReleaseComObject(pMapFrame); pMapFrame = &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: small; font-family: Consolas;"&gt;null&lt;/SPAN&gt;&lt;SPAN style="font-size: small; font-family: Consolas;"&gt;; }&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Dec 2017 13:31:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/getting-map-scale-in-standalone-c-application/m-p/124001#M3275</guid>
      <dc:creator>CarlosPiccirillo</dc:creator>
      <dc:date>2017-12-14T13:31:16Z</dc:date>
    </item>
  </channel>
</rss>

