Examining Annotations (2) Example for C#

private void ExamineAnnotations2(ref LTDICLib.LEADDicomDS objPresStateDS)
{
   string sRefSOPInstanceUID = null;
   // Pick one of the images referenced in the "Presentation State Module" and
   // get its SOP Instance UID
   if (objPresStateDS.FindFirstPresStateRefSeriesItem() == (short)LTDicomKernelLib.DicomErrorCodes.DICOM_SUCCESS)
   {
      if (objPresStateDS.GetPresStateImageRefCount() > 0)
         sRefSOPInstanceUID = objPresStateDS.GetPresStateImageRefInstanceUID(0);
   }
   // Find the SOP Class UID of that image
   if (objPresStateDS.FindPresStateRefImageItem(sRefSOPInstanceUID) == (short)LTDicomKernelLib.DicomErrorCodes.DICOM_SUCCESS)
   {
      if (objPresStateDS.MoveChildElement() == 0)
      {
         if (objPresStateDS.FindFirstElement((int)LTDICLib.DicomDataSetTagConstants1.TAG_REFERENCED_SOP_CLASS_UID, true) == 0)
         {
            if (objPresStateDS.GetStringValue(0, 1) == 0)
               MessageBox.Show(objPresStateDS.get_StringValues(0), "Referenced SOP Class UID");
         }
      }
   }
   // Remove the reference to that image from the "Presentation State Module"
   objPresStateDS.RemovePresStateImageRef(sRefSOPInstanceUID);
   // Pick a Graphic Annotation Item int hGraphicAnnotationItem = 0;
   string sGraphicLayer = null;
   if (objPresStateDS.FindFirstGraphicAnnItem() == (short)LTDicomKernelLib.DicomErrorCodes.DICOM_SUCCESS)
   {
      hGraphicAnnotationItem = objPresStateDS.get_CurrentElement().hElement;
      // Pick an image reference
      if (objPresStateDS.GetLayerImageRefCount() > 0)
      {
         sRefSOPInstanceUID = objPresStateDS.GetLayerImageRefInstanceUID(0);
         objPresStateDS.FindLayerRefImageItem(sRefSOPInstanceUID);
         // Display one of the attributes of the Referenced Image Item
         if (objPresStateDS.MoveChildElement() == 0)
         {
            if (objPresStateDS.FindFirstElement((int)LTDICLib.DicomDataSetTagConstants1.TAG_REFERENCED_SOP_CLASS_UID, true) == 0)
            {
               if (objPresStateDS.GetStringValue(0, 1) == 0)
                  MessageBox.Show("Referenced SOP Class UID: " + objPresStateDS.get_StringValues(0), "Referenced Image Item");
            }
         }
         objPresStateDS.SetCurrentElement(hGraphicAnnotationItem);
         // Remove the image reference
         objPresStateDS.RemoveLayerImageRef(sRefSOPInstanceUID);
         // Remove all references to images that are listed in this Graphic Annotation
         // Item (this way, the annotations defined by this Item will be applied to all
         // the images listed in the "Presentation State Module")
         objPresStateDS.RemoveAllLayerImageRefs();
      }
      sGraphicLayer = objPresStateDS.GetLayerName();
      // Display some of the layer's attributes objPresStateDS.GetLayerAttributes(objPresStateDS.GetLayerIndex(sGraphicLayer));
      MessageBox.Show("Graphic Layer: " + objPresStateDS.LayerAttributes.LayerName + System.Environment.NewLine + "Graphic Layer Order: " + objPresStateDS.LayerAttributes.LayerOrder + System.Environment.NewLine + "Graphic Layer Description: " + objPresStateDS.LayerAttributes.LayerDescription, "Graphic Layer Attributes");
      // Change the layer of this Graphic Annotation Item (the specified new
      // layer should already be defined in the "Graphic Layer Module")
      objPresStateDS.SetLayerName("ANOTHER_LAYER");
      // Pick a graphic annotation object
      if (objPresStateDS.GetGraphicObjectCount() > 0)
      {
         objPresStateDS.FindGraphicObjectItem(0);
         // Display one of the attributes of this object
         if (objPresStateDS.MoveChildElement() == 0)
         {
            // Graphic Type (0070,0023)
            if (objPresStateDS.FindFirstElement(0X700023, true) == 0)
            {
               if (objPresStateDS.GetStringValue(0, 1) == 0)
                  MessageBox.Show("Graphic Type: " + objPresStateDS.get_StringValues(0), "Graphic Annotation Object");
            }
         }
         objPresStateDS.SetCurrentElement(hGraphicAnnotationItem);
         // Remove the object objPresStateDS.RemoveGraphicObject(0);
         // Remove all the graphic annotation objects defined by this Graphic
         // Annotation Item
         objPresStateDS.RemoveAllGraphicObjects();
         // Or:
         //objPresStateDS.RemoveLayerGraphicObjects
      }
      // Pick a text annotation object
      if (objPresStateDS.GetTextObjectCount() > 0)
      {
         objPresStateDS.FindTextObjectItem(0);
         // Display one of the attributes of this object
         if (objPresStateDS.MoveChildElement() == 0)
         {
            // Unformatted Text Value (0070,0006)
            if (objPresStateDS.FindFirstElement(0X700006, true) == 0)
            {
               if (objPresStateDS.GetStringValue(0, 1) == 0)
                     MessageBox.Show("Unformatted Text Value: " + objPresStateDS.get_StringValues(0), "Text Annotation Object");
            }
         }
         objPresStateDS.SetCurrentElement(hGraphicAnnotationItem);
         // Remove the object
         objPresStateDS.RemoveTextObject(0);
         // Remove all the text annotation objects defined by this Graphic
         // Annotation Item
         objPresStateDS.RemoveAllTextObjects();
         // Or:
         //objPresStateDS.RemoveLayerTextObjects

      }
   }
   // Remove all references to images that are listed in all the Graphic Annotation
   // Items (this way, the annotations defined by all the Items will be applied to all
   // the images listed in the "Presentation State Module")
   objPresStateDS.RemoveAllLayersImageRefs();
   // Remove all references to images from the "Presentation State Module"
   objPresStateDS.RemoveAllPresStateImageRefs();
   // Pick one of the layers
   if (objPresStateDS.LayerCount > 0)
   {
      objPresStateDS.FindLayerItem(0);
      // Display one of the attributes of this layer
      if (objPresStateDS.MoveChildElement() == 0)
      {
         // Graphic Layer (0070,0002)
         if (objPresStateDS.FindFirstElement(0X700002, true) == 0)
         {
            if (objPresStateDS.GetStringValue(0, 1) == 0)
               MessageBox.Show("Graphic Layer: " + objPresStateDS.get_StringValues(0), "Graphic Layer");
         }
      }
      // Remove the layer
      objPresStateDS.RemoveLayer(0, true);
      // Remove all the layers defined in the "Graphic Layer Module"
      objPresStateDS.RemoveAllLayers(true);
   }
}