当我使用带有长度标签的线来测量距离时,它会在图像上绘制一条线和一个文本。文字是长度。我想删除所有线条和带线条的文本,同时保留其他文本组件。我可以使用下面的代码删除所有行。但我不知道如何用线条删除文本。
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)
这确实很“棘手”,因为线条及其标签只是注释,只是常规的线条和文本注释,没有易于访问的属性来说明它们的链接。 幸运的是,有一些命令可以解决行标签问题:
LineAnnotationRemoveLengthLabel()
LineAnnotationAddLengthLabel()
LineAnnotationUpdateLengthLabel()
所以,这应该可行。 (请注意 While() 循环的使用,因为现在每次迭代都会删除两个组件。):
Void clear_line_annot(Image img)
{
Number k_line_annot = 2
ImageDisplay img_disp = img.ImageGetImageDisplay(0)
while( 0 < img_disp.ComponentCountChildrenOfType(k_line_annot) )
{
Component comp = img_disp.ComponentGetNthChildOfType(k_line_annot,0)
comp.LineAnnotationRemoveLengthLabel()
comp.ComponentRemoveFromParent()
}
}
Image img := GetFrontImage()
clear_line_annot(img)
我有时发现另一对命令很有用: 组件对象可以将自己序列化到 tagGroup 或从 tagGroup 序列化 - 这也是您保存或加载 imageDocument 时发生的情况。 这也可以通过脚本来完成:
image img:=RealImage("Test",4,100,100) = icol
img.ShowImage()
imageDisplay disp = img.ImageGetImageDisplay(0)
component comp = NewTextAnnotation(disp,30,30,"Test text\n2nd line", 12)
disp.ComponentAddChildAtEnd(comp)
TagGroup tg = NewTagGroup()
comp.ComponentExternalizeProperties(tg)
If (TwoButtonDialog("Show Externalized?","Yes","No"))
tg.TagGroupOpenBrowserWindow("Component serialized",0)
If (TwoButtonDialog("Modify ?","Yes","No"))
{
tg.TagGroupSetTagAsLong("TextFormat:DrawingMode",1)
tg.TagGroupSetTagAsFloat("Transparency",0.6)
comp.ComponentInternalizeProperties(tg)
}