AnsweredAssumed Answered

IEditTemplate SetDefault Value help

Question asked by purplecruz on Oct 2, 2015
Latest reply on Oct 9, 2015 by purplecruz

I am trying to set a default value for a field. I have created a script in VB.Net that will access the layers I am interested in and get the edit template for each one.  I can access all of the properties in the IEditTemplate interface but when I try and access the SetDefaultValue method I get an error - Error HRESULT E_FAIL has been returned from a call to a COM component.  I have 3 message boxes that display the values without error but as soon as it reaches the SetDefaultValue it errors out.  Any help would be greatly appreciated!

                    Dim idx As Integer
                    Dim pLayer As ILayer
                    Dim pFeatureLayer As IFeatureLayer2
                    Dim pFeatureClass As IFeatureClass
                    Dim pDataset As IDataset
                    Dim pEnumLayer As IEnumLayer


                    pEnumLayer = pMap.Layers(Nothing, True)
                    pEnumLayer.Reset()
                    pLayer = pEnumLayer.Next


                    For idx = 0 To pMap.LayerCount - 1
                        Do Until pLayer Is Nothing
                            If TypeOf pLayer Is IFeatureLayer2 And Not TypeOf pLayer Is RasterLayer Then
                                pFeatureLayer = pLayer
                                pFeatureClass = pFeatureLayer.FeatureClass
                                If pFeatureLayer.DataSourceType = "SDE Feature Class" Then
                                    If Not pFeatureClass.FeatureDataset Is Nothing Then
                                        pDataset = pFeatureClass.FeatureDataset
                                        Dim pLayerExt As ILayerExtensions
                                        pLayerExt = pLayer
                                        Dim pEditTemplateMgr As IEditTemplateManager
                                        Dim jdx As Integer
                                        For jdx = 0 To pLayerExt.ExtensionCount - 1
                                            Dim extension As Object = pLayerExt.Extension(jdx)
                                            If TypeOf extension Is IEditTemplateManager Then
                                                pEditTemplateMgr = extension
                                                Dim pEditTemplate As IEditTemplate = pEditTemplateMgr.EditTemplate(0)
                                                MsgBox(pLayerExt.ExtensionCount)
                                                MsgBox(pEditTemplate.Name)
                                                MsgBox(pEditTemplate.DefaultValue("Feature_Type"))
                                                pEditTemplate.SetDefaultValue("Feature_Type", "Lake", True)
                                            End If
                                        Next
                                    End If
                                End If
                            End If
                            pLayer = pEnumLayer.Next
                        Loop
                    Next

Outcomes