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


Create A SchematicAttributeFunction On A Schematic Element Class Snippet (ArcObjects .NET 10.6 SDK)
ArcObjects Library Reference

Create A SchematicAttributeFunction On A Schematic Element Class Snippet

Create a function SchematicAttribute on a given SchematicElementClass

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

                ESRI.ArcGIS.Schematic.ISchematicAttribute schAttribute=null;
                try
                // create an ISchematicAttribute
                {
                        ESRI.ArcGIS.esriSystem.UID pUid=new ESRI.ArcGIS.esriSystem.UID();
                        pUid.Value="{F5379E0E-1081-4CB0-931A-FE9248463E35}";
                        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 ISchematicAttributeFunction and set its properties
                ESRI.ArcGIS.Schematic.ISchematicAttributeFunction schAttFunction=(ESRI.ArcGIS.Schematic.ISchematicAttributeFunction)schAttribute;
                if (schAttFunction != null)
                {
                        schAttFunction.FunctionName=sFunctionName;
                        schAttFunction.ParameterNames=ParameterNames;
                        schAttFunction.UserProgId=sUserProgId;
                }
                return schAttFunction;
        }
[Visual Basic .NET]
        ''' <summary>
        ''' Create a function SchematicAttribute on a given SchematicElementClass
        ''' </summary>
        ''' <param name="schElementClass">The SchematicElementClass where the function attribute is created</param>
        ''' <param name="AttributeName">The ISchematicAttributeFunction 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="sFunctionName">The FunctionName for the created schematic attribute</param>
        ''' <param name="sUserProgId">The UserProgId for the created schematic attribute</param>
        ''' <param name="ParameterNames">The ParameterNames for the created schematic attribute</param>
        ''' <returns>The created ESRI.ArcGIS.Schematic.ISchematicAttributeFunction</returns>
        ''' <remarks>The UID.Value is a contant GUID value for the ISchematicAttributeFunction type of schematic attribute</remarks>
        Public Function CreateAttributeFunctionForElementClass(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 sFunctionName As String, ByVal sUserProgId As String, ByVal ParameterNames() As String) As ESRI.ArcGIS.Schematic.ISchematicAttributeFunction

                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="{F5379E0E-1081-4CB0-931A-FE9248463E35}"
                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 ISchematicAttributeFunction and set its properties
                Dim schAttFunction As ESRI.ArcGIS.Schematic.ISchematicAttributeFunction=TryCast(schAttribute, ESRI.ArcGIS.Schematic.ISchematicAttributeFunction)
                If (schAttFunction IsNot Nothing) Then
                        schAttFunction.FunctionName=sFunctionName
                        schAttFunction.ParameterNames=ParameterNames
                        schAttFunction.UserProgId=sUserProgId
                End If
                Return schAttFunction
        End Function

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