问题描述
我有这个任务,我需要找到某种类型的混合形状并将它们收集在列表框中 我已经完成了那部分,但我需要以这样一种方式创建它,当用户从列表框中选择一个项目时,应该在 catia 中选择相应的混合形状或对象 这是图片
这是代码
Option Explicit
Dim odoc As Document
Dim opartdoc As PartDocument
Dim oPart As Part
Dim ohybs As HybridBodies
Dim ohyb As HybridBody
Dim ohybshps As HybridShapes
Dim ohybshp As HybridShape
Dim i As Integer
Dim j As Integer
Private Sub UserForm_Initialize()
Set odoc = CATIA.ActiveDocument
Set opartdoc = CATIA.ActiveDocument
Set oPart = opartdoc.Part
End Sub
Private Sub ListBtn_Click()
Set ohybs = oPart.HybridBodies
Set ohyb = ohybs.Item("Shapes")
Set ohybshps = ohyb.HybridShapes
For i = 1 To ohybshps.Count
Set ohybshp = ohybshps.Item(i)
ShapeBox.AddItem ohybshp.Name
ShapeBox.Font.Bold = True
ShapeBox.Font.Size = 25
Next
End Sub
Private Sub SelectBtn_Click()
End Sub
我不太了解列表框处理 如何在列表框中的项目和 catia 中的对象之间创建链接
谢谢
解决方法
您好,您可以将此添加到您的代码中并尝试一下。请注意,您的解决方案非常脆弱。您应该考虑对对象验证进行更可靠的检查
诀窍在于 Shapebox 点击事件中的 ShapeBox.Value
。其余的只是catia的东西。但是这个解决方案并不是万无一失的,因为如果您有更多同名的形状,它可能无法选择正确的形状。我更喜欢创建一个集合,您可以在其中存储集合中的真实对象并将这些对象传递给选择
Private Sub ShapeBox_Click()
Call opartdoc.Selection.Clear
Call opartdoc.Selection.Add(opartdoc.Part.FindObjectByName(ShapeBox.Value))
End Sub