Exception while creating the schematic diagram for selected features?

2902
2
Jump to solution
07-19-2014 11:01 PM
SreerajanParamanandham1
New Contributor II

I am trying to generate schematic using the below code, this code is working fine to generate schematic for logical data. But the same code is raising exception "while creating the schematic for selected featues in map". I have used the"Geo initial position" layou.

Please help me to resolve this isse.

 

Type factoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.AccessWorkspaceFactory");

IWorkspaceFactory sWorkspaceFactory = (IWorkspaceFactory)Activator.CreateInstance(factoryType);

IWorkspace sWorkspace = sWorkspaceFactory.OpenFromFile(@"xxxxxx.mdb", 0);

ISchematicWorkspaceFactory oSchematicWorkspaceFactory = new SchematicWorkspaceFactory();

ISchematicWorkspace sSchematicWorkspace = oSchematicWorkspaceFactory.Open(sWorkspace);

ISchematicDataset sSchematicDataset = sSchematicWorkspace.get_SchematicDatasetByName("TestDataset");

ISchematicDiagramClassContainer oSchDiagramClassContainer = (ISchematicDiagramClassContainer)sSchematicDataset;

ISchematicDiagramClass sSchematicDiagramClass = oSchDiagramClassContainer.GetSchematicDiagramClass("TestTemplate");

ISchematicBuilder sSchematicBuilder;

ISchematicStandardBuilder sSchematicStandardBuilder;

Type.GetTypeFromProgID("esriSchematic.SchematicStandardBuilderContext");

Activator.CreateInstance(objClassType);

ISchematicBuilderContext sSchematicBuilderCtxt = (ISchematicBuilderContext)objApp_Late;

ISchematicBuilder)sSchematicDiagramClass;

ISchematicStandardBuilder)sSchematicDiagramClass.SchematicBuilder;

sSchematicStandardBuilder.InitializeLinksVertices = false;

sSchematicStandardBuilder.AutoCreateElementClasses = true;

ITrackCancel oTrackCancel = new TrackCancelClass();

ISchematicDiagramContainer)sSchematicDataset;

objSchemaDiag = sSchematicBuilder.GenerateDiagram("xxxxx", pSchematicDiagramContainer, null, sSchematicBuilderCtxt, oTrackCancel); //Exception raised

 

Exception in Generate diagram

COMException was CaughtError

HRESULT E_FAIL has been returned from a call to a COM component.

 

Regareds

Sreerajan P

0 Kudos
1 Solution

Accepted Solutions
Anne-YvonneBlin
New Contributor III

It looks like you didn't initialize the ISchematicStandardBuilderContext with the selected features set in the map.

#region"Generate A Diagram From A Map Selection"

// ArcGIS Snippet Title:

// Generate A Diagram From A Map Selection

//

// Long Description:

// Generate a diagram from features selected in a geographic map

//

// Add the following references to the project:

// ESRI.ArcGIS.Carto

// ESRI.ArcGIS.Schematic

//

// Intended ArcGIS Products for this snippet:

// ArcGIS Desktop (Standard, Advanced)

// ArcGIS Engine

//

// Applicable ArcGIS Product Versions:

// 10.0

// 10.1

//

// Required ArcGIS Extensions:

// ArcGIS Schematics

//

// Notes:

// This snippet is intended to be inserted at the base level of a Class.

// It is not intended to be nested within an existing Method.

//

/// <summary>

/// Generate a diagram from features selected in a geographic map

/// </summary>

/// <param name="pMap">Geographic map containing the input selected GIS features</param>

/// <param name="schemDiagClass">SchematicDiagramClass; that is, diagram template on which the generated diagram is based</param>

/// <param name="schemDiagramContainer">SchematicDiagramContainer where the generated diagram will be stored</param>

/// <param name="DiagramName">Name for the generated diagram</param>

/// <returns>ESRI.ArcGIS.Schematic.ISchematicDiagram</returns>

///<remarks></remarks>

public ESRI.ArcGIS.Schematic.ISchematicDiagram GenerateDiagramFromMap(ESRI.ArcGIS.Carto.IMap pMap, ESRI.ArcGIS.Schematic.ISchematicDiagramClass schemDiagClass, ESRI.ArcGIS.Schematic.ISchematicDiagramContainer schemDiagramContainer, string DiagramName)

{

  // if DiagramName is empty exit

  if (DiagramName.Length == 0) return null;

    // cast SchematicDiagramClass into ISchematicBuilder

  ESRI.ArcGIS.Schematic.ISchematicBuilder schBuilder = (ESRI.ArcGIS.Schematic.ISchematicBuilder)schemDiagClass;

    // create the ISchematicStandardBuilderContext

  Type objectType = Type.GetTypeFromProgID("esriSchematic.SchematicStandardBuilderContext");

  // if objectType is null, the BuilderContext cannot be created, then exit

  if (objectType == null) return null;

  ESRI.ArcGIS.Schematic.ISchematicStandardBuilderContext schBuilderCtxt;

  schBuilderCtxt = Activator.CreateInstance(objectType) as ESRI.ArcGIS.Schematic.ISchematicStandardBuilderContext;

    // get the selected features in the map

  ESRI.ArcGIS.Geodatabase.IEnumFeature enumFeature = (ESRI.ArcGIS.Geodatabase.IEnumFeature)pMap.FeatureSelection;

    // initialize the ISchematicStandardBuilderContext with the selection set

  schBuilderCtxt.InitialObjects = new EnumSchematicObject(enumFeature);

  // generate the schematic diagram

    ESRI.ArcGIS.Schematic.ISchematicDiagram GeneratedDiagram = schBuilder.GenerateDiagram(DiagramName, schemDiagramContainer, null, (ESRI.ArcGIS.Schematic.ISchematicBuilderContext)schBuilderCtxt, null);

    return GeneratedDiagram;

}

