Catia 列表框项目

Catia Listbox items

我有这个任务,我需要找到某种类型的混合形状并将它们收集到列表框中 我已经完成了那部分,但是我需要以这样的方式创建它,即当用户从列表框中选择一个项目时,应在 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

中的对象之间创建 link

谢谢

您好,您可以将此添加到您的代码中并尝试一下。当心您的解决方案非常脆弱。您应该考虑对对象验证进行更可靠的检查

诀窍在于Shapebox点击事件中的ShapeBox.Value。剩下的只是catia的东西。但是这个解决方案并不是万无一失的,因为如果你有更多同名的形状,它可能 select 不是正确的。我更愿意创建一个集合,您可以在其中存储集合中的真实对象并将这些对象传递给 selection

    Private Sub ShapeBox_Click()
    
        Call opartdoc.Selection.Clear
        Call opartdoc.Selection.Add(opartdoc.Part.FindObjectByName(ShapeBox.Value))
    
    End Sub