How to change geometry of annotation?

305
11
Jump to solution
01-17-2013 01:14 AM
Highlighted
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
Reply
0 Kudos
1 Solution

Accepted Solutions
Highlighted
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

Reply
0 Kudos
11 Replies
Highlighted
Occasional Contributor
Nobody has the answer?
Reply
0 Kudos
Highlighted
Regular Contributor III
Have you tried modifying the geometry used by the text path (ITextPath.Geometry)?
Reply
0 Kudos
Highlighted
Occasional Contributor
Yes Neal, but did not succeed. Maybe you can show me how to do it?
Reply
0 Kudos
Highlighted
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?
Reply
0 Kudos
Highlighted
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
Reply
0 Kudos
Highlighted
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
Reply
0 Kudos
Highlighted
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 ***                       
Reply
0 Kudos
Highlighted
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

Reply
0 Kudos
Highlighted
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?
Reply
0 Kudos