When I used line with length label to measure the distance, it will draw a line and a text on the image. The text is the length. I'd like to remove all the line and the text with line, while keep other text components. I can use the code below to remove all the line. But I have no idea how to remove the text with line.
Void clear_line_annot(Image img)
{
Number k_line_annot = 2
ImageDisplay img_disp = img.ImageGetImageDisplay(0)
Number comp_num = img_disp.ComponentCountChildren()
for (Number i = comp_num - 1; i >= 0; i--)
{
Component comp = img_disp.ComponentGetChild(i)
if (comp.ComponentGetType()!= k_line_annot) Continue
comp.ComponentRemoveFromParent()
}
}
Image img := GetFrontImage()
clear_line_annot(img)
This is indeed "tricky" as lines and their labels are just annotations are just regular line and text annotations with no easily accessible property telling about their linkage. Luckily, some commands exist to address line-labels:
LineAnnotationRemoveLengthLabel()LineAnnotationAddLengthLabel()LineAnnotationUpdateLengthLabel()So, this should work. (Note the use of the While() loop, as each iteration now removes two components.):
There is another pair of commands which I sometimes find useful: Component objects can serialize themselves to and from tagGroups - that's what happens when you save or load an imageDocument as well. This can also be done by script: