Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
insomnix
in reply to: insomnix

Since my original post and solution, I found an instance where the code did not function as expected. It took some time to figure out why it kept giving me the error "Object reference not set to an instance of an object." This error occurs when one or both items being constrained is a plane. It would probably error on a point or axis as well.

My first thought was to verify the object type, but the errors continued. That is when it occurred to me to verify that the object occurrence had a value. The code below is the result. Because of the way this is written, it will never change the suppression on a constraint of two planes. If anyone has a better function, please share.

 

Dim oDoc As AssemblyDocument = ThisDoc.Document
Dim oAsmDef As AssemblyComponentDefinition = oDoc.ComponentDefinition
Dim oConstrs As AssemblyConstraints = oAsmDef.Constraints

For Each oConstr As AssemblyConstraint In oConstrs		
	If Not IsNothing(oConstr.OccurrenceOne) And Not IsNothing(oConstr.OccurrenceTwo) Then
    	    If oConstr.OccurrenceOne.Suppressed = True Or oConstr.OccurrenceTwo.Suppressed = True Then
	        oConstr.Suppressed = True
	    Else
	        oConstr.Suppressed = False
	    End If
	ElseIf Not IsNothing(oConstr.OccurrenceOne) And IsNothing(oConstr.OccurrenceTwo) Then
	    If oConstr.OccurrenceOne.Suppressed = True Then
	        oConstr.Suppressed = True
	    Else
	        oConstr.Suppressed = False
	    End If
	ElseIf IsNothing(oConstr.OccurrenceOne) And Not IsNothing(oConstr.OccurrenceTwo) Then
	    If oConstr.OccurrenceTwo.Suppressed = True Then
	        oConstr.Suppressed = True
	    Else
	        oConstr.Suppressed = False
	    End If
	End If
Next