How to create schematic attribute as associated field using ArcObjects?

4224
14
09-02-2014 08:55 AM
KevinLECOCQ
New Contributor III

Hi,

I'm trying to automate the complete creation of a schematic template with ArcObjects SDK for Java (10.2).

I've managed to create the GDB, the schematic dataset and the schematic diagram class (template).

Then, I created a schematic element class associated with a feature class taken from the same GDB, which works.

I would like to share a field "NAME" between the feature class and the schematic element class, in order to label the nodes of a schematic diagram.

So, I tried that:

     ...

     ISchematicElementClass nodeSchematicElementClass = schematicDataset.createSchematicElementClass("NODE", esriSchematicElementType.esriSchematicNodeType);

     nodeSchematicElementClass.setSchematicDataSourceByRef(schematicDataSource);

     nodeSchematicElementClass.alterAssociatedObjectClass(schematicDataSource, nodeFeatureClass.getObjectClassID());

     nodeSchematicElementClass.setGeometryType(esriGeometryType.esriGeometryPoint);

     nodeSchematicElementClass.setExternalQueryEvaluationMode(esriSchematicExternalQueryEvaluationMode.esriSchematicQueryBuildEvaluation);

     nodeSchematicElementClass.setQueryString("SELECT * FROM NODE");

     schematicDiagramClass.associateSchematicElementClass(nodeSchematicElementClass);

     UID associatedFieldUID = new UID();

     associatedFieldUID.setValue("{7DE3A19D-32D0-41CD-B896-37CA3AFBD88A}"); // taken from the file ...\Desktop10.2\bin\configuration\CLSID\esri.clsid.ecfg

     ISchematicAttribute schematicAttribute = nodeSchematicElementClass.createSchematicAttribute("NAME", associatedFieldUID);

then I get the following ArcObjects error in the last line:

AutomationException: 0x80040a28 - Additional field can't be added : NAME in 'Esri Schematics'

I get the same error with any other field name.

Does anybody have a solution? Am I doing something wrong with my attribute field association?

I would appreciate any help! Thanks,

Kevin

0 Kudos
14 Replies
Anne-YvonneBlin
New Contributor III

Hi Kevin

There is a sample in ArcObjects Help for .NET that should help you: http://resources.arcgis.com/en/help/arcobjects-net/conceptualhelp/index.html#//000100000p85000000

Hopping this help

Anne-Yvonne

0 Kudos
KevinLECOCQ
New Contributor III

Yes Anne-Yvonne, thanks for your reply.

Actually, I was inspired by this .NET sample to write my Java code.

I used the same method: after creating the ISchematicElementClass, the UID corresponding to the SchematicAttributeAssociatedField class is created, then I invoke the function createSchematicAttribute with the field name and this UID.

So, maybe it's not the right time to invoke this function. I don't see how/when to do it.

0 Kudos
Anne-YvonneBlin
New Contributor III

Several questions to make sure I understand:

  • On the node schematic feature class you want to create by code, you specified a SQL Query to get all the nodes in your NODE GIS feature class. Does this mean that you expect to generate diagrams containing all those features as schematic node features in each of your diagrams? No problem with that but, in that case, you must know that you are taking control on the node features that will be built in your diagrams (the Standard builder will not longer manage them.)
  • You want to create a schematic attribute which values will be retrieved from the NAME field of the NODE GIS feature class you are querying. In this case, you must create a SchematicAttributeField instead of a SchematicAttributeAssociatedField (SchematicAttributeAssociatedField is designed to be used for features that are fully controlled by the Standard builder, not those returned by query). The code below should help you creating this SchematicAttributeField;

''' Create a field SchematicAttribute on a given SchematicElementClass

''' </summary>

''' <param name="schElementClass">The SchematicElementClass where the field attribute is created</param>

''' <param name="AttributeName">The ISchematicAttributeField name</param>

''' <param name="EvalMode">The EvaluationMode for the created schematic attribute</param>

''' <param name="StorageMode">The StorageMode for the created schematic attribute</param>

''' <param name="value">The FieldNames for the created schematic attribute</param>

''' <returns>The created ESRI.ArcGIS.Schematic.ISchematicAttributeField</returns>

