vbacatia

Activation of deactivated features


I'm attempting to activate the deactivated features.
I think if I get a Feature.activity parameter and change it to True from False, then I can activate all the decativated features.

Sub CATMain()

' On Error Resume Next

Dim partDocument1 As Document
Set partDocument1 = CATIA.ActiveDocument

Dim part1 As Part
Set part1 = partDocument1.Part

If Err.Number = 0 Then
    Dim selection1 As Selection
    Set selection1 = partDocument1.Selection
    
    'selection1.Search "CATPrtSearch.PartDesignFeature.Activity=FALSE,all"
    selection1.Search "CATPrtSearch.MechanicalFeature.Activity=FALSE,all"

    If selection1.Count = 0 Then
        MsgBox "No deactivated features"
        Exit Sub
 
    Else
        If MsgBox("The number of deactivated components is : " & selection1.Count & vbNewLine & "Click yes to activate or click no to exit.", vbYesNo) = vbYes Then
            
            For i = 1 To selection1.Count

**                'selection1.Item2(i).Activate

                selection1.Item2(i).MechanicalFeature.Activity=TRUE              
             
                'selection1.Item2(i).Value.Activity = True**
                
            Next 'i

            part1.Update

        End If

    End If

Else
    MsgBox "Not a part document! Open a single part document."
End If

End Sub

Solution

  • To active a feature you can use the method Activate from the part object. e.g.

    part1.Activate(selection1.Item2(i).Value)
    

    Be aware, if e.g. a sketch of a pad is also deacivated you get an error (your search doesn`t include sketches)