1 / 50

Customizing ArcInfo 8 with VBA

ESRI EUROPEAN USER CONFERENCE. Customizing ArcInfo 8 with VBA. Overview. Customization options VBA in ArcInfo 8 Introducing CO M Object model Example tasks in VBA. U Customization options. Customization options. AML ODE VBA scripts Using COM objects

vadin
Download Presentation

Customizing ArcInfo 8 with VBA

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ESRI EUROPEAN USER CONFERENCE Customizing ArcInfo 8 with VBA

  2. Overview • Customization options • VBA in ArcInfo 8 • Introducing COM • Object model • Example tasks in VBA

  3. U Customization options

  4. Customization options • AML • ODE • VBA scripts • Using COM objects • Extending the application • Creating COM objects • Use any COM compliant language Customization options

  5. Comparing customizations • VBA • Customizations are document based • Less code • Not compiled • Integrated debugging • Third party language • Create COM objects that plug into ArcInfo • More code • Compiled Customization options

  6. VBA in ArcInfo 8

  7. The development environment • VBA Editor • Visual Basic programming VBA in ArcInfo 8

  8. Storing customizations • Customization context • ArcMap has 3 levels of storage • ArcCatalog only uses a Normal Template VBA in ArcInfo 8

  9. This Document Base Template Normal Template The VBA project explorer VBA in ArcInfo 8

  10. Running macros • Code can be added to Modules or Documents as Pocedures • A macro is a VBA Procedure • Test run a macro from the VBA Editor or the Macros dialog (Tools/Macros/Macros) VBA in ArcInfo 8

  11. Add a macro to a toolbar • Drag a macro onto a toolbar or menu • The macro becomes a button on the toolbar • Edit the control’s properties (image, etc.) • Define UIControls and use the Properties and Events for storing macros VBA in ArcInfo 8

  12. Document Events • Perform some actions when certain things occur in the document • Write code in Project.ThisDocument VBA in ArcInfo 8

  13. ArcMap (MxDocument) ActiveViewChanged BeforeCloseDocument CloseDocument MapsChanged NewDocument OnContextMenu OpenDocument ArcCatalog (GxDocument) ActiveViewChanged CloseDocument NewDocument OnContextMenu OpenDocument Document Events VBA in ArcInfo 8

  14. User Forms • VB Forms created in the VBA Editor • Can be called from your macros • Used for display or input of data VBA in ArcInfo 8

  15. Creating Templates • Create a new document • Make your customizations • Save As template • New documents can now easily load your customizations VBA in ArcInfo 8

  16. Introducing COM

  17. Introducing COM • Component Object Model • Binary way for objects to communicate • Technology behind Object Linking and Embedding (OLE) • Active X • Any technology built on COM Introducing COM

  18. Extensibility • Extensibility • Create objects that other applications can use (e.g. ArcMap) • Use any COM compliant language Introducing COM

  19. Integration • Object Linking and Embedding • Can integrate ESRI objects into third party applications • Can integrate third party objects into ESRI applications • VBA Introducing COM

  20. Working with objects • Objects • Methods • Properties Introducing COM

  21. VB object example • pDog is a reference to the entire object • Dim declares the variable • Use Set when setting a variable to an object • Use New to create a new object Dim pDog As Dog Set pDog = New Dog pDog.Bark DOG Bark Name Color Growl CallPet Introducing COM

  22. COM object interfaces • Define methods and properties • Logical group • An object can have one or more interfaces • The only way to communicate with an object is through its interfaces Introducing COM

  23. DOG IDog Color Bark IPet Name Growl CallPet COM objects • Objects • Interfaces • Methods • Properties Introducing COM

  24. DOG IDog Color Bark IPet Name Growl CallPet VB COM object example • pDog is a reference to the IDog interface of the DOG object Dim pDog As IDog Set pDog = New Dog pDog.Bark Introducing COM

  25. DOG IDog Color Bark IPet Name Growl CallPet Getting a different interface • QueryInterface - QI • pPet holds a new interface to the existing dog object • pDog still holds the IDog interface Dim pDog As IDog Set pDog = New Dog pDog.Bark Dim pPet As IPet Set pPet = pDog pPet.CallPet Introducing COM

  26. DOG IDog Color Bark CAT IPet Name Growl Color ICat CallPet Meow Purr IPet Name CallPet Polymorphism • Multiple objects can support the same interface • The object implements the methods and properties Introducing COM

  27. DOG IDog Color Bark CAT IPet Name Growl Color ICat CallPet Meow Purr IPet Name CallPet Multiple objects - VB Example Dim pDog As IDog Dim pCat As ICat Set pDog = New Dog Set pCat = New Cat Dim pPet As IPet Set pPet = pDog pPet.CallPet Set pPet = pCat pPet.CallPet Introducing COM

  28. Object model

  29. Object diagrams • Define the types of objects • CoClass • Class • Abstract Class • Help define which interfaces are on an object • Show relationships between objects • Which objects can be created • How objects are created Object model

  30. IMap Map IActiveView CoClass • Instantiable and Creatable • Can create with the New keyword • Shaded and 3D Dim pMap As IMap Set pMap = New Map Object model

  31. IFeature Feature IFeatureBuffer Class • Instantiable but not creatable • Can’t be created with the New Keyword • Created from other objects • No shade and 3D Object model

  32. ILayer Layer Abstract class • Not instantiable and not creatable • Holds interfaces • Shaded and 2D Object model

  33. Class Relationships • “Is a type of” • “Has a” • “Composed of” • “Creates a” Object model

  34. ILayer Layer IFeatureLayer FeatureLayer IGeoDataset “Is a type of” relationship • Interfaces on the parent are available on the child Object model

  35. IActiveViewEvents Legend ILegend IClone LegendFormat ILegendFormat “Has A” relationship • “Has A” objects are not destroyed with the parent Object model

  36. ILayer Layer IMap Map * IActiveView “Composed of” relationship • “Composed of” objects are destroyed with the parent Object model

  37. FeatureClass IGeoDataset Feature IFeature IFeatureClass IFeatureBuffer “Creates A” Relationship Object model

  38. Class diagram key Object model

  39. Example tasks in VBA

  40. Example tasks • Change the message in the Status Bar • Change the extent to a selected layer • Executing an existing command Example tasks in VBA

  41. Change the message on the status bar • Use the IApplication interface of the Application object • Top level object • Contains a StatusBar object • Application variable is preset to IApplication Application.Statusbar.Message(0) = "ArcMap is great" Example tasks in VBA

  42. Change the extent to a selected layer • Get the document object • Get the selected layer in the document • Set the extent of the map to the extent of the layer Example tasks in VBA

  43. IApplication IDocument IMap Application Document Map IMxApplication IMxDocument IActiveView Document • One document per application • ThisDocument variable • A document • Contains one or more maps * Example tasks in VBA

  44. IMap Map IActiveView Maps and layers • A map can have 0 or more layers • Types of layers • Feature, Graphics, Annotation, Image, Group * ILayer Layer IFeatureLayer FeatureLayer IGeoDataset Example tasks in VBA

  45. IMxDocument • IMxDocument • Operations specific to ArcMap documents Dim pMxDoc As IMxDocument Set pMxDoc = ThisDocument Example tasks in VBA

  46. IMxDocument properties • IMxDocument.ActiveView returns IActiveView • Of map in Geographic view • Of PageLayout in page view • IMxDocument.SelectedLayer returns the selected layer in the TOC Example tasks in VBA

  47. Get to the extent • IActiveView.Extent sets / gets the extent of the map • IGeoDataset.Extent gets the extent of the layer Dim pMxDoc As IMxDocument Set pMxDoc = ThisDocument Dim pGeoDataset As IGeoDataset Set pGeoDataset = pMxDoc.SelectedLayer pMxDoc.ActiveView.Extent = pGeoDataset.Extent pMxDoc.ActiveView.Refresh Example tasks in VBA

  48. Executing an existing command • Get a commanditem from the commandbars collection • Use ArcID • Execute the commanditem Example tasks in VBA

  49. ICommandItem CommandBars • Collection of Menus and toolbars • Contain Commands, Macros, UI Controls • CommandBars.Find(UID) returns ICommandItem • UID (Unique Identifier) for all COM objects ICommandItem CommandItem * ICommandBar CommandBar Example tasks in VBA

  50. Executing a command • ArcID module returns the UID for all ESRI CommandItems • CommandItems are organized in ArcID by Category_Name Dim pCommandItem As ICommandItem Set pCommandItem = CommandBars.Find(ArcID.File_AddData) pCommandItem.Execute Example tasks in VBA

More Related