首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在dm-script中使用python添加文本注释

如何在dm-script中使用python添加文本注释
EN

Stack Overflow用户
提问于 2021-01-19 09:28:18
回答 1查看 167关注 0票数 1

如何在dm-脚本中添加带有python的文本注释(编辑.在3.4.0版中)?

我想在GMS环境中使用python向图像添加一些文本。因此,我想使用文本注释。

我可以使用DM.NewTextAnnotation()创建文本注释。但是返回的DM.Py_Component对象没有任何ComponentAddChild...()方法。因此,我可以创建文本注释,但不能添加它们。

还有一个DM.Py_Component.AddNewComponent(type, f1, f2, f3, f4)方法。我可以用它创建文本注释(使用type = 13)。但是我只能用参数f1f4来指定位置。使用字符串参数将引发TypeError。有一个DM.Py_Component.GetText()和几个字体操作方法,但没有DM.Py_Component.SetText()。因此,我可以创建文本注释,这些注释已经附加到父组件,但没有文本。我不能设置课文。

dm-script文档还讨论了一个Component::ComponentExternalizeProperties(),它允许我假设每个组件的背景中都有一个TagGroup。即使python模块中没有DM.Py_Component.ExternalizeProperties(),也有任何方法来操作它吗?

因此,我的问题是:向图像添加文本注释的目的是什么?有没有向组件添加注释或设置添加注释的文本的方法?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-01-19 11:16:34

上述缺失的命令是与最近发布的GMS 3.4.3一起添加的。没有它们,就没有办法添加组件,除非有一些创造性的混合编码。

对于这些命令,正确的示例是:

代码语言:javascript
复制
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)的文本:

代码语言:javascript
复制
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脚本来绕过缺失的命令,如本例所示:

代码语言:javascript
复制
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 testImg
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65788652

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档