【发布时间】:2019-04-25 00:54:51
【问题描述】:
我正在尝试在 CATIA 中进行一些设计自动化。我正在使用 python,然后我在 CATIA 中记录宏并将那里的代码转换为 python 代码。现在我偶然发现了一个问题。
下面是我想翻译成 pyhton 代码的 CATIA 宏。
Language="VBSCRIPT"
Sub CATMain()
Set productDocument1 = CATIA.ActiveDocument
Set product1 = productDocument1.Product
Set product1 = product1.ReferenceProduct
Set constraints1 = product1.Connections("CATIAConstraints")
Set reference1 = product1.CreateReferenceFromName("ContainerSchiff/Container1/!yz plane")
Set reference2 = product1.CreateReferenceFromName("ContainerSchiff/Container0/!Geometrical Set.1/Point.2")
----Here is the problem ---- Set constraint1 = constraints1.AddBiEltCst(catCstTypeDistance, reference1, reference2)
Set length1 = constraint1.Dimension
length1.Value = 300.000000
product1.Update
End Sub
翻译时我不知道如何处理catCstTypeDistance
如果我保持原样,那么 python 显然会抱怨名称未定义。如果我将它作为字符串传递也会抱怨。下面是python的部分
else:
add_container_skeleton(product1,i)
product1.ReferenceProduct
constraints1=product1.Connections("CATIAConstraints")
Name1="ContainerSchiff/Container" + str(i-1) + "/!Container1/yz plane"
Name2="ContainerSchiff/Container" + str(i) + "/!Geometrical Set.1/Point.2"
reference1= product1.CreateReferenceFromName(Name1)
reference2 = product1.CreateReferenceFromName(Name2)
constraint1 = constraints1.AddBiEltCst('catCstTypeDistance', reference1, reference2)
length1 = constraint1.Dimension
length1.Value = 300.000000
以及我收到的两条不同的错误消息。
File "C:\Users\Mange\Documents\LIU\Catia part 2\first_draft.py", line 179, in place_containers
constraint1 = constraints1.AddBiEltCst('catCstTypeDistance', reference1, reference2)
File "<COMObject Connections>", line 3, in AddBiEltCst
ValueError: invalid literal for int() with base 10: 'catCstTypeDistance'
File "C:\Users\Mange\Documents\LIU\Catia part 2\first_draft.py", line 179, in place_containers
constraint1 = constraints1.AddBiEltCst(catCstTypeDistance(), reference1, reference2)
NameError: name 'catCstTypeDistance' is not defined
我怎样才能从 python 中“访问”这个东西/对象(?)?
【问题讨论】:
-
这是一个很好的问题。标题可能更适合搜索,因为“评估 CATIA 对象”在 CATIA 自动化中具有特定含义——它指的是获取 CATIA 应用程序对象。更好的标题可能是“使用 Python 在 CATIA 中创建注释”或“使用 Python 时的 Catia 枚举值”