Using VBA Schematics Legacy Code in ArcGIS 10

945
7
07-18-2011 08:14 AM
CharlesScaife
New Contributor
Many of the interface names from ArcGIS 9.3 have been removed [i.e. those pertaining to the ngo engine] in the Schematics ArcObjects Library.  As a result, when I run my 9.3 code in ArcGIS 10 I get a compile error: "user-defined type not defined".  Is there an easy way to update the old ngo engine interface names to corresponding ones in ArcGIS 10?

Thanks
0 Kudos
7 Replies
EdgarBejarano
Occasional Contributor
I am not sure if there is an easy way to update the old ngo engine interface names to corresponding ones in ArcGIS 10, however, the below document touches up on NGO library removal and makes mention of some equivalent interfaces in version 10, with a comparison table:

Migrating schematic custom code to ArcGIS 10 > NGO library removal
---
http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#//000100000m29000000
0 Kudos
CharlesScaife
New Contributor
As I'm migrating my VBA Schematics code into one that is readable in ArcGIS 10, I've ran across a major speed bump.  In the following code I referenced the NGO library (which is no supported by 10) and I can't seem to find a suitable way to adapt the code.  What's most frustrating to work around is the "GetNgProject()" method.  Does anyone have insight on finding replacement method that is 10x compatible?


Public Function ngProjectFromSchDataset(ByVal pSchDataset As ISchematicDataset) As INgProject
[INDENT]Dim schProjMgr As ISchematicProjectMgr[/INDENT]
[INDENT]Set schProjMgr = New SchematicProjectMgr[/INDENT]
[INDENT]Set ngProjectFromSchDataset = schProjMgr.GetNgProject(pSchDataset)[/INDENT]
End Function
0 Kudos
RickAnderson
Occasional Contributor III
So first of all, everyone must realize that VBA is dead...  So if you are migrating code to 10, I would strongly suggest that you don't do it to just VBA.  Follow the new Add-In paradigm that uses .NET or you will end up migrating again when VBA is completely pulled out of ArcGIS. 

Secondly, there are a lot of schematic samples available in the desktop developer kit that show how to work with the api.  So just saying you need NgProject isn't descriptive enough, we need to know what you are actually trying to accomplish.  At 10, you can do most everything from the diagramclass or elementclass, but again, depends on what you are trying to accomplish.

So let us know what you are doing and I will try to help you through it.
0 Kudos
CharlesScaife
New Contributor
So first of all, everyone must realize that VBA is dead...  So if you are migrating code to 10, I would strongly suggest that you don't do it to just VBA.  Follow the new Add-In paradigm that uses .NET or you will end up migrating again when VBA is completely pulled out of ArcGIS. 

Secondly, there are a lot of schematic samples available in the desktop developer kit that show how to work with the api.  So just saying you need NgProject isn't descriptive enough, we need to know what you are actually trying to accomplish.  At 10, you can do most everything from the diagramclass or elementclass, but again, depends on what you are trying to accomplish.

So let us know what you are doing and I will try to help you through it.


None of the original VBA code was written by me, I'm merely trying to get it to run successfully in 10.  With few comments marked throughout the code it sometimes is difficult to read.  I can give you an example of what the previous programmer wrote, that I'm trying to translate.

Private Sub UserForm_Initialize()
[INDENT]Dim diagrams As INgDiagrams[/INDENT]
[INDENT]Dim diagram As INgDiagram[/INDENT]
[INDENT]Set diagrams = getDiagramsInDataFrame[/INDENT]
[INDENT]For Each diagram In diagrams[/INDENT]
[INDENT][INDENT]lstTarget.AddItem diagram.Name[/INDENT][/INDENT]
[INDENT][INDENT]cboSource.AddItem diagram.Name[/INDENT][/INDENT]
[INDENT]Next[/INDENT]
End Sub

Public Function getDiagramsInDataFrame() As INgDiagrams
[INDENT]Dim pDoc As IMxDocument[/INDENT]
[INDENT]Dim pMap As IMap[/INDENT]
[INDENT]Dim pLayer As ILayer[/INDENT]
[INDENT]Dim pLayers As IEnumLayer[/INDENT]
[INDENT]Dim schLayer As ISchematicLayer[/INDENT]
[INDENT]Dim schDiagram As ISchematicDiagram[/INDENT]
[INDENT]Dim i As Integer[/INDENT]   
[INDENT]Set pDoc = ThisDocument[/INDENT]
[INDENT]Set pMap = pDoc.FocusMap[/INDENT]
[INDENT]Set getDiagramsInDataFrame = New NgDiagrams[/INDENT]
[INDENT]i = 0[/INDENT]
[INDENT]Set pLayers = pMap.layers[/INDENT]
[INDENT]pLayers.Reset[/INDENT]
[INDENT]Set pLayer = pLayers.Next[/INDENT]
[INDENT]Do While Not pLayer Is Nothing[/INDENT]
[INDENT][INDENT]If TypeOf pLayer Is ISchematicLayer Then[/INDENT][/INDENT]
[INDENT][INDENT][INDENT]Set schLayer = pLayer[/INDENT][/INDENT][/INDENT]
[INDENT][INDENT][INDENT]getDiagramsInDataFrame.Add ngDiagramFromSchDiagram(schLayer.SchematicDiagram)[/INDENT][/INDENT][/INDENT]
[INDENT][INDENT]End If[/INDENT][/INDENT]
[INDENT][INDENT]Set pLayer = pLayers.Next[/INDENT][/INDENT]
[INDENT]Loop[/INDENT]
End Function

Public Function ngDiagramFromSchDiagram(ByVal schDiagram As ISchematicDiagram) As INgDiagram
[INDENT]Dim schDataset As ISchematicDataset[/INDENT]
[INDENT]Dim pObjectClass As IObjectClass[/INDENT]
[INDENT]Set schDataset = schDiagram.SchematicDiagramClass.SchematicDataset[/INDENT]
[INDENT]Set pObjectClass = schDiagram.SchematicDiagramClass[/INDENT]
[INDENT]Set ngDiagramFromSchDiagram = ngProjectFromSchDataset(schDataset).GetDiagramType(pObjectClass.AliasName).GetDiagram(schDiagram.Name)[/INDENT]
End Function

Public Function ngProjectFromSchDataset(ByVal pSchDataset As ISchematicDataset) As INgProject
[INDENT]Dim schProjMgr As ISchematicProjectMgr[/INDENT]
[INDENT]Set schProjMgr = New SchematicProjectMgr[/INDENT]
[INDENT]Set ngProjectFromSchDataset = schProjMgr.getNgProject(pSchDataset)[/INDENT]
End Function

Public Function getNgProject(ByVal doc As IMxDocument) As INgProject
[INDENT]Dim pMap As IMap[/INDENT]
[INDENT]Dim pLayer As ILayer[/INDENT]
[INDENT]Dim pSchematicLayer As ISchematicLayer[/INDENT]
[INDENT]Dim pDiagram As ISchematicDiagram[/INDENT]
[INDENT]Dim pDiagramClass As ISchematicDiagramClass[/INDENT]
[INDENT]Dim pSchDataset As ISchematicDataset[/INDENT]
[INDENT]Dim pSchProjMgr As ISchematicProjectMgr[/INDENT]
[INDENT]Dim pNgProj As INgProject[/INDENT]
[INDENT]Dim i As Integer[/INDENT]
[INDENT]Dim schematicOpen As Boolean[/INDENT]
[INDENT]Set pMap = doc.FocusMap 'active data frame[/INDENT]
[INDENT]For i = 0 To pMap.LayerCount - 1[/INDENT]
[INDENT][INDENT]If TypeOf pMap.layer(i) Is ISchematicLayer Then[/INDENT][/INDENT]
[INDENT][INDENT][INDENT]Set pSchematicLayer = pMap.layer(i)[/INDENT][/INDENT][/INDENT]
[INDENT][INDENT][INDENT]schematicOpen = True[/INDENT][/INDENT][/INDENT]
[INDENT][INDENT][INDENT]Exit For[/INDENT][/INDENT][/INDENT]
[INDENT][INDENT]End If[/INDENT][/INDENT]
[INDENT]Next i[/INDENT]
[INDENT]If schematicOpen <> True Then[/INDENT]
[INDENT][INDENT]MsgBox "There are no schematics here!"[/INDENT][/INDENT]
[INDENT][INDENT]Exit Function[/INDENT][/INDENT]
[INDENT]End If[/INDENT]
[INDENT]Set pDiagram = pSchematicLayer.SchematicDiagram [/INDENT]
[INDENT]Set pDiagramClass = pDiagram.SchematicDiagramClass [/INDENT]
[INDENT]Set pSchDataset = pDiagramClass.SchematicDataset [/INDENT]
[INDENT]Set pSchProjMgr = New SchematicProjectMgr [/INDENT]
[INDENT]Set getNgProject = pSchProjMgr.getNgProject(pSchDataset)[/INDENT]
End Function
0 Kudos
RickAnderson
Occasional Contributor III
You just really don't need NgProject anymore.  The only place it really looks like this code was using it was

Set ngDiagramFromSchDiagram = ngProjectFromSchDataset(schDataset).GetDiagramType(pObjectClass.AliasName).GetDiagram(schDiagram.Name)

Now you just get the schematic dataset, then get a diagramclasscontainer and set it to the schematic dataset.  Once you have the diagramclasscontainer, you get the specific diagram class (used to be called diagram type) and from there get your diagram.

If your schematicdataset variable is named m_pSDS, then the code would look like this:
ISchematicDiagramClassContainer pDCC = (ISchematicDiagramClassContainer)m_pSDS;
ISchematicDiagramClass pDC = PDCC.GetSchematicDiagramClass(somename);
ISchematicDiagram pDiagram = pDC.SchematicDiagramByName(somename);
0 Kudos
CharlesScaife
New Contributor
...but how would you go about replacing the usages of INgDiagrams and INgDiagram because they too are not supported in ArcGIS 10.





email: scaife.charles@gmail.com
0 Kudos
RickAnderson
Occasional Contributor III
Again this depends on what you need to do.  Make sure to read and understand the document that edga6340 left a link to in his post.  Schematics has always had 2 levels basically. Prior to 10, there was 'Schematic' and 'Ng'.  Ng was just a prefix but it was dealing with things once they are 'in-memory'.  So in 10, that was cleaned up with proper naming.  So, for the most part things that used to be Ng..., are now just SchematicInMemory...
0 Kudos