''' <remarks>The UID.Value is a contant GUID value for the ISchematicAttributeField type of schematic attribute</remarks>

Public Function CreateAttributeFieldForElementClass(ByVal schElementClass As ESRI.ArcGIS.Schematic.ISchematicElementClass, ByVal AttributeName As String, ByVal EvalMode As ESRI.ArcGIS.Schematic.esriSchematicAttributeEvaluationMode, ByVal StorageMode As ESRI.ArcGIS.Schematic.esriSchematicAttributeStorageMode, ByVal value() As String) As ESRI.ArcGIS.Schematic.ISchematicAttributeField

  Dim schAttribute As ESRI.ArcGIS.Schematic.ISchematicAttribute = Nothing

        Try

  ' create an ISchematicAttribute

  Dim pUid As ESRI.ArcGIS.esriSystem.UID = New ESRI.ArcGIS.esriSystem.UID()

  pUid.Value = "{E1902BB0-6070-4EE2-995A-DB86FAC5EEB0}"

  schAttribute = schElementClass.CreateSchematicAttribute(AttributeName, pUid)

        Catch

  Return Nothing

        End Try

  Dim schAttributeMngt As ESRI.ArcGIS.Schematic.ISchematicAttributeManagement = TryCast(schAttribute, ESRI.ArcGIS.Schematic.ISchematicAttributeManagement)

  Try

  ' the StorageMode must be set before the EvaluationMode

  ' consistenty is checked when the EvaluationMode is set

  schAttributeMngt.StorageMode = StorageMode

  schAttributeMngt.EvaluationMode = EvalMode

  Catch

  ' an error is returned if the StorageMode and EvaluationMode are not consistent

  End Try

  ' cast SchematicAttribute into ISchematicAttributeField and set its properties

  Dim schAttField As ESRI.ArcGIS.Schematic.ISchematicAttributeField = TryCast(schAttribute, ESRI.ArcGIS.Schematic.ISchematicAttributeField)

  If (schAttField IsNot Nothing) Then

  schAttField.FieldNames = value

  End If

  Return schAttField

End Function

  • This being said, the message you get looks strange; "Additional field can't be added : NAME in 'Esri Schematics'"... According to me, this has nothing to do with AttributeAssociatedField type vs AttributeField type. Could you have a look on the schematic feature classes created under schematic dataset? Is your new NODE schematic feature class already created? Does it already contain a NAME field? Here are the steps to verify that:
  1. Start ArcCatalog and expand the schematic dataset in Catalog tree.
  2. Right-click the schematic dataset in Catalog tree.
  3. Click Show/Hide Schematic Classes.
0 Kudos
KevinLECOCQ
New Contributor III

Yes, by using an SQL query when creating the node schematic element class, I expect to generate a diagram containing every node of my feature class. When you say that the standard builder will no longer manage them, that's to say node features selection has no effect on the diagram generation? Actually, in addition to this attribute issue, I don't manage to create a schematic diagram because I don't see how to instantiate (in java) a ISchematicStandardBuilder in order to use the generateDiagram function.

0 Kudos
Anne-YvonneBlin
New Contributor III

You are right, selecting features prior to generate the diagram have no impact when configuring queries on your schematic feature classes. If you want to generate diagram from a selection set of features in your map, you should let the standard builder running in its full "standard" mode.

0 Kudos
KevinLECOCQ
New Contributor III

And OK, I will try to create a SchematicAttributeField instead of a SchematicAttributeAssociatedField.

Now, in ArcCatalog, I see my schematic dataset containing a schematic template, containing the schematic NODE and EDGE feature classes I created, so that's a good start.

0 Kudos
Anne-YvonneBlin
New Contributor III

Except if you want to work from a selection set of features... In this case, you need to associate your schematic feature class to the desired GIS feature class (NODE in your case, I guess), remove the SQL query you specified for your schematic class and create a SchematicAttributeAssociatedField instead.

How do you want to work exactly (from a features selection set or from queries?)? Why are you coding your dataset configuration; that is, the creation of your diagram template, schematic feature classes from scratch? Why are you not working within Dataset Editor?

Did you read and try the Schematics tutorials http://resources.arcgis.com/en/help/main/10.2/index.html#//004z00000066000000

and the Schematics videos Getting started with Schematics in videos | ArcGIS Resource Center

0 Kudos
KevinLECOCQ
New Contributor III

I prefer the SQL query method, but actually it doesn't matter as I want to associate all GIS features to schematic features.

I'm trying to automate the schematic dataset, template and diagram creation by code because I have to create a lot of geodatabases containing each one a geometric network and a schematic diagram based on it.

0 Kudos
Anne-YvonneBlin
New Contributor III

It's up to you to do so... but it looks to be quite complex. In your case, I would have coded the diagram template creation and configure it to simply work with the Standard builder with the AutoCreateElementClasses option turned on.

Then I would have called GenerateDiagram on ISchematicBuilder while the InitialObjects for the input ISchematicBuilderContext parameter is initialized with the whole set of geometric network edges. Indeed, working with the only edges in input is often sufficient for the Standard builder to generate diagrams corresponding to the entire GN.

0 Kudos