如何在dm-脚本中添加带有python的文本注释(编辑.在3.4.0版中)?
我想在GMS环境中使用python向图像添加一些文本。因此,我想使用文本注释。
我可以使用DM.NewTextAnnotation()创建文本注释。但是返回的DM.Py_Component对象没有任何ComponentAddChild...()方法。因此,我可以创建文本注释,但不能添加它们。
还有一个DM.Py_Component.AddNewComponent(type, f1, f2, f3, f4)方法。我可以用它创建文本注释(使用type = 13)。但是我只能用参数f1到f4来指定位置。使用字符串参数将引发TypeError。有一个DM.Py_Component.GetText()和几个字体操作方法,但没有DM.Py_Component.SetText()。因此,我可以创建文本注释,这些注释已经附加到父组件,但没有文本。我不能设置课文。
dm-script文档还讨论了一个Component::ComponentExternalizeProperties(),它允许我假设每个组件的背景中都有一个TagGroup。即使python模块中没有DM.Py_Component.ExternalizeProperties(),也有任何方法来操作它吗?
因此,我的问题是:向图像添加文本注释的目的是什么?有没有向组件添加注释或设置添加注释的文本的方法?
发布于 2021-01-19 11:16:34
上述缺失的命令是与最近发布的GMS 3.4.3一起添加的。没有它们,就没有办法添加组件,除非有一些创造性的混合编码。
对于这些命令,正确的示例是:
testImg = DM.GetFrontImage()
img_disp = testImg.GetImageDisplay(0)
textComp = DM.NewTextAnnotation(0, 0, 'test new text annotation', 15)
img_disp.AddChildAtEnd(textComp)
# Cleanup
del img_disp
del testImg以及更改现有文本组件(类型13)的文本:
testImg = DM.GetFrontImage()
img_disp = testImg.GetImageDisplay(0)
nSubComp = img_disp.CountChildren()
for index in range(nSubComp):
comp = img_disp.GetChild(index)
if ( comp.GetType() == 13 ):
comp.TextAnnotationSetText( 'Other text' )
# Cleanup
del img_disp
del testImg如果您需要使用先前的GMS 3.4.3版本来完成此操作,您可以通过从Python脚本调用DM脚本来绕过缺失的命令,如本例所示:
annotext = 'This is the annotation'
testImg = DM.GetFrontImage()
# Build a DM script as proxy
dmScript = '// This is a DM script' + '\n'
dmScript += 'imageDisplay disp = ' + testImg.GetLabel() + '.ImageGetImageDisplay(0)' + '\n'
dmScript += 'component anno = NewTextAnnotation( 0, 0, "'
dmScript += annotext
dmScript += '", 15)' + '\n'
dmScript += 'disp.ComponentAddChildAtEnd( anno )' + '\n'
#print( dmScript )
# Run the DM script
DM.ExecuteScriptString( dmScript )
# Cleanup
del testImghttps://stackoverflow.com/questions/65788652
复制相似问题