0

I wrote a macro that hides everything in several geometrical sets and the objects and geometrical sets in these first sets except one specific branch. I use this for saving a defined object of a huge and complicated specification tree as a STP file. (See attached below.)

(Small complication in this “Hide_and_Save” macro: adding bodies to my hide-selection works well but for my show-selection it didn’t work the same way. Why would this happen?)

I also wrote a macro that does iterative adjustments. For the iterations I use a Do While Loop and some parameters and measurements. To update these values, I have to update the part/object in every cycle. But there are some construction elements that issue errors until the loop is successfully completed. Therefore I deactivate all the geometrical sets that I don’t need for the iterations (inclusively all children) and later I reactivate them manually.

My goal is to improve automation, so I tried to use my “Hide_and_Save” macro for deactivation and reactivation. This didn’t work. When I record the process, each object is listed in a separate line and deactivated. Since there are more than 350 elements, I would like to avoid this.

How do I deactivate all subelements in a geometrical set (preferably with children) without addressing each element individually?

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

(Usually I work with Generative Shape Design and use VBA for Macros.)

Community
  • 1
  • 1
Christina
  • 13
  • 4

1 Answers1

0

Each feature has an "Activity" parameter aggregated to it.

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

Let me add that screwing with Activity of features is not a best practice. I NEVER do this myself. If you have access KBE (Specifically Knowledge Advisor Workbench) you can probably do what you want with Rules/Actions/Reactions, less coding and have a more robust model in the end.

C R Johnson
  • 964
  • 1
  • 5
  • 12
  • Thank you for your answer :). I have to check if I have access to KBE but I'll try it out if I do have. – Christina Jan 16 '20 at 21:48