Select to view content in your preferred language

Update Feature Linked Annotation

2857
4
11-14-2010 04:48 AM
MeleKoneya
Frequent Contributor
We have non Feature Linked Annotation which I am copying to the Feature Linked Annotation Feature Class with an ICommand.  

The feature linked anno shows water main size and material.

Once copied,  the FeatureID of the feature linked anno is calculated to the OID of the water main feature which contains its annotation.

This procedure works well,  but I am looking for a solution to update the annotation so that it reflects the current values in the related water main feature.

Our current thought is to calc a value in a field in the related water main feature that is used to derive the feature linked annotation.     What we would do is to calculate the value to itself and then this would trigger the update of the annotation.

Is there any methods in ArcObjects that would update the annotation without having to calculate a value in the water main feature?

Thanks,

Mele
0 Kudos
4 Replies
johannesuhl
Deactivated User
Hello there,

did you find a solution to your problem? I am running into the same problem. I found some code to update the annotations (using the IAnnotationFeature2 Interface) but it does not work for updating the text string. If you found a solution and still remember it (your post was a long time ago :-)) it would be great if you could give me some advice 🙂 Thank you very much,

Best, Johannes

The following code sample demonstrates how to update the text of an AnnotationFeature:

Public Sub UpdateText(pAnnoFeature As IAnnotationFeature2)
  Dim pElement As IElement
  Set pElement = pAnnoFeature.Annotation
   
  If TypeOf pElement Is ISymbolCollectionElement Then
    'use ISymbolCollectionElement for efficient annotation updates editing
    Dim pSymbolCollectionElement As ISymbolCollectionElement
    Set pSymbolCollectionElement = pElement
    pSymbolCollectionElement.Text = "Foo"
    pAnnoFeature.Annotation = pElement
    Dim pFeature As IFeature
    Set pFeature = pAnnoFeature
    pFeature.Store
  End If
End Sub
0 Kudos
MeleKoneya
Frequent Contributor
Johannes,

I was able to get something to work,   I am reviewing my code so I can refresh my mind as to what it actually does.  

I will post some code and an explanation to this forum once I figure out what I did.

Mele
0 Kudos
MeleKoneya
Frequent Contributor
We have non feature linked water annotation and water mains with feature linked annotation.

In order to transfer existing anno to feature linked annotation the user selects an existing annotation feature and a water main.
The program then creates a new feature linked annotation feature where the selected non-feature linked annotation is placed.      The program also assigns the Water Main OID of the selected water main to the feature linked annotation LinkedFeatureID.

The feature linked annotation is forced to update by setting a field in the water main.   In our case, we just updated the Owner field to its current value and then the feature linked annotation is forced to update.

Finally the program deletes the non-feature linked annotation.

Attached is the code that does the items described above.  

public static IFeatureClass FCmain_anno;   - set to feature linked annotation feature class
public static IFeatureClass FCmain; - set to water main feature class
public static IFeatureSelection FMainSel;  set to selected water main
public static ISelectionSet MainSelSet;
public static ISelectionSet Anno_SelSet;
public static IFeatureCursor FCur_main;
public static IFeatureCursor FCur_anno;
public static IFeature FMain;
public static IFeature F_anno;
public static IAnnotationFeature2 Anno_Feat;
  
  
  
               FCmain_anno = FLmain_anno.FeatureClass;
               FCmain = FLmain.FeatureClass;

                //get main feature
                IQueryFilter QF = null;
                FMainSel = (IFeatureSelection)FLmain;
                MainSelSet = FMainSel.SelectionSet;
                MainSelSet.Search(QF, false, out Cur_Main);
                FCur_main = (IFeatureCursor)Cur_Main;
                FMain = FCur_main.NextFeature();

                //get existing anno feature
                F_annoSel = (IFeatureSelection)FL_anno;
                Anno_SelSet = F_annoSel.SelectionSet;
                Anno_SelSet.Search(QF, false, out Cur_anno);
                FCur_anno = (IFeatureCursor)Cur_anno;
                F_anno = FCur_anno.NextFeature();
                Anno_Feat = (IAnnotationFeature2)F_anno;
               
                //create new  main anno feature
                IFeature wmannoFeature = FCmain_anno.CreateFeature();
                IAnnotationFeature2 FLannoFeat = (IAnnotationFeature2)wmannoFeature;
                FLannoFeat.Annotation = Anno_Feat.Annotation;

                UID edUID = new UIDClass();
                edUID.Value = "{F8842F20-BB23-11D0-802B-0000F8037368}";

                IEditor editor = (IEditor)m_application.FindExtensionByCLSID(edUID);
                IEditLayers EditLayers = (IEditLayers)editor;

                EditLayers.SetCurrentLayer(FLmain_anno, 0);
                //assign OID to feature linked anno
                int OIDFieldvalue = FMain.OID;
                FLannoFeat.LinkedFeatureID = OIDFieldvalue;

                //assign AnnoClassID 
                int annoclassid = 0;
                FLannoFeat.AnnotationClassID = annoclassid;

                //store feature
                editor.StartOperation();
                wmannoFeature.Store();
                editor.StopOperation("Done");

                ////Get new feature linked anno feature and set symbolID
                IQueryFilter pQF = new QueryFilterClass();
                pQF.WhereClause = "FeatureID = " + OIDFieldvalue;
                IFeatureCursor FLannoCursor = FCmain_anno.Update(pQF, false);

                long symbolid = 0;
                wmannoFeature = FLannoCursor.NextFeature();
                wmannoFeature.set_Value((FCmain_anno.FindField("SymbolId")), symbolid);

                editor.StartOperation();
                FLannoCursor.UpdateFeature(wmannoFeature);
                wmannoFeature.Store();
                editor.StopOperation("IDs updated");

        
                IQueryFilter mQF = new QueryFilterClass();
                mQF.WhereClause = "OBJECTID = " + OIDFieldvalue;
                IFeatureCursor mFCursor = FCmain.Update(mQF, false);
                IFeature mF = mFCursor.NextFeature();
                mF.set_Value(FCmain.FindField("Owner"), mF.get_Value(FCmain.FindField("Owner")));

                editor.StartOperation();
                mFCursor.UpdateFeature(mF);
                editor.StopOperation("Main Updated");

                //delete original anno
                F_anno.Delete();

                pMap.ClearSelection();
                mxDoc.ActiveView.Refresh(); 



I hadn't look at this code for a while so I had to step through the code to jog my fading memory.   I hope this makes sample makes some sense.

Mele
0 Kudos
johannesuhl
Deactivated User
Thank you Mele, I just came back to that topic, your code example was useful for me.
Regards, Johannes
0 Kudos