Private Type My_ArcObjects IMxApplication As IMxApplication IPrinter As IPrinter IPaper As IPaper IPageLayout As IPageLayout IEmfPrinter As IEmfPrinter IExport As IExport IScreenDisplay As IScreenDisplay ISimpleRenderer As ISimpleRenderer ISimpleFillSymbol As ISimpleFillSymbol IDraw As IDraw IClone As IClone ImouseCursor As ImouseCursor ICartographicLineSymbol As ICartographicLineSymbol IPolyline As IPolyline IArrowMarkerSymbol As IArrowMarkerSymbol IMxDocument As IMxDocument IActiveView As IActiveView IMap As IMap IMaps As IMaps iGeoFeatureLayer As iGeoFeatureLayer ILayer As ILayer IDisplayTransformation As IDisplayTransformation ITextsymbol As ITextsymbol IFontDisp As IFontDisp IField As IField IFields As IFields IFieldsEdit As IFieldsEdit IFieldEdit As IFieldEdit ICursor As ICursor iRow As iRow ITable As ITable ISelectionSet As ISelectionSet IQueryFilter As IQueryFilter IFeatureSelection As IFeatureSelection iFeatureLayer As iFeatureLayer IFeatureCursor As IFeatureCursor IFeature As IFeature IDataSet As IDataSet IEnvelope As IEnvelope IFeatureClass As IFeatureClass IEnumVertex As IEnumVertex IFillSymbol As IFillSymbol ICommandItem As ICommandItem ICommandBar As ICommandBar ICommandBars As ICommandBars IWorkspaceFactory As IWorkspaceFactory IPropertySet As IPropertySet IWorkspace As IWorkspace IFeatureWorkspace As IFeatureWorkspace IPoint As IPoint IPointCollection As IPointCollection ICurve As ICurve IPolygon As IPolygon ILine As ILine IGeometry As IGeometry IGeometryCollection As IGeometryCollection IGeometryDefEdit As IGeometryDefEdit IGeometryDef As IGeometryDef ISpatialReference As ISpatialReference IWorkspaceEdit As IWorkspaceEdit SpatialReferenceEnvironment As SpatialReferenceEnvironment IProjectedCoordinateSystem As IProjectedCoordinateSystem IAnnotateLayerPropertiesCollection As IAnnotateLayerPropertiesCollection '--------------- Indexes ------------ RowCount As Long ' Row Count PartCount As Long ' Part Count PointCount As Long ' Point Count ShapeIndex As Long ' Graphic Table Index RowIndex As Long ' Current Row PartIndex As Long ' Current Polygon / Polyline PART Index PointIndex As Long ' Current Polygon / Polyline Point Index End Type Private Type this A As My_ArcObjects Message As String Color As Class_Color End Type Dim Lib As New Class_Lib Private this As this '======================================================= ' Class Initialize '======================================================= Private Sub Class_Initialize() Set this.A.IMxDocument = ThisDocument Set this.A.IMxApplication = Application Set this.A.IMaps = this.A.IMxDocument.Maps Set this.Color = New Class_Color End Sub '======================================================= ' Messsage (Let) '======================================================= Public Property Let Message(Text As String) this.Message = Text End Property '======================================================= ' Message (Get) '======================================================= Public Property Get Message() As String Message = this.Message End Property '======================================================= ' TurnOnAllLayers '======================================================= Public Sub TurnOnAllLayers() Dim i Dim J For i = 1 To this.A.IMaps.Count Set this.A.IMap = this.A.IMaps.Item(i - 1) For J = 1 To this.A.IMap.LayerCount Set this.A.ILayer = this.A.IMap.Layer(J - 1) this.A.ILayer.Visible = True Next J Next i this.A.IMxDocument.UpdateContents this.A.IMxDocument.ActiveView.Refresh End Sub '======================================================= ' TurnOffAllLayers '======================================================= Public Sub TurnOffAllLayers() Dim i Dim J For i = 1 To this.A.IMaps.Count Set this.A.IMap = this.A.IMaps.Item(i - 1) For J = 1 To this.A.IMap.LayerCount Set this.A.ILayer = this.A.IMap.Layer(J - 1) this.A.ILayer.Visible = False Next J Next i this.A.IMxDocument.UpdateContents this.A.IMxDocument.ActiveView.Refresh End Sub '======================================================= ' ZoomIn '======================================================= Public Sub ZoomIn() Dim Center As IPoint Set this.A.IMxDocument = Application.Document Set this.A.IActiveView = this.A.IMxDocument.FocusMap Set this.A.IDisplayTransformation = this.A.IActiveView.ScreenDisplay.DisplayTransformation Set this.A.IEnvelope = this.A.IActiveView.Extent Set Center = New Point Center.x = (this.A.IEnvelope.XMax + this.A.IEnvelope.xmin) / 2 Center.y = (this.A.IEnvelope.YMax + this.A.IEnvelope.ymin) / 2 this.A.IEnvelope.width = this.A.IEnvelope.width / 2 this.A.IEnvelope.height = this.A.IEnvelope.height / 2 this.A.IEnvelope.CenterAt Center this.A.IDisplayTransformation.visibleBounds = this.A.IEnvelope this.A.IActiveView.Refresh End Sub '======================================================= ' ZoomOut '======================================================= Public Sub ZoomOut() Dim Center As IPoint Set this.A.IActiveView = this.A.IMxDocument.FocusMap Set this.A.IDisplayTransformation = this.A.IActiveView.ScreenDisplay.DisplayTransformation Set this.A.IEnvelope = this.A.IActiveView.Extent Set Center = New Point Center.x = (this.A.IEnvelope.XMax + this.A.IEnvelope.xmin) / 2 Center.y = (this.A.IEnvelope.YMax + this.A.IEnvelope.ymin) / 2 this.A.IEnvelope.width = this.A.IEnvelope.width / 0.2 this.A.IEnvelope.height = this.A.IEnvelope.height / 0.2 this.A.IEnvelope.CenterAt Center MsgBox "x value:" & Center.x & " Y: " & Center.y this.A.IDisplayTransformation.visibleBounds = this.A.IEnvelope this.A.IActiveView.Refresh End Sub '======================================================= ' CenterTo '======================================================= Public Sub CenterTo(x, y) Dim Center As IPoint Set this.A.IActiveView = this.A.IMxDocument.FocusMap Set this.A.IDisplayTransformation = this.A.IActiveView.ScreenDisplay.DisplayTransformation Set this.A.IEnvelope = this.A.IActiveView.Extent Set Center = New Point Center.x = x Center.y = y this.A.IEnvelope.CenterAt Center this.A.IDisplayTransformation.visibleBounds = this.A.IEnvelope this.A.IActiveView.Refresh End Sub '======================================================= ' ShowCenter '======================================================= Public Sub ShowCenter(x, y) Dim Center As IPoint Set this.A.IActiveView = this.A.IMxDocument.FocusMap Set this.A.IDisplayTransformation = this.A.IActiveView.ScreenDisplay.DisplayTransformation Set this.A.IEnvelope = this.A.IActiveView.Extent Set Center = New Point Center.x = (this.A.IEnvelope.XMax + this.A.IEnvelope.xmin) / 2 Center.y = (this.A.IEnvelope.YMax + this.A.IEnvelope.ymin) / 2 MsgBox "X value: " & Center.x & " " & vbCrLf & _ "Y value: " & Center.y & " " & vbCrLf & _ "Height: " & this.A.IEnvelope.height & vbCrLf & _ "Width: " & this.A.IEnvelope.width End Sub '======================================================= ' FindLayer '======================================================= Public Function FindLayer(name) Dim i, J FindLayer = True For i = 0 To this.A.IMaps.Count - 1 Set this.A.IMap = this.A.IMaps.Item(i) For J = 0 To this.A.IMap.LayerCount - 1 If TypeOf this.A.IMap.Layer(J) Is iFeatureLayer Then Set this.A.iFeatureLayer = this.A.IMap.Layer(J) If (LCase(this.A.iFeatureLayer.name) = LCase(name)) Then Exit Function End If Next J Next i FindLayer = False End Function '======================================================= ' Turn Off Layer '======================================================= Public Function TurnOffLayer(name) If (Not FindLayer(name)) Then Exit Function Set this.A.ILayer = this.A.iFeatureLayer this.A.ILayer.Visible = False this.A.IMxDocument.UpdateContents this.A.IMxDocument.ActiveView.Refresh End Function '======================================================= ' Turn On Layer '======================================================= Public Function TurnOnLayer(name) If (Not FindLayer(name)) Then Exit Function Set this.A.ILayer = this.A.iFeatureLayer this.A.ILayer.Visible = True this.A.IMxDocument.UpdateContents this.A.IMxDocument.ActiveView.Refresh End Function '======================================================= ' Add Shapefile '======================================================= Public Function AddShapeFile(filename) Set this.A.IWorkspaceFactory = New ShapefileWorkspaceFactory Set this.A.IFeatureWorkspace = this.A.IWorkspaceFactory.OpenFromFile(Lib.ExtractFilepath(filename), 0) Set this.A.IFeatureClass = this.A.IFeatureWorkspace.OpenFeatureClass(Lib.ExtractFileNam(filename)) Set this.A.iFeatureLayer = New FeatureLayer Set this.A.iFeatureLayer.FeatureClass = this.A.IFeatureClass this.A.iFeatureLayer.name = this.A.IFeatureClass.AliasName this.A.IMxDocument.AddLayer this.A.iFeatureLayer this.A.IMxDocument.ActiveView.PartialRefresh esriViewGeography, this.A.iFeatureLayer, Nothing End Function '======================================================= ' PrintActiveView '======================================================= Public Sub PrintActiveView() Dim deviceBounds As IEnvelope Dim deviceFrame As tagRECT Dim visibleBounds As IEnvelope Dim pageLayoutView As IActiveView Dim printableBounds As IEnvelope Dim hDC As Long Dim xmin Dim ymin Set deviceBounds = New Envelope Set visibleBounds = New Envelope Set this.A.IPrinter = this.A.IMxApplication.Printer Set this.A.IPaper = this.A.IPrinter.Paper Set this.A.IPageLayout = this.A.IMxDocument.PageLayout Set this.A.IActiveView = this.A.IMxDocument.ActiveView Set visibleBounds = this.A.IActiveView.ScreenDisplay.ClipEnvelope this.A.IPageLayout.Page.GetDeviceBounds this.A.IPrinter, 1, 0, this.A.IPrinter.Resolution, deviceBounds deviceFrame.Left = deviceBounds.xmin deviceFrame.Right = deviceBounds.XMax deviceFrame.Top = deviceBounds.ymin deviceFrame.bottom = deviceBounds.YMax Set pageLayoutView = this.A.IPageLayout If (TypeOf this.A.IActiveView Is IPageLayout) Then Set printableBound = this.A.IPrinter.printableBounds this.A.IPageLayout.Page.GetPageBounds this.A.IPrinter, 0, 0, visibleBounds End If Set this.A.IEmfPrinter = this.A.IPrinter '----------------- Offset device bounds for EMF printers only ------------- If (TypeOf this.A.IPrinter Is IEmfPrinter) Then Set printableBounds = this.A.IPrinter.printableBounds xmin = printableBounds.xmin ymin = printableBounds.ymin XMax = printableBounds.XMax YMax = printableBounds.YMax deviceFrame.Left = xmin * this.A.IPrinter.Resolution deviceFrame.Top = ymin * this.A.IPrinter.Resolution deviceFrame.Right = XMax * this.A.IPrinter.Resolution deviceFrame.bottom = YMax * this.A.IPrinter.Resolution End If '-------------------------------------------------------------------------- Set visibleBounds = this.A.IActiveView.ScreenDisplay.ClipEnvelope hDC = this.A.IPrinter.StartPrinting(deviceBounds, 0) this.A.IActiveView.Output hDC, this.A.IPrinter.Resolution, deviceFrame, visibleBounds, Nothing this.A.IPrinter.FinishPrinting End Sub '======================================================= ' Printer '======================================================= Function Test(x, y) Dim arrow As IMarkerSymbol Set arrow = New ArrowMarkerSymbol arrow.Angle = 0 arrow.Size = 50 arrow.XOffset = 0 arrow.YOffset = 0 Set this.A.IActiveView = this.A.IMxDocument.ActiveView Set this.A.IScreenDisplay = this.A.IActiveView.ScreenDisplay Set this.A.IPoint = this.A.IScreenDisplay.DisplayTransformation.ToMapPoint(x, y) Set this.A.IDraw = this.A.IScreenDisplay this.A.IDraw.StartDrawing this.A.IScreenDisplay.WindowDC, esriNoScreenCache Set this.A.ISimpleFillSymbol = New simpleFillSymbol this.A.ISimpleFillSymbol.Color = this.Color.Esri("Green") this.A.ISimpleFillSymbol.Style = esriSMSDiamond this.A.ISimpleFillSymbol.Outline.width = 4 Set this.A.ISimpleRenderer = New simpleRenderer Set this.A.ISimpleRenderer.Symbol = simpleFillSymbol ' this.A.IDraw this.A.ISimpleFillSymbol this.A.IDraw.FinishDrawing End Function '======================================================= ' Draw '======================================================= Function draw(hDC As OLE_HANDLE) Dim rect As tagRECT rect.Top = 0 rect.bottom = 40 rect.Right = 60 rect.Left = 0 Set this.A.IActiveView = this.A.IMxDocument.ActiveView Set this.A.IScreenDisplay = this.A.IActiveView.ScreenDisplay Set this.A.IDraw = this.A.IScreenDisplay this.A.IDraw.StartDrawing hDC, esriNoScreenCache this.A.IActiveView.Output hDC, 96, rect, Nothing, Nothing this.A.IDraw.FinishDrawing End Function '======================================================= ' setOrentation '======================================================= Private Sub setOrientation(orientation) Set this.A.IActiveView = this.A.IMxDocument.ActiveView Set this.A.IClone = this.A.IMxApplication.Printer Set this.A.IPrinter = this.A.IClone.Clone Set this.A.IPaper = this.A.IPrinter.Paper this.A.IPaper.orientation = orientation Set this.A.IMxApplication.Printer = this.A.IPrinter Set this.A.IPageLayout = this.A.IMxDocument.PageLayout this.A.IPageLayout.Page.orientation = orientation this.A.IActiveView.PrinterChanged this.A.IPrinter End Sub '======================================================= ' setLandscape '======================================================= Public Sub setLandscape() Const landscape = 2 setOrientation (landscape) End Sub '======================================================= ' setPortrait '======================================================= Public Sub setPortrait() Const Portrait = 1 setOrientation (Portrait) End Sub '======================================================= ' ExportToJpeg '======================================================= Public Sub ExportToJeg(height, width, filename) Dim exportRECT As tagRECT Dim hDC As Long Dim Scl, scalex, scaley Set this.A.IActiveView = this.A.IMxDocument.ActiveView Set this.A.IExport = New ExportJPEG Set this.A.IPrinter = this.A.IMxApplication.Printer Set this.A.IPaper = this.A.IPrinter.Paper Set this.A.IPageLayout = this.A.IMxDocument.PageLayout this.A.IExport.ExportFileName = filename this.A.IExport.Resolution = 1 scalex = width / this.A.IActiveView.ScreenDisplay.ClipEnvelope.width scaley = height / this.A.IActiveView.ScreenDisplay.ClipEnvelope.height Scl = scalex If (scaley > Scl) Then Scl = scaley exportRECT.Left = 0 exportRECT.Top = 0 exportRECT.Right = this.A.IActiveView.ScreenDisplay.ClipEnvelope.width * Scl exportRECT.bottom = this.A.IActiveView.ScreenDisplay.ClipEnvelope.height * Scl h = this.A.IActiveView.ScreenDisplay.ClipEnvelope.height * Scl w = this.A.IActiveView.ScreenDisplay.ClipEnvelope.width * Scl Set this.A.IEnvelope = New Envelope this.A.IEnvelope.PutCoords exportRECT.Left, exportRECT.Top, exportRECT.Right, exportRECT.bottom this.A.IExport.PixelBounds = this.A.IEnvelope hDC = this.A.IExport.StartExporting this.A.IActiveView.Output hDC, this.A.IExport.Resolution, exportRECT, Nothing, Nothing '--------------------- Draw Polygon ---------- Set this.A.IScreenDisplay = this.A.IActiveView.ScreenDisplay Set this.A.IFillSymbol = New simpleFillSymbol this.A.IFillSymbol.Color = this.Color.Esri("Tomato") this.A.IScreenDisplay.StartDrawing hDC, esriNoScreenCache this.A.IScreenDisplay.SetSymbol this.A.IFillSymbol this.A.IScreenDisplay.drawPolygon getPolygon(200, 200) '--------------------- Draw Polygon ---------- this.A.IScreenDisplay.FinishDrawing this.A.IExport.FinishExporting this.A.IExport.Cleanup End Sub '======================================================= ' getPolygon '======================================================= Function getPolygon(x, y) As IPolygon Dim h, w, x1, y1 Dim Text Set getPolygon = New Polygon Set this.A.IPointCollection = getPolygon Set this.A.IPoint = New Point h = 10 w = 10 x1 = x - (w / 2) y1 = y - (h / 2) Set this.A.IActiveView = this.A.IMxDocument.FocusMap Set this.A.IScreenDisplay = this.A.IActiveView.ScreenDisplay Set this.A.IPoint = this.A.IScreenDisplay.DisplayTransformation.ToMapPoint(x1, y1) this.A.IPointCollection.AddPoint this.A.IPoint Set this.A.IPoint = this.A.IScreenDisplay.DisplayTransformation.ToMapPoint(x1 + w, y1) this.A.IPointCollection.AddPoint this.A.IPoint Set this.A.IPoint = this.A.IScreenDisplay.DisplayTransformation.ToMapPoint(x1 + w, y1 + h) this.A.IPointCollection.AddPoint this.A.IPoint Set this.A.IPoint = this.A.IScreenDisplay.DisplayTransformation.ToMapPoint(x1, y1 + h) this.A.IPointCollection.AddPoint this.A.IPoint getPolygon.Close End Function '======================================================= ' getPolyline '======================================================= Public Function getPolyline(x, y) As IPolyline Dim h, w, x1, y1 Dim Text Set getPolyline = New Polyline Set this.A.IPointCollection = getPolyline Set this.A.IPoint = New Point h = 10 w = 10 x1 = x - (w / 2) y1 = y - (h / 2) Set this.A.IActiveView = this.A.IMxDocument.FocusMap Set this.A.IScreenDisplay = this.A.IActiveView.ScreenDisplay Set this.A.IPoint = this.A.IScreenDisplay.DisplayTransformation.ToMapPoint(x1, y1) this.A.IPointCollection.AddPoint this.A.IPoint Set this.A.IPoint = this.A.IScreenDisplay.DisplayTransformation.ToMapPoint(x1 + w, y1) this.A.IPointCollection.AddPoint this.A.IPoint Set this.A.IPoint = this.A.IScreenDisplay.DisplayTransformation.ToMapPoint(x1 + w, y1 + h) this.A.IPointCollection.AddPoint this.A.IPoint Set this.A.IPoint = this.A.IScreenDisplay.DisplayTransformation.ToMapPoint(x1, y1 + h) this.A.IPointCollection.AddPoint this.A.IPoint End Function '======================================================= ' DrawPolygon '======================================================= Public Function drawPolygon(IPolygon As IPolygon) Set this.A.IActiveView = this.A.IMxDocument.FocusMap Set this.A.IScreenDisplay = this.A.IActiveView.ScreenDisplay Set this.A.IFillSymbol = New simpleFillSymbol this.A.IFillSymbol.Color = this.Color.Esri("Tomato") this.A.IScreenDisplay.StartDrawing this.A.IScreenDisplay.hDC, esriNoScreenCache this.A.IScreenDisplay.SetSymbol this.A.IFillSymbol this.A.IScreenDisplay.drawPolygon IPolygon this.A.IScreenDisplay.FinishDrawing End Function '======================================================= ' DrawText '======================================================= Public Function drawText(Point, Text, Angle) Set this.A.ITextsymbol = New textSymbol Set this.A.IFontDisp = New StdFont this.A.IFontDisp.name = "Arial" ' some value is required this.A.IFontDisp.Size = 12 ' any value is required here this.A.IFontDisp.Underline = True this.A.ITextsymbol.Font = this.A.IFontDisp this.A.ITextsymbol.Size = 12 this.A.ITextsymbol.Angle = Angle this.A.ITextsymbol.RightToLeft = False this.A.ITextsymbol.VerticalAlignment = esriTextVerticalAlignment.esriTVABaseline this.A.ITextsymbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHAFull Set this.A.IActiveView = this.A.IMxDocument.FocusMap Set this.A.IScreenDisplay = this.A.IActiveView.ScreenDisplay this.A.IScreenDisplay.StartDrawing this.A.IScreenDisplay.hDC, esriNoScreenCache this.A.IScreenDisplay.SetSymbol this.A.ITextsymbol this.A.IScreenDisplay.drawText Point, Text this.A.IScreenDisplay.FinishDrawing End Function '======================================================= ' DrawTextScreen '======================================================= Public Function drawTextScreen(x, y, Text, Angle) Set this.A.ITextsymbol = New textSymbol Set this.A.IFontDisp = New StdFont this.A.IFontDisp.name = "Arial" ' some value is required this.A.IFontDisp.Size = 12 ' any value is required here this.A.IFontDisp.Underline = True this.A.ITextsymbol.Font = this.A.IFontDisp this.A.ITextsymbol.Size = 12 this.A.ITextsymbol.Angle = Angle this.A.ITextsymbol.RightToLeft = False this.A.ITextsymbol.VerticalAlignment = esriTextVerticalAlignment.esriTVABaseline this.A.ITextsymbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHAFull Set this.A.IActiveView = this.A.IMxDocument.FocusMap Set this.A.IScreenDisplay = this.A.IActiveView.ScreenDisplay Set this.A.IPoint = this.A.IScreenDisplay.DisplayTransformation.ToMapPoint(x, y) this.A.IScreenDisplay.StartDrawing this.A.IScreenDisplay.hDC, esriNoScreenCache this.A.IScreenDisplay.SetSymbol this.A.ITextsymbol this.A.IScreenDisplay.drawText this.A.IPoint, Text this.A.IScreenDisplay.FinishDrawing End Function '======================================================= ' DrawSymbol '======================================================= Public Function drawSymbol(x, y) Dim arrow As IArrowMarkerSymbol Set this.A.IArrowMarkerSymbol = New ArrowMarkerSymbol this.A.IArrowMarkerSymbol.Angle = 90 this.A.IArrowMarkerSymbol.Size = 10 this.A.IArrowMarkerSymbol.XOffset = 0 this.A.IArrowMarkerSymbol.YOffset = 0 this.A.IArrowMarkerSymbol.Length = 10 Set this.A.IActiveView = this.A.IMxDocument.FocusMap Set this.A.IScreenDisplay = this.A.IActiveView.ScreenDisplay Set this.A.IPoint = this.A.IScreenDisplay.DisplayTransformation.ToMapPoint(x, y) this.A.IScreenDisplay.StartDrawing this.A.IScreenDisplay.hDC, esriNoScreenCache this.A.IScreenDisplay.SetSymbol this.A.IArrowMarkerSymbol this.A.IScreenDisplay.DrawPoint this.A.IPoint this.A.IScreenDisplay.FinishDrawing End Function '======================================================= ' DrawPolyline '======================================================= Public Function drawPolyline(IPolyline As IPolyline) Dim arrow As IArrowMarkerSymbol Set this.A.ICartographicLineSymbol = New CartographicLineSymbol this.A.ICartographicLineSymbol.width = 1 this.A.ICartographicLineSymbol.Cap = esriLCSSquare this.A.ICartographicLineSymbol.Join = esriLJSMitre this.A.ICartographicLineSymbol.Color = this.Color.Esri("Blue") Set this.A.IActiveView = this.A.IMxDocument.FocusMap Set this.A.IScreenDisplay = this.A.IActiveView.ScreenDisplay Set this.A.IPoint = this.A.IScreenDisplay.DisplayTransformation.ToMapPoint(x, y) this.A.IScreenDisplay.StartDrawing this.A.IScreenDisplay.hDC, esriNoScreenCache this.A.IScreenDisplay.SetSymbol this.A.ICartographicLineSymbol this.A.IScreenDisplay.drawPolyline IPolyline this.A.IScreenDisplay.FinishDrawing End Function '======================================================= ' Cursor '======================================================= Public Property Let Cursor(ByVal Value As Variant) Set this.A.ImouseCursor = New MouseCursor this.A.ImouseCursor.SetCursor Value End Property