• Blog posts

    Bio

    By Scott Cunliffe

    Does it bother you that you can’t suppress a component’s constraints at the same you suppress the part or sub-assembly?  Here’s some iLogic code to help you do just that:

    'This iLogic code originally appeared on Cadline Community
    'https://www.cadlinecommunity.co.uk/hc/en-us/articles/214079065
     
    Dim oDoc As AssemblyDocument = ThisDoc.Document
    Dim oAsmDef As AssemblyComponentDefinition = oDoc.ComponentDefinition
    Dim oConstrs As AssemblyConstraints = oAsmDef.Constraints
     
    'Cycle through each selected component
    For Each oOcc In oDoc.SelectSet
            
        'Cycle through each constraint in the assembly
        For Each oConstr As AssemblyConstraint In oConstrs
                
            'Compare the component suppression state with the constraint
            If oConstr.Suppressed = oOcc.Suppressed Then
                
                'Suppress the constraint if the first half is the component            
                 Try
                    If oConstr.OccurrenceOne.Name = oOcc.Name Then
                        Constraint.IsActive(oConstr.Name) = _
                           Not Constraint.IsActive(oConstr.Name)
                    End If
                Catch
                End Try
                
                'Suppress the constraint if the second half is the component
                Try        
                    If oConstr.OccurrenceTwo.Name = oOcc.Name Then
                        Constraint.IsActive(oConstr.Name) = _
                           Not Constraint.IsActive(oConstr.Name)
                    End If
                Catch
                End Try
        
            End If
            
        Next
        
        'Finally suppress the component
        Component.IsActive(oOcc.Name) = Not Component.IsActive(oOcc.Name)
        
    Next

    The code above will toggle suppression to the opposite of the current state.  Multi-selections of varying suppression will not normalise the suppression as per the right click context menu, where the icon would show a square.

    It is worth noting that for every component selected, we have to cycle through every constraint in the assembly to check if it is being used in that constraint.  The constraint is effectively above the component in hierarchical terms.  The result is that the code may take longer to finish in larger assemblies.

    The code above is devoid of any of the usual checks required to prevent failure.  You can find the full version below.