This document is archived and information here might be outdated.  Recommended version.


Create A SchematicAttributeFormatted On A Schematic Element Class Snippet (ArcObjects .NET 10.5 SDK)
ArcObjects Library Reference

Create A SchematicAttributeFormatted On A Schematic Element Class Snippet

Create a formatted SchematicAttribute on a given SchematicElementClass

[C#]
        /// <summary>
        /// Create a formatted SchematicAttribute on a given SchematicElementClass
        /// </summary>
        /// <param name="schElementClass">The SchematicElementClass where the formatted attribute is created</param>
        /// <param name="AttributeName">The ISchematicAttributeFormatted 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="sFormat">The Format for the created schematic attribute</param>
        /// <param name="ParameterNames">The ParameterNames for the created schematic attribute</param>
        /// <returns>The created ESRI.ArcGIS.Schematic.ISchematicAttributeFormatted</returns>
        /// <remarks>The UID.Value is a contant GUID value for the ISchematicAttributeFormatted type of schematic attribute</remarks>
        public ESRI.ArcGIS.Schematic.ISchematicAttributeFormatted CreateAttributeFormattedForElementClass(ESRI.ArcGIS.Schematic.ISchematicElementClass schElementClass, string AttributeName, ESRI.ArcGIS.Schematic.esriSchematicAttributeEvaluationMode EvalMode, ESRI.ArcGIS.Schematic.esriSchematicAttributeStorageMode StorageMode, string sFormat, string[] ParameterNames)
        {

                ESRI.ArcGIS.Schematic.ISchematicAttribute schAttribute=null;
                try
                // create an ISchematicAttribute
                {
                        ESRI.ArcGIS.esriSystem.UID pUid=new ESRI.ArcGIS.esriSystem.UID();
                        pUid.Value="{1DE95A2A-B750-446A-8D3A-3C67660E8B59}";
                        schAttribute=schElementClass.CreateSchematicAttribute(AttributeName, pUid);
                }
                catch
                {
                        return null;
                }

                ESRI.ArcGIS.Schematic.ISchematicAttributeManagement schAttributeMngt=(ESRI.ArcGIS.Schematic.ISchematicAttributeManagement)schAttribute;
                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
                }

                // cast SchematicAttribute into ISchematicAttributeFormatted and set its properties
                ESRI.ArcGIS.Schematic.ISchematicAttributeFormatted schAttFormatted=(ESRI.ArcGIS.Schematic.ISchematicAttributeFormatted)schAttribute;
                if (schAttFormatted != null)
                {
                        schAttFormatted.Format=sFormat;
                        schAttFormatted.ParameterNames=ParameterNames;
                }

                return schAttFormatted;
        }
[Visual Basic .NET]
        ''' <summary>
        ''' Create a formatted SchematicAttribute on a given SchematicElementClass
        ''' </summary>
        ''' <param name="schElementClass">The SchematicElementClass where the formatted attribute is created</param>
        ''' <param name="AttributeName">The ISchematicAttributeFormatted 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="sFormat">The Format for the created schematic attribute</param>
        ''' <param name="ParameterNames">The ParameterNames for the created schematic attribute</param>
        ''' <returns>The created ESRI.ArcGIS.Schematic.ISchematicAttributeFormatted</returns>
        ''' <remarks>The UID.Value is a contant GUID value for the ISchematicAttributeFormatted type of schematic attribute</remarks>
        Public Function CreateAttributeFormattedForElementClass(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 sFormat As String, ByVal ParameterNames() As String) As ESRI.ArcGIS.Schematic.ISchematicAttributeFormatted

                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="{1DE95A2A-B750-446A-8D3A-3C67660E8B59}"
                        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 ISchematicAttributeFormatted and set its properties
                Dim schAttFormatted As ESRI.ArcGIS.Schematic.ISchematicAttributeFormatted=TryCast(schAttribute, ESRI.ArcGIS.Schematic.ISchematicAttributeFormatted)
                If (schAttFormatted IsNot Nothing) Then
                        schAttFormatted.Format=sFormat
                        schAttFormatted.ParameterNames=ParameterNames
                End If

                Return schAttFormatted
        End Function

Additional Requirements
  • The code in this document requires the following References added to the Visual Studio project:
  • ESRI.ArcGIS.Schematic