![]() |
This document is archived and information here might be outdated. Recommended version. |
| ArcObjects Help for .NET developers > ESRI.ArcGIS.Snippets > Snippets > Create A Standard Builder Schematic Diagram Class From Scratch Snippet (ArcObjects .NET 10.4 SDK) |
This sample code creates a schematic diagram template based on the standard builder to generate diagrams from any network feature selected in a map or any record selected in an object table.
using System;
using System.Collections.Generic;
using System.Text;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Schematic;
using ESRI.ArcGIS.Framework;
using ESRI.ArcGIS.Geodatabase;
namespace CodeSnippetCS
{
public class StandardDiagramClass
{
#region Create Standard builder diagram template
// This sample code creates a schematic diagram template based on the standard builder to generate diagrams from any network feature selected in a map or any record selected in an object table.
const string DATASET_NAME="MyStandardBuilderDataset";
const string DIAGRAM_TEMPLATE_NAME="MyDiagramClass";
public ESRI.ArcGIS.Schematic.ISchematicDataset CreateStandardSchematicDataset(ESRI.ArcGIS.Geodatabase.IWorkspace esriWorkspace)
{
ESRI.ArcGIS.Schematic.ISchematicWorkspace schWorkspace=null;
ISchematicDataset schData=null;
//-- STEP#1 -- Opening the ISchematicWorkspace related to the input IWorkspace
Type objectType=Type.GetTypeFromProgID("esriSchematic.SchematicWorkspaceFactory");
ESRI.ArcGIS.Schematic.ISchematicWorkspaceFactory schWorkspaceFct;
schWorkspaceFct=Activator.CreateInstance(objectType) as ESRI.ArcGIS.Schematic.ISchematicWorkspaceFactory;
if (esriWorkspace != null) schWorkspace=schWorkspaceFct.Open(esriWorkspace);
//-- STEP#2 -- Creating the new ISchematicDataset
// verify that the ISchematicDataset to create doesn't already exist in the input IWorkspace
schData=schWorkspace.get_SchematicDatasetByName(DATASET_NAME);
// if it already exists, exit
if (schData != null) return schData;
// create the new ISchematicDataset
try
{
schData=schWorkspace.CreateSchematicDataset(DATASET_NAME, "");
schData.DesignMode=true;
}
catch
{
// if the ISchematicDataset cannot be created, the process stops
return null;
}
//-- STEP#3 -- Creating the ISchematicStandardBuilder that will be assigned afterwards to the schematic diagram template
objectType=Type.GetTypeFromProgID("esriSchematic.SchematicStandardBuilder");
ESRI.ArcGIS.Schematic.ISchematicStandardBuilder pSchStandardBuilder;
if (objectType == null) return null;
pSchStandardBuilder=Activator.CreateInstance(objectType) as ESRI.ArcGIS.Schematic.ISchematicStandardBuilder;
// if the ISchematicStandardBuilder is Nothing, exit
if (pSchStandardBuilder == null) return null;
pSchStandardBuilder.AddConnectedNodes=true;
pSchStandardBuilder.InitializeLinksVertices=true;
// the builder is configured to work with the AutoCreateElementClasses mode enabled
pSchStandardBuilder.AutoCreateElementClasses=true;
// this makes that the builder will automatically create schematic feature classes that could be missing from the schematic diagram template when it operates
ESRI.ArcGIS.Schematic.ISchematicBuilder pSchBuilder=(ISchematicBuilder)pSchStandardBuilder;
//-- STEP#4 -- Creating the ISchematicDiagramClass
ESRI.ArcGIS.Schematic.ISchematicDiagramClass schDiagClass=null;
try
{
schDiagClass=schData.CreateSchematicDiagramClass(DIAGRAM_TEMPLATE_NAME);
}
catch { }
schDiagClass.SchematicBuilder=pSchBuilder;
//-- STEP#5 -- Configuring some diagram class parameters
schDiagClass.SchematicDataSource=schData.DefaultSchematicDataSource;
schDiagClass.ExternalQueryEvaluationMode=esriSchematicExternalQueryEvaluationMode.esriSchematicNoQuery;
//-- STEP#6 -- Saving the schematic dataset and exit the design mode
schData.Save(ESRI.ArcGIS.esriSystem.esriArcGISVersion.esriArcGISVersionCurrent, false);
schData.DesignMode=false;
return schData;
}
#endregion
}
}
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports ESRI.ArcGIS.Carto
Imports ESRI.ArcGIS.Geometry
Imports ESRI.ArcGIS.esriSystem
Imports ESRI.ArcGIS.Schematic
Imports ESRI.ArcGIS.Framework
Imports ESRI.ArcGIS.Geodatabase
Public Class StandardDiagramClass
#Region "Create Standard builder diagram template"
'This sample code creates a schematic diagram template based on the standard builder to generate diagrams from any network feature selected in a map or any record selected in an object table.
Const DATASET_NAME As String="MyStandardBuilderDataset"
Const DIAGRAM_TEMPLATE_NAME As String="MyDiagramClass"
Public Function CreateStandardSchematicDataset(ByVal esriWorkspace As ESRI.ArcGIS.Geodatabase.IWorkspace) As ESRI.ArcGIS.Schematic.ISchematicDataset
Dim schWorkspace As ESRI.ArcGIS.Schematic.ISchematicWorkspace=Nothing
Dim schData As ESRI.ArcGIS.Schematic.ISchematicDataset=Nothing
'-- STEP#1 -- Opening the ISchematicWorkspace related to the input IWorkspace
Dim objectType As Type=Type.GetTypeFromProgID("esriSchematic.SchematicWorkspaceFactory")
Dim schWorkspaceFct As ESRI.ArcGIS.Schematic.ISchematicWorkspaceFactory
schWorkspaceFct=TryCast(Activator.CreateInstance(objectType), ISchematicWorkspaceFactory)
If (esriWorkspace IsNot Nothing) Then schWorkspace=schWorkspaceFct.Open(esriWorkspace)
'-- STEP#2 -- Creating the new ISchematicDataset
' verify that the ISchematicDataset to create doesn't already exist in the input IWorkspace
schData=schWorkspace.SchematicDatasetByName(DATASET_NAME)
' if it already exists, exit
If (schData IsNot Nothing) Then Return schData
' create the new ISchematicDataset
Try
schData=schWorkspace.CreateSchematicDataset(DATASET_NAME, "")
schData.DesignMode=True
Catch
' if the ISchematicDataset cannot be created, the process stops
Return Nothing
End Try
'-- STEP#3 -- Creating the ISchematicStandardBuilder that will be assigned afterwards to the schematic diagram template
objectType=Type.GetTypeFromProgID("esriSchematic.SchematicStandardBuilder")
Dim pSchStandardBuilder As ESRI.ArcGIS.Schematic.ISchematicStandardBuilder
If (objectType Is Nothing) Then Return Nothing
pSchStandardBuilder=TryCast(Activator.CreateInstance(objectType), ESRI.ArcGIS.Schematic.ISchematicStandardBuilder)
' if the ISchematicStandardBuilder is Nothing, exit
If (pSchStandardBuilder Is Nothing) Then Return Nothing
pSchStandardBuilder.AddConnectedNodes=True
pSchStandardBuilder.InitializeLinksVertices=True
' the builder is configured to work with the AutoCreateElementClasses mode enabled
pSchStandardBuilder.AutoCreateElementClasses=True
' this makes that the builder will automatically create schematic feature classes that could be missing from the schematic diagram template when it operates
Dim pSchBuilder As ESRI.ArcGIS.Schematic.ISchematicBuilder=TryCast(pSchStandardBuilder, ISchematicBuilder)
'-- STEP#4 -- Creating the ISchematicDiagramClass
Dim schDiagClass As ESRI.ArcGIS.Schematic.ISchematicDiagramClass=Nothing
Try
schDiagClass=schData.CreateSchematicDiagramClass(DIAGRAM_TEMPLATE_NAME)
Catch
End Try
schDiagClass.SchematicBuilder=pSchBuilder
'-- STEP#5 -- Configuring some diagram class parameters
schDiagClass.SchematicDataSource=schData.DefaultSchematicDataSource
schDiagClass.ExternalQueryEvaluationMode=esriSchematicExternalQueryEvaluationMode.esriSchematicNoQuery
'-- STEP#6 -- Saving the schematic dataset and exit the design mode
schData.Save(ESRI.ArcGIS.esriSystem.esriArcGISVersion.esriArcGISVersionCurrent, False)
schData.DesignMode=False
Return schData
End Function
#End Region
End Class