ArcGIS Developer Help  (EditorExt)    

INetworkAnalysisExtWeights Example

[Visual Basic 6.0]
 'This example demonstrates how to use the properties and methods on the INetworkAnalysisExtWeights interface.
 'g_pApplication is a variable of type IApplication holding a valid reference to the ArcMap application
 'SDE_CONNECTION_FILE is a string constant containing the path to an SDE connection file
 'FEATUREDATASET1_NAME ia a string constants containing a feature dataset name
 'GEOMETRICNETWORK1_NAME is a string constants containing a geometric network name
   
   Dim pNetworkAnalysisExtWeights As esriEditorExt.INetworkAnalysisExtWeights
   Dim pUID As New esriSystem.UID
   Dim pNetworkAnalysisExt As esriEditorExt.INetworkAnalysisExt
   Dim pWorkspaceFactory As esriGeoDatabase.IWorkspaceFactory
   Dim pFeatureWorkspace As esriGeoDatabase.IFeatureWorkspace
   Dim pNetworkCollection As esriGeoDatabase.INetworkCollection
   Dim pGeometricNetwork As esriGeoDatabase.IGeometricNetwork
   Dim pNetSchema As esriGeoDatabase.INetSchema
   Dim pNetWeight As esriGeoDatabase.INetWeight
   Dim strWeightName As String
   Dim lngWeightCount As Long
   Dim lngNetworkCount As Long
   Dim i As Long
   
   'obtain a reference to the interface by querying the application for the Utility Network Analysis extension
   pUID = "esriEditorExt.UtilityNetworkAnalysisExt"
   Set pNetworkAnalysisExtWeights = g_pApplication.FindExtensionByCLSID(pUID)
 
   'add a geometric network to the extension
   'create a new SDE workspace factory
   Set pWorkspaceFactory = New SdeWorkspaceFactory
   'create a feature workspace using the specified SDE connection file
   Set pFeatureWorkspace = pWorkspaceFactory.OpenFromFile(SDE_CONNECTION_FILE, 0)
   'get a reference to the INetworkCollection interface of the feature dataset
   Set pNetworkCollection = pFeatureWorkspace.OpenFeatureDataset(FEATUREDATASET1_NAME)
   'get a reference to the geometric network by specifying its name
   Set pGeometricNetwork = pNetworkCollection.GeometricNetworkByName(GEOMETRICNETWORK1_NAME)
   'add the network to the extension
   Set pNetworkAnalysisExt = pNetworkAnalysisExtWeights
   pNetworkAnalysisExt.AddNetwork pGeometricNetwork
   
   'QI for the INetSchema interface on the current network
   Set pNetSchema = pGeometricNetwork.Network
   
   With pNetworkAnalysisExtWeights
   
     'set the junction weight to use using the JunctionWeightName property
     lngWeightCount = pNetSchema.WeightCount
     If lngWeightCount = 0 Then Exit Sub
     Set pNetWeight = pNetSchema.Weight(0)
     .JunctionWeightName = pNetWeight.WeightName
     
     'get the weight name using the JunctionWeightName property
     strWeightName = .JunctionWeightName
     
     'set the from-to weight to use using the FromToWeightName property
     .FromToEdgeWeightName = pNetWeight.WeightName
     
     'get the from-to weight name using the FromToWeightName property
     strWeightName = .FromToEdgeWeightName
     
     'set the to-from weight to use using the ToFromWeightName property
     .ToFromEdgeWeightName = pNetWeight.WeightName
     
     'get the to-from weight name using the ToFromWeightName property
     strWeightName = .ToFromEdgeWeightName
     
   End With
   
   'remove all of the networks from the extension
   lngNetworkCount = pNetworkAnalysisExt.NetworkCount
   For i = 0 To lngNetworkCount - 1
     Set pGeometricNetwork = pNetworkAnalysisExt.CurrentNetwork
     pNetworkAnalysisExt.DeleteNetwork pGeometricNetwork
   Next i
   
  
 

[Visual Basic .NET, C#, C++]
No example is available for Visual Basic .NET, C#, or C++. To view a Visual Basic 6.0 example, click the Language Filter button Language Filter in the upper-left corner of the page.