フィーチャ テンプレートの操作

 2016/9/1 (木)    

Public Sub AddFeatureTemplate()
    Dim pMxDocumenet As IMxDocument
    Set pMxDocumenet = ThisDocument
     
    Dim pFeatureLayer As IFeatureLayer
    Set pFeatureLayer = pMxDocumenet.SelectedLayer  '選択レイヤの取得
     
    Dim pDataset As IDataset
    Set pDataset = pFeatureLayer.FeatureClass
     
    Dim pFeature As IFeature
    Set pFeature = pFeatureLayer.FeatureClass.GetFeature(1)
     
    Dim pEditTemplateFactory As IEditTemplateFactory
    Set pEditTemplateFactory = New EditTemplateFactory
     
    Dim pEditTemplate As IEditTemplate
    Set pEditTemplate = pEditTemplateFactory.Create("<テンプレート名>", pFeatureLayer)
    Call pEditTemplate.SetDefaultValues(pFeature)
     
    Dim pUID As IUID
    Set pUID = New UID
    pUID.Value = "esriEditor.Editor"
     
    Dim pEditor As IEditor3
    Set pEditor = Application.FindExtensionByCLSID(pUID)
     
    '編集の開始
    If Not pEditor.EditState = esriStateEditing Then
        Call pEditor.StartEditing(pDataset.Workspace)
    End If
     
    'テンプレートの追加
    Dim pArray As IArray
    Set pArray = New esriSystem.Array
    Call pArray.Add(pEditTemplate)
    Call pEditor.AddTemplates(pArray)
     
    'テンプレート数
    Debug.Print pEditor.TemplateCount
 
    'テンプレートの取得
    Set pEditTemplate = pEditor.Template(0) '編集開始状態でなければテンプレートがカウントできない
     
    'テンプレートの修正
    Call pEditTemplate.SetDefaultValue("KEN", "あああ", True)
 
    'テンプレートの削除
    pEditor.RemoveTemplate pEditTemplate
 
    '編集の終了
    Call pEditor.StopEditing(False)
End Sub

Copyright© WINGFIELD since1981 , 2018 All Rights Reserved.