2

Seems like this should be dead simple. I'm writing an add-in for ArcMap 10 in VB.Net. I need code that will reproduce the 'Selection --> Zoom To Selected Feature' menu option.

asked Oct 4, 2010 at 20:40
2
  • What is causing problems? Add-in or "Zoom to selected"? Commented Oct 5, 2010 at 14:50
  • Implementing "Zoom To Selected" inside the Add-in. The Add-in itself is working fine, other than the Zoom To Selected feature. I assumed there would be some VB.Net equivalent to the python code here: gis.stackexchange.com/questions/1711/… Commented Oct 5, 2010 at 15:00

3 Answers 3

2

You can call the built-in command for "Zoom to Selected Features" using the CLSID or ProgID.

{AB073B49-DE5E-11D1-AA80-00C04FA37860} esriArcMapUI.ZoomToSelectedCommand

http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#/ArcMap_commands/00010000029s000000/

http://resources.esri.com/help/9.3/arcgisdesktop/com/shared/desktop/reference/ArcMapIds.htm

answered Oct 5, 2010 at 18:29
1
  • Awesome. Exactly what I was looking for. I've been wasting my time trying to implement this manually in the code using envelopes, etc. but I really didn't need that level of granular control. I knew there had to be a straightforward way to simply use the existing toolbar commands. Thanks again! Commented Oct 5, 2010 at 18:55
1

I had problems implementing the above solutions - the syntax hadn't been updated. This is my solution.

 Dim pUID As New UID
 'set the puid by using the clsid
 'pUID.Value = "{AB073B49-DE5E-11D1-AA80-00C04FA37860}"
 'Put subtype here if there is one. There isn't in this case so you don't need it.
 'pUID.SubType = 0
 'Used the ProgID instead. Easier for someone else to read the code.
 pUID.Value = "esriArcMapUI.ZoomToSelectedCommand"
 My.ArcMap.Application.Document.CommandBars.Find(pUID).Execute()

This was written for an add-in using ArcGIS 10sp2 and Visual Studio 2008.

answered Sep 12, 2011 at 18:04
0
 public void ZoomToSelectedFeatures()
 {
 ESRI.ArcGIS.Carto.IActiveView pActiveView;
 ESRI.ArcGIS.Carto.IMap pMap;
 ESRI.ArcGIS.Geodatabase.IEnumFeature pEnumFeature;
 ESRI.ArcGIS.Geodatabase.IFeature pFeature;
 pMap = (IMap)m_hookHelper.FocusMap;
 pEnumFeature = (IEnumFeature)pMap.FeatureSelection;
 pFeature = pEnumFeature.Next();
 ESRI.ArcGIS.Geometry.IEnvelope pEnvelope;
 pEnvelope = new EnvelopeClass();
 while (pFeature != null)
 {
 pEnvelope.Union(pFeature.Shape.Envelope);
 pFeature = pEnumFeature.Next();
 }
 pEnvelope.Expand(1.2, 1.2, true);
 pActiveView = m_hookHelper.ActiveView;
 pActiveView.Extent = pEnvelope;
 pActiveView.Refresh();
 }
answered Dec 8, 2012 at 1:31

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.