How to change geometry of annotation?

1124
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
1 Solution

Accepted Solutions
JeffMatson
Occasional Contributor III
You'll need to have an edit session going, either programatically, or manually via the Editor toolbar...


pElement does't accept any changes. The following code gives me automation errors:
                        '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 '*** automation error ***                          Dim pNewPointCol As IPointCollection                         Set pNewPointCol = New Polyline                         Set pNewPointCol = pNewPolyline                         pElement.Geometry = pNewPointCol '*** automation error ***                                                  pPointCol.RemovePoints 1, pPointCol.PointCount - 2                         pElement.Geometry = pPointCol '*** automation error ***                        

View solution in original post

0 Kudos
11 Replies
HenkZwols
Occasional Contributor
Nobody has the answer?
0 Kudos
NeilClemmons
Regular Contributor III
Have you tried modifying the geometry used by the text path (ITextPath.Geometry)?
0 Kudos
HenkZwols
Occasional Contributor
Yes Neal, but did not succeed. Maybe you can show me how to do it?
0 Kudos
JeffMatson
Occasional Contributor III
The documentation recommends not changing the geometry of an OverposterTextPath:

http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#/ITextPath_Interface/001w...

Can you create a new SimpleTextPath (using a newly created polyline of the From and To points) and then assign this new SimpleTextPath back to your TextSymbol.TextPath?
0 Kudos
HenkZwols
Occasional Contributor
There must be missing something. The geometry doesn't change.
                        '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)

                        Dim pNewTextPath As ITextPath
                        Set pNewTextPath = New SimpleTextPath
                        Set pNewTextPath.Geometry = pNewPolyline
                        Set pTextSym.TextPath = pNewTextPath

                        pFeatureCursor.UpdateFeature pFeature
0 Kudos
JeffMatson
Occasional Contributor III
You'll probably need to set pElement.Geometry back to the modified point collection and then set pAnnoFeat.Annotation to the updated pElement.

If TypeOf pElement.Geometry Is IPolyline Then


      Dim pPointCol As IPointCollection
      Set pPointCol = pElement.Geometry

       ' Just keep start- and endpoint
       pPointCol.RemovePoints 1, pPointCol.PointCount - 2
                        
       ''----------------------------
        pElement.Geometry = pPointCol
        pAnnoFeat.Annotation = pElement
        ''----------------------------
                        
        pFeatureCursor.UpdateFeature pfeature
                       
End If




There must be missing something. The geometry doesn't change.
                        '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)

                        Dim pNewTextPath As ITextPath
                        Set pNewTextPath = New SimpleTextPath
                        Set pNewTextPath.Geometry = pNewPolyline
                        Set pTextSym.TextPath = pNewTextPath

                        pFeatureCursor.UpdateFeature pFeature
0 Kudos
HenkZwols
Occasional Contributor
pElement does't accept any changes. The following code gives me automation errors:
                        '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 '*** automation error ***

                        Dim pNewPointCol As IPointCollection
                        Set pNewPointCol = New Polyline
                        Set pNewPointCol = pNewPolyline
                        pElement.Geometry = pNewPointCol '*** automation error ***     
                   
                        pPointCol.RemovePoints 1, pPointCol.PointCount - 2
                        pElement.Geometry = pPointCol '*** automation error ***                        
0 Kudos
JeffMatson
Occasional Contributor III
You'll need to have an edit session going, either programatically, or manually via the Editor toolbar...


pElement does't accept any changes. The following code gives me automation errors:
                        '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 '*** automation error ***                          Dim pNewPointCol As IPointCollection                         Set pNewPointCol = New Polyline                         Set pNewPointCol = pNewPolyline                         pElement.Geometry = pNewPointCol '*** automation error ***                                                  pPointCol.RemovePoints 1, pPointCol.PointCount - 2                         pElement.Geometry = pPointCol '*** automation error ***                        
0 Kudos
HenkZwols
Occasional Contributor
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