Avenue to VBA

3392
7
03-15-2011 10:35 PM
PriyankaMehta
New Contributor
Hi all,

I have never used Avenue scripts. In fact when I was going through forum I realized it was about in the year 2000 that the change from .ave to vba had started taking place. That time I was probably in high school 😛

Anyways,, is there any documentation that gives information on library changes from avenue to vba.

I basically want to convert the following avenue script to vba.. Can anyone please help me with that :


tView = av.GetActiveDoc

tdisp = av.GetActiveDoc.getdisplay

atheme = tView.GetThemes.get(0)

tGrid = atheme.GetGrid
CellSize = tGrid.GetCellSize
theGridExtent = tGrid.GetExtent

top = thegridextent.gettop
bottom = thegridextent.getbottom
left = thegridextent.getleft
right = thegridextent.getright


userPoint = tdisp.ReturnUserPoint
x = userPoint.GetX
y = userPoint.GetY

userCellValue = tGrid.CellValue(userPoint,Prj.MakeNull)



coordfile = FileDialog.Put("xyz.dbf".AsFileName,"*.*","File")
theVtab = Vtab.MakeNew(coordfile,dbase)
coortable = Table.Make(theVtab)
coortable.SetName("High Points Blocking View")

PntType = Field.Make("Coord Type",#FIELD_CHAR,12,0)
theAzmth = Field.Make("Azimuth",#FIELD_DECIMAL,10,3)
Pntx = Field.Make("x",#FIELD_DECIMAL,25,4)
Pnty = Field.Make("y",#FIELD_DECIMAL,25,4)
theAngle = Field.Make("View Angle",#FIELD_DECIMAL,25,4)
theVtab.AddFields({PntType,theAzmth,Pntx,Pnty,theAngle})

rec = theVtab.AddRecord

theVtab.SetValue(PntType,rec,"User")
theVtab.SetValue(Pntx,rec,x)
theVtab.SetValue(Pnty,rec,y)



av.ShowStopButton

for each azimuth in 0..359
  tmpPoint = Point.MakeNull
  oldCellValue = userCellValue
  distance = CellSize
  azimuthR = azimuth.AsRadians
  x2 = x
  y2 = y
  higherPt = false
  
     While ( (x2 < right) and (x2 > left) and (y2 < top) and (y2 > bottom))
        
        a = distance * azimuthR.sin
        b = distance * azimuthR.cos
        x2 = x + a
        y2 = y + b
                
        if ( (x2 < right) and (x2 > left) and (y2 < top) and (y2 > bottom)) then
          tmpPoint.SetX(x2)
          tmpPoint.SetY(y2)
          NewCellValue = tGrid.CellValue(tmpPoint,Prj.MakeNull)
          x3 = x2
          y3 = y2
          
          if ( NewCellValue > OldCellValue) then
             OldCellValue = NewCellValue
             x4 = x3
             y4 = y3
             higherPt = true
          end
        end
        distance = distance + CellSize
         
        doMore = av.SetWorkingStatus
          if (not doMore) then
            exit
          end
     end
    
    rec = theVtab.AddRecord
    theVtab.SetValue(PntType,rec,"Calculated")
    theVtab.SetValue(theAzmth,rec,azimuth)
        
    if (higherPt = true) then
      HowFar = ( ((x - x4)*(x - x4)) + ((y - y4)*(y-y4))).sqrt
      height = NewCellValue - userCellValue
      hyp = ( (HowFar*HowFar) + (height*height)).sqrt
      theVtab.SetValue(Pntx,rec,x4)
      theVtab.SetValue(Pnty,rec,y4)
      theVtab.SetValue(theAngle,rec,HowFar/hyp)
    else
      theVtab.SetValue(Pntx,rec,x3)
      theVtab.SetValue(Pnty,rec,y3)
      theVtab.SetValue(theAngle,rec,1)
    end
     
end
av.ClearWorkingStatus
total = 0
for each rec in theVtab
  total = total + theVtab.ReturnValue(theAngle,rec)
end
total = (total/360) * 100
Msgbox.Info("The sky seen index is " + total.asString,"INFO")




Thanks !

Priyanka
0 Kudos
7 Replies
AlexanderGray
Occasional Contributor III
All the libraries have changed between Avenue and ArcObjects, it is a complete re-write.  You best bet is probably to figure out what the Avenue code does, write pseudo-code and rewrite it with ArcObjects.  Avenue is a proprietary esri language that works with ArcView GIS 3.x.  VBA is a microsoft language which esri provides to work with the ArcGIS programming API called ArcObjects.  So the language has changed and also the application you program against.  There used to be a course on migrating avenue to vba.  I haven't seen it for years but you might be able to get your hands on some of the course documents. 

You should also note that VBA is planned to be deprecated in the near future too so you might be converting all your programs to something that will be need reconverting soon.
0 Kudos
PriyankaMehta
New Contributor
Thanks Alexander

I tried using the avenue script on arcview(3.1) and it gives me an error on the second line itself
tdisp = av.GetActiveDoc.getdisplay

Now this might be a line as basic as
Set pMap = pMxDocument.ActiveView (This is what I am assuming)

but I don't know how to rectify it in avenue.


Right now I am trying to convert the avenue code to VBA
like where it says

CellSize = tGrid.GetCellSize

so there I have used IRasterAnalysisEnvironment

pRAEnv.GetCellSize esriRasterEnvMaxOf, cellSize
    Debug.Print "Cellsize: " & cellSize




but I got stuck pretty much in the beginning itself

Avenue says :

for each azimuth in 0..359
----------
-------

loop


It is trying to look at each grid pixel from 0 to 360 degrees starting from the user defined point.
And then it selects the highest elevation on that azimuth between the user point and the edge of the grid


Any ideas on how to do it in VBA would be much appreaciated


Regards,
Priyanka
0 Kudos
AlexanderGray
Occasional Contributor III
Ok, I don't think IRasterAnalysisEnvironment is going to be much help.
The activeview will be a map as long as you are not in page layout view so that might not always work.  The IMxDocument.FocusMap will always be a map.   Next is to get the layer that is the raster from the map, in avenue that is called a theme.  The layer returned should be a IRasterLayer.  The IRasterLayer has a raster property that returns an IRaster, that used to be a grid.   A raster class has many properties that allow you to get the cell size, the value at a point, a pixelblock (neighbourhood.)
http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#/RasterClass_Class/001q00...
0 Kudos
PriyankaMehta
New Contributor
Thanks again Alexander !

Basically, the beginning part I figured it quite much by the evening..

Its actually the azimuth settings that I am not getting..

How to look at the grid pixels at particular azimuths only..

The avenue script has a for loop and azimuth that looks through 0 to 360.
I am not being able to find a way to do that in Arcobjects..
0 Kudos
PriyankaMehta
New Contributor
figured out that too 🙂

will update my vba code once my task is complete


thanks,
Priyanka
0 Kudos
MichaelRobb
Occasional Contributor III
figured out that too 🙂

will update my vba code once my task is complete


thanks,
Priyanka


You may want to consider recompiling in something other than VBA if you plan on continuing along with Arc Upgrades, as this will be just as expired as Avenue in due time.  There is no further VBA support when arc10.1 comes out.  This is stated on many release documents.
Just saying, if you are going to invest a bunch of time migrating things over, better look at the pros and cons of something that will not work in a few months with the latest release.

ArcGIS 10.0 is the last release of Microsoft Visual Basic for Applications (VBA); we will no longer support VBA beyond the ArcGIS 10.0 release. Esri strongly recommends that no further development occur on this platform. Beyond ArcGIS 10.0, Esri will no longer be able to support VBA as a development platform. Users who have custom functionality built using VBA should actively plan strategies to rewrite their applications using a supported development language such as Python, VB.NET, or C# so their applications continue to be operational and supported in future releases of ArcGIS.'

ref:
http://downloads2.esri.com/support/TechArticles/ArcGIS10and101Deprecation_Plan.pdf
0 Kudos
PriyankaMehta
New Contributor
hmm... thats bad news for me !!
i guess its probably time to learn a new language to customize stuff

Thanks
Priyanka
0 Kudos