如何将此AutoCAD VBA代码转换为Python? [英] How to translate this AutoCAD VBA code into Python?

查看:384
本文介绍了如何将此AutoCAD VBA代码转换为Python?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Python在AutoCAD中自动执行某些绘图,并且使用SelectOnScreen方法. 这是VBA中的代码:

I'm trying to automate some drawing in AutoCAD using Python and I work with SelectOnScreen method. Here is a code in VBA:

Dim FilterType(0) As Integer
Dim FilterData(0) As Variant
FilterType(0) = 0
FilterData(0) = "TEXT"
selection.SelectOnScreen FilterType, FilterData

在Python中,我将其用作:

In Python I use it as:

FilterType = win32com.client.VARIANT(VT_ARRAY|VT_I2, [0]) 
FilterData = win32com.client.VARIANT(VT_ARRAY|VT_VARIANT, ['TEXT'])
selection.SelectOnScreen(FilterType, FilterData)

,它可在AutoCAD中使用. 但是我想选择不同类型的对象(文本和多行文本),并且在VBA中有一个代码示例.那么如何将以下VBA代码转换为Python?

and it works in AutoCAD. However I want to select different types of object (texts and mtexts) and I have an example of code in VBA. So how to translate the following VBA code into Python?

Dim FilterType(1) As Integer
Dim FilterData(1) As Variant
FilterType(0) = 0
FilterData(0) = "Text"
FilterType(1) = 0
FilterData(1) = "MText"
selection.SelectOnScreen FilterType, FilterData

这是我尝试的Python代码尝试,但在AutoCAD中不起作用:

Here is my attempt of Python code I've tried, but it doesn't work in AutoCAD:

FilterType = win32com.client.VARIANT(VT_ARRAY|VT_I2, [0, 0]) 
FilterData = win32com.client.VARIANT(VT_ARRAY|VT_VARIANT, ["MTEXT", "TEXT"])
selection.SelectOnScreen(FilterType, FilterData)

当我尝试使用它时什么也没选择.

Nothing selects when I try to use it.

推荐答案

您的代码无法选择任何内容的原因是因为选择过滤器具有隐式的 AND 逻辑,因此对象不能同时是TEXT MTEXT.

The reason that your code fails to select anything is because the selection filter has an implicit AND logic, hence an object cannot be both TEXT and MTEXT.

由于选择过滤器将允许通配符匹配,因此可以使用以下内容:

Since the selection filter will permit a wildcard match, you can use the following:

FilterType = win32com.client.VARIANT(VT_ARRAY|VT_I2, [0]) 
FilterData = win32com.client.VARIANT(VT_ARRAY|VT_VARIANT, ['TEXT,MTEXT'])
selection.SelectOnScreen(FilterType, FilterData)

或者,如果您不担心选择RTEXT的可能性:

Or, if you're not fussed about the possibility of selecting RTEXT:

FilterType = win32com.client.VARIANT(VT_ARRAY|VT_I2, [0]) 
FilterData = win32com.client.VARIANT(VT_ARRAY|VT_VARIANT, ['*TEXT'])
selection.SelectOnScreen(FilterType, FilterData)

您也可以将逻辑运算符<OROR>与组代码-4结合使用:

You can alternatively use the logical operators <OR and OR> in conjunction with the group code -4:

FilterType = win32com.client.VARIANT(VT_ARRAY|VT_I2, [-4, 0, 0, -4]) 
FilterData = win32com.client.VARIANT(VT_ARRAY|VT_VARIANT, ['<OR', 'TEXT', 'MTEXT', 'OR>'])
selection.SelectOnScreen(FilterType, FilterData)

这篇关于如何将此AutoCAD VBA代码转换为Python?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