我有这个任务,我需要找到某种类型的混合形状,并将它们收集在列表框中我已经完成了这一部分,但我需要以这样的方式创建它,当用户从列表框中选择一个项目时,相应的混合形状或对象应该在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 IntegerPrivate Sub UserForm_Initialize()
Set ODoc = CATIA.ActiveDocument
Set opartdoc = CATIA.ActiveDocument
Set oPart = opartdoc.PartEnd 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 = 25Next
End Sub
Private Sub SelectBtn_Click()
End Sub
我对列表框的处理不太了解,如何在列表框中的项和catia中的对象之间创建链接
谢谢
发布于 2021-07-31 16:55:20
您好,您可以将此代码添加到您的代码中并尝试它。当心你的解决方案是相当脆弱的。您应该考虑对对象验证进行更健壮的检查
诀窍在于Shapebox点击事件中的ShapeBox.Value。剩下的都是catia的东西。但是这个解决方案并不是万无一失的,因为如果你有更多同名的形状,它可能不会选择正确的形状。我更喜欢创建一个集合,在其中存储集合中的真实对象,并将这些对象传递给selection
Private Sub ShapeBox_Click()
Call opartdoc.Selection.Clear
Call opartdoc.Selection.Add(opartdoc.Part.FindObjectByName(ShapeBox.Value))
End Subhttps://stackoverflow.com/questions/68600252
复制相似问题