如何自动停用和重新激活多个几何集和对象?

我写了一个宏,它隐藏了几个几何集合中的所有内容,并隐藏了除了一个特定分支之外的这些第一集合中的对象和几何集合。我将其用于将庞大而复杂的规范树的已定义对象另存为STP文件。 (请参阅下面的附件。)

(此“ Hide_and_Save”宏中的小并发症:将主体添加到我的隐藏选择中效果很好,但对于我的显示选择,它却没有同样的效果。为什么会这样?

我还写了一个进行迭代调整的宏。对于迭代,我使用“ Do While循环”以及一些参数和测量值。要更新这些值,我必须在每个循环中更新零件/对象。但是有一些构造元素会发出错误,直到循环成功完成。因此,我停用了所有不需要的几何图形集(包括所有子项),后来又手动将其重新激活。

我的目标是提高自动化程度,因此我尝试使用“ Hide_and_Save”宏进行停用和重新激活。这没用。在记录过程时,每个对象都在单独的行中列出并被停用。既然有350多个元素,我想避免这种情况。

如何在不单独处理每个元素的情况下停用几何集中的所有子元素(最好带有子元素)?

Attribute VB_Name = "Hide_and_Save"

'_______________________________________________________________________________________

'Title:         Hide_and_Save
'Language:      catvba
'_______________________________________________________________________________________

Sub CATMain()
'---------------------------------------------------------------------------------------

    'Select active Part/Document
    Dim myDocument As Document
    Set myDocument = CATIA.activeDocument
    Dim myPart As part
    Set myPart = CATIA.activeDocument.part

    '--------------------------------------------------------------

    ' Enter file path
    Dim filepath As String
    filepath = InputBox("Please select memory location","Input filepath","...")
    If filepath = "" Then 'cancle,abort or empty input
        MsgBox "No valid input / cancle !"
        Exit Sub
    End If

    '--------------------------------------------------------------

    ' Hide/show Objects of Part/Products and save as STEP

    ' Update Model
    CATIA.activeDocument.part.Update

    ' Deklaration of Selections and Properties
    Dim selectionShow,selectionHide As Selection
    Set selectionShow = myDocument.Selection
    Set selectionHide = myDocument.Selection

    Dim visPropertySetShow,visPropertySetHide As VisPropertySet
    Set visPropertySetShow = selectionShow.VisProperties
    Set visPropertySetHide = selectionHide.VisProperties

    ' Definition of the collection of geometric sets - HybridBodies
    Dim hybridBodiesInPart,hybridBodiesInProcess As HybridBodies
    Dim hybridBodiesInRS,hybridBodiesInHuelle As HybridBodies

    ' Definition of individual geometric sets - HybridBody
    Dim hybridBodyInPart,hybridBodyProcess,hybridBodyInProcess As HybridBody
    Dim hybridBodyRS,hybridBodyInRS As HybridBody
    Dim hybridBodyHuelle,hybridBodyInHuelle As HybridBody

    ' Definition of the collection of 3D-objects - HybridShapes
    Dim hybridShapesInHuelle As HybridShapes

    ' Definition of individual 3D-objects - HybridShape
    Dim hybridShapeInHuelle,hybridShapeForm As HybridShape

    ' Hide objects
    Set hybridBodiesInPart = myPart.HybridBodies
    For Each hybridBodyInPart In hybridBodiesInPart
        selectionHide.Add hybridBodyInPart
    Next

    Set hybridBodyProcess = hybridBodiesInPart.Item("Process")
    Set hybridBodiesInProcess = hybridBodyProcess.HybridBodies
    For Each hybridBodyInProcess In hybridBodiesInProcess
        selectionHide.Add hybridBodyInProcess
    Next

    Set hybridBodyHuelle = hybridBodiesInProcess.Item("Huelle")
    Set hybridBodiesInHuelle = hybridBodyHuelle.HybridBodies
    For Each hybridBodyInHuelle In hybridBodiesInHuelle
        selectionHide.Add hybridBodyInHuelle
    Next

    Set hybridShapesInHuelle = hybridBodyHuelle.HybridShapes
    For Each hybridShapeInHuelle In hybridShapesInHuelle
        selectionHide.Add hybridShapeInHuelle
    Next

    Set hybridShapeForm = hybridShapesInHuelle.Item("Form")

    visPropertySetHide.SetShow 1 'hide
    selectionHide.Clear

    ' Show objects
    selectionShow.Add hybridBodyProcess
    selectionShow.Add hybridBodyHuelle
    selectionShow.Add hybridShapeForm       
    visPropertySetShow.SetShow 0 'show
    selectionShow.Clear

    ' Data export as STP
    stepAnswer = MsgBox("Should the displayed elements be saved as STEP?",3 + 0,"Export: Form")
    If stepAnswer = 6 Then
        myDocument.ExportData filepath & "Form" & ".stp","stp"
    ElseIf stepAnswer = 3 Or stepAnswer = 2 Then 'cancle or abort
        MsgBox "cancle !"
        Exit Sub
    End If

'---------------------------------------------------------------------------------------

    MsgBox "Finished !" & vbCrLf & s

End Sub

(通常,我使用Generative Shape Design,并将VBA用于宏。)

a277158272 回答:如何自动停用和重新激活多个几何集和对象?

每个功能都具有一个“活动”参数。

Dim oShape as HybridShape
For Each oShape In oGS.HybridShapes
    Dim oActivity as Parameter
    Set oActivity = oPart.Parameters.SubList(oShape,False).Item("Activity")
    Call oActivity.ValuateFromString("False")
Next

让我补充一点,拧紧“功能的活动”不是最佳实践。我永远不会自己做。如果您具有KBE(特别是Knowledge Advisor工作台)访问权限,则可以使用“规则/动作/反应”来完成所需的工作,减少编码并最终获得更可靠的模型。

本文链接:https://www.f2er.com/2788289.html

大家都在问