如何在 CATIA 中使用 CATscript 翻译零件?
How to translate a part using CATscript in CATIA?
我在 CATIA 中使用 CATscript 创建宏。我正在尝试创建一个 CATscript 来翻译 CATIA 中的一个功能。
当我 运行 CATscript 时,我应该 select 应该翻译的功能,并且该功能将被翻译。
但我收到 运行时间错误 类型不匹配:'part1.CreateReferenceFromObject'
我找不到这个问题的解决方案。
期待您的帮助。
提前致谢。
Sub CATMain()
Set partDocument1 = CATIA.ActiveDocument
Set part1 = partDocument1.Part
Set hybridShapeFactory1 = part1.HybridShapeFactory
Set hybridShapeDirection1 = hybridShapeFactory1.AddNewDirectionByCoord(1.000000, 0.000000, 0.000000)
Set hybridShapeTranslate1 = hybridShapeFactory1.AddNewEmptyTranslate()
Set UserSel = partDocument1.Selection
Dim type1(0)
type1(0) = "HybridShape"
'--------------------------------------
'Dim input As Object
input = UserSel.SelectElement2(type1, "select input.", False)
Set reference1 = part1.CreateReferenceFromObject(input)
hybridShapeTranslate1.ElemToTranslate = reference1
hybridShapeTranslate1.Direction = hybridShapeDirection1
hybridShapeTranslate1.DistanceValue = 1.000000
Set hybridBody2 = hybridBodies1.Item("Geometrical Set.3")
hybridBody2.AppendHybridShape hybridShapeTranslate1
part1.InWorkObject = hybridShapeTranslate1
part1.Update
End Sub
您的问题是您正试图从 Selection 对象创建引用。
input = UserSel.SelectElement2(type1, "select input.", False)
此 returns 类型选择。您可以深入研究输入并获得您 select.
的实际对象
尝试:
Dim myReference as Reference
Dim myExpectedObject as HybridShape 'or use variant
Set mySelectedObject = input.Item2(1).Value 'this will grab the first item from the selection collection
set myReference = part1.CreateReferenceFromObject(mySelectedObject)
'continue the rest of your code
此外,在使用用户 selection 之前,您应该始终清除 selection 作为一个好习惯。
UserSel.Clear 'call this before you call a SelectElement selection function
我在 CATIA 中使用 CATscript 创建宏。我正在尝试创建一个 CATscript 来翻译 CATIA 中的一个功能。
当我 运行 CATscript 时,我应该 select 应该翻译的功能,并且该功能将被翻译。
但我收到 运行时间错误 类型不匹配:'part1.CreateReferenceFromObject'
我找不到这个问题的解决方案。 期待您的帮助。
提前致谢。
Sub CATMain()
Set partDocument1 = CATIA.ActiveDocument
Set part1 = partDocument1.Part
Set hybridShapeFactory1 = part1.HybridShapeFactory
Set hybridShapeDirection1 = hybridShapeFactory1.AddNewDirectionByCoord(1.000000, 0.000000, 0.000000)
Set hybridShapeTranslate1 = hybridShapeFactory1.AddNewEmptyTranslate()
Set UserSel = partDocument1.Selection
Dim type1(0)
type1(0) = "HybridShape"
'--------------------------------------
'Dim input As Object
input = UserSel.SelectElement2(type1, "select input.", False)
Set reference1 = part1.CreateReferenceFromObject(input)
hybridShapeTranslate1.ElemToTranslate = reference1
hybridShapeTranslate1.Direction = hybridShapeDirection1
hybridShapeTranslate1.DistanceValue = 1.000000
Set hybridBody2 = hybridBodies1.Item("Geometrical Set.3")
hybridBody2.AppendHybridShape hybridShapeTranslate1
part1.InWorkObject = hybridShapeTranslate1
part1.Update
End Sub
您的问题是您正试图从 Selection 对象创建引用。
input = UserSel.SelectElement2(type1, "select input.", False)
此 returns 类型选择。您可以深入研究输入并获得您 select.
的实际对象尝试:
Dim myReference as Reference
Dim myExpectedObject as HybridShape 'or use variant
Set mySelectedObject = input.Item2(1).Value 'this will grab the first item from the selection collection
set myReference = part1.CreateReferenceFromObject(mySelectedObject)
'continue the rest of your code
此外,在使用用户 selection 之前,您应该始终清除 selection 作为一个好习惯。
UserSel.Clear 'call this before you call a SelectElement selection function