public class EnumSchematicObject : ESRI.ArcGIS.Geodatabase.IEnumObject

{

  private ESRI.ArcGIS.Geodatabase.IEnumFeature m_pIEnumFeature;

  public EnumSchematicObject(ESRI.ArcGIS.Geodatabase.IEnumFeature pEnumFeature)

  {

        m_pIEnumFeature = pEnumFeature;

  }

  public ESRI.ArcGIS.Geodatabase.IObject Next()

  {

  if (m_pIEnumFeature != null)

  return (ESRI.ArcGIS.Geodatabase.IObject)m_pIEnumFeature.Next();

  else

  return null;

  }

  public void Reset()

  {

  if (m_pIEnumFeature != null) m_pIEnumFeature.Reset();

  }

}

#endregion

View solution in original post

2 Replies
Anne-YvonneBlin
New Contributor III

It looks like you didn't initialize the ISchematicStandardBuilderContext with the selected features set in the map.

#region"Generate A Diagram From A Map Selection"

// ArcGIS Snippet Title:

// Generate A Diagram From A Map Selection

//

// Long Description:

// Generate a diagram from features selected in a geographic map

//

// Add the following references to the project:

// ESRI.ArcGIS.Carto

// ESRI.ArcGIS.Schematic

//

// Intended ArcGIS Products for this snippet:

// ArcGIS Desktop (Standard, Advanced)

// ArcGIS Engine

//

// Applicable ArcGIS Product Versions:

// 10.0

// 10.1

//

// Required ArcGIS Extensions:

// ArcGIS Schematics

//

// Notes:

// This snippet is intended to be inserted at the base level of a Class.

// It is not intended to be nested within an existing Method.

//

/// <summary>

/// Generate a diagram from features selected in a geographic map

/// </summary>

/// <param name="pMap">Geographic map containing the input selected GIS features</param>

/// <param name="schemDiagClass">SchematicDiagramClass; that is, diagram template on which the generated diagram is based</param>

/// <param name="schemDiagramContainer">SchematicDiagramContainer where the generated diagram will be stored</param>

/// <param name="DiagramName">Name for the generated diagram</param>

/// <returns>ESRI.ArcGIS.Schematic.ISchematicDiagram</returns>

///<remarks></remarks>

public ESRI.ArcGIS.Schematic.ISchematicDiagram GenerateDiagramFromMap(ESRI.ArcGIS.Carto.IMap pMap, ESRI.ArcGIS.Schematic.ISchematicDiagramClass schemDiagClass, ESRI.ArcGIS.Schematic.ISchematicDiagramContainer schemDiagramContainer, string DiagramName)

{

  // if DiagramName is empty exit

  if (DiagramName.Length == 0) return null;

    // cast SchematicDiagramClass into ISchematicBuilder

  ESRI.ArcGIS.Schematic.ISchematicBuilder schBuilder = (ESRI.ArcGIS.Schematic.ISchematicBuilder)schemDiagClass;

    // create the ISchematicStandardBuilderContext

  Type objectType = Type.GetTypeFromProgID("esriSchematic.SchematicStandardBuilderContext");

  // if objectType is null, the BuilderContext cannot be created, then exit

  if (objectType == null) return null;

  ESRI.ArcGIS.Schematic.ISchematicStandardBuilderContext schBuilderCtxt;

  schBuilderCtxt = Activator.CreateInstance(objectType) as ESRI.ArcGIS.Schematic.ISchematicStandardBuilderContext;

    // get the selected features in the map

  ESRI.ArcGIS.Geodatabase.IEnumFeature enumFeature = (ESRI.ArcGIS.Geodatabase.IEnumFeature)pMap.FeatureSelection;

    // initialize the ISchematicStandardBuilderContext with the selection set

  schBuilderCtxt.InitialObjects = new EnumSchematicObject(enumFeature);

  // generate the schematic diagram

    ESRI.ArcGIS.Schematic.ISchematicDiagram GeneratedDiagram = schBuilder.GenerateDiagram(DiagramName, schemDiagramContainer, null, (ESRI.ArcGIS.Schematic.ISchematicBuilderContext)schBuilderCtxt, null);

    return GeneratedDiagram;

}

public class EnumSchematicObject : ESRI.ArcGIS.Geodatabase.IEnumObject

{

  private ESRI.ArcGIS.Geodatabase.IEnumFeature m_pIEnumFeature;

  public EnumSchematicObject(ESRI.ArcGIS.Geodatabase.IEnumFeature pEnumFeature)

  {

        m_pIEnumFeature = pEnumFeature;

  }

  public ESRI.ArcGIS.Geodatabase.IObject Next()

  {

  if (m_pIEnumFeature != null)

  return (ESRI.ArcGIS.Geodatabase.IObject)m_pIEnumFeature.Next();

  else

  return null;

  }

  public void Reset()

  {

  if (m_pIEnumFeature != null) m_pIEnumFeature.Reset();

  }

}

#endregion

SreerajanParamanandham1
New Contributor II

Thanks you very much Anne-Yvonne Blin, This is working fine .