How to change geometry of annotation?

1125
11
Jump to solution
01-17-2013 01:14 AM
HenkZwols
Occasional Contributor
Hello,

I want to change the geometry (textpath) of existing annotation features so that the curvature gets horizontal.  I tried several things but did not succeed.
Can somebody help me with the code i already have?
        Set pFeatureCursor = pFeatureclass.Update(pFilter, False)         Set pFeature = pFeatureCursor.NextFeature         While Not pFeature Is Nothing              Dim pAnnoFeat As IAnnotationFeature             Set pAnnoFeat = pFeature                          Dim pElement As IElement             Set pElement = pAnnoFeat.Annotation                          Dim pTextElement As ITextElement             Set pTextElement = pElement                          Dim pTextSym As ISimpleTextSymbol             Set pTextSym = pTextElement.Symbol              If Not pTextSym Is Nothing Then                  Dim pTextPath As ITextPath                 Set pTextPath = pTextSym.TextPath                  If TypeOf pTextPath Is IOverposterTextPath Then                      If TypeOf pElement.Geometry Is IPolyline Then                          Dim pPointCol As IPointCollection                         Set pPointCol = New Polyline                         Set pPointCol = pElement.Geometry                          ' Just keep start- and endpoint                         pPointCol.RemovePoints 1, pPointCol.PointCount - 2                                                  '....... Replace textPath here ......                          pFeatureCursor.UpdateFeature pFeature                      End If                 End If             End If             Set pFeature = pFeatureCursor.NextFeature         Wend              End If       


Greetings, Henk
0 Kudos
11 Replies
JeffMatson
Occasional Contributor III
Glad it's working...

To open an edit session on a layer not loaded in ArcMap you can open the workspace using IWorkspaceFactory.OpenFromFile and IWorkspaceEdit.  Here is an old sample that opens a personal geodatabase which will work in ArcMap, ArcCatalog, etc.:

   
Dim pFClass As IFeatureClass
    Dim pEnumDS As IEnumDataset
    Dim pDS As IDataset
    Dim pWS As IWorkspace
    Dim pWSE As IWorkspaceEdit
    Dim pWSF As IWorkspaceFactory
    
    Set pWSF = New AccessWorkspaceFactory
    Set pWS = pWSF.OpenFromFile("C:\TestData\TestData.mdb", 0)
    Set pWSE = pWS
    Set pEnumDS = pWS.Datasets(esriDTAny)
    Set pDS = pEnumDS.Next
    Do Until pDS Is Nothing
        If pDS.Name = "TestLayer1" Then
            Set pFClass = pDS
            Exit Do
        End If
        Set pDS = pEnumDS.Next
    Loop
    
    If Not pFClass Is Nothing Then
        pWSE.StartEditing False
        pWSE.StartEditOperation
        
        Dim pFCur As IFeatureCursor
        Dim pFeat As IFeature
        Set pFCur = pFClass.Search(Nothing, False)
        Set pFeat = pFCur.NextFeature
        Do Until pFeat Is Nothing
            ''Do something with feature....


            Set pFeat = pFCur.NextFeature
        Loop
        pWSE.StopEditOperation
        pWSE.StopEditing True
    End If




Thanks Jeff, that's the way: start an edit session.

                    '*** edit session running ***

                    If TypeOf pElement.Geometry Is IPolyline Then
                           
                        Dim pPointCol As IPointCollection
                        Set pPointCol = New Polyline
                        Set pPointCol = pElement.Geometry

                        'Replace textPath here ......
                        ' Just keep start- and endpoint
                        Dim pNewPolyline As IPolyline
                        Set pNewPolyline = New Polyline
                        pNewPolyline.fromPoint = pPointCol.Point(0)
                        pNewPolyline.toPoint = pPointCol.Point(pPointCol.PointCount - 1)
                        
                        pElement.Geometry = pNewPolyline

                        pAnnoFeat.Annotation = pElement

                        pFeatureCursor.UpdateFeature pFeature

                    End If


One more question: is it possible to start an edit session programatically without having the involved featureclass loaded in the table of contents?
0 Kudos
HenkZwols
Occasional Contributor
Thanks a lot Jeff!
0 Kudos