How to Check if a CSYS is used for assembly constraint

I have a pattern of CSYS, and each CSYS is supposed to have specifica component based on a criteria.

I am thinking of (step1)running a check if each CSYS of each instance of the pattern is used as a component constraint reference, (step2)if not then add the component.

I was able to figure out step2, can you please help me with code for step1 or suggest if there is another better approach ?

The following code looks through the constraints in the part and reports some info on each. If the constraint references a datum csys owned by the assembly, it flags it with the line:
** constraint references a datum csys from the assembly

Imports System
Imports NXOpen

Module Module1
Sub Main(ByVal args() As String)

Dim theSession As NXOpen.Session = NXOpen.Session.GetSession()
Dim lw As ListingWindow = theSession.ListingWindow

lw.Open()
If IsNothing(theSession.Parts.Work) Then
Return
End If

If theSession.Parts.Work.ComponentAssembly.Positioner.Constraints.ToArray.Length = 0 Then
lw.WriteLine("no constraints in work part")
Return
Else
lw.WriteLine(theSession.Parts.Work.ComponentAssembly.Positioner.Constraints.ToArray.Length.ToString & " constraints in work part")
End If
lw.WriteLine("")

For Each temp As Positioning.Constraint In theSession.Parts.Work.ComponentAssembly.Positioner.Constraints
'lw.WriteLine("constraint status: " & temp.GetConstraintStatus.ToString)
lw.WriteLine("constraint type: " & temp.ConstraintType.ToString)
Dim conRefs() As Positioning.ConstraintReference = temp.GetReferences
For Each conRef As Positioning.ConstraintReference In conRefs
Dim constraintGeo As NXObject = conRef.GetGeometry
lw.WriteLine(" constraint geometry: " & constraintGeo.GetType.ToString)
If constraintGeo.IsOccurrence Then
'geometry owned by a component
lw.WriteLine(" owned by component: " & constraintGeo.OwningComponent.Name)
Else
'geometry owned by the assembly part
lw.WriteLine(" owned by assembly: " & constraintGeo.OwningPart.Leaf)
'check to see if the geometry belongs to a feature
Dim geoFeature As Features.Feature = theSession.Parts.Work.Features.GetAssociatedFeature(constraintGeo)
If IsNothing(geoFeature) Then
'nothing to see here
Continue For
End If
If TypeOf (geoFeature) Is Features.DatumCsys Then
lw.WriteLine("** constraint references a datum csys from the assembly")
End If
End If
Next
lw.WriteLine("")
Next

End Sub
End Module

Thanks for the IsOccurrence example. Looks like it is more efficient way of doing it.

I also worked out another method that collects that ProtoType Geometry Tags from all the solved constraints in the assembly-> into a list and then another list that contains the CSYS object tags of the patterns' CSYS instances. This approach suited how the pattern features were modelled my workpart.

Partial codes for below:

LoadRelatedGeometry();

NXOpen.Positioning.Constraint[] AssemblyConstraints = theSession.Parts.Work.ComponentAssembly.Positioner.Constraints.ToArray();

foreach(NXOpen.Positioning.Constraint constraint in AssemblyConstraints)
{
if(constraint.GetConstraintStatus().ToString() == "Solved")
{
NXOpen.Positioning.ConstraintReference[] ConstraintReferences = constraint.GetReferences();
SolvedConstraintCSYSTags.Add(ProtoTag(ConstraintReferences[0]));
SolvedConstraintCSYSTags.Add(ProtoTag(ConstraintReferences[1]));
}
}

2nd partial code that is doing the comparison

for (int b = 0; b <= InstanceOrientationList.Length - 2; b++)
{
if (SolvedConstraintCSYSTags.Contains(EntitiesCSYSTag(workPart.Features.FindObject(ChildOfPointPatternInstances[b]))) == true)
{
lw.WriteLine("Instance " + ChildOfPointPatternInstances[b] + " was found in SolvedConstraintsList");
}
else
{
//Add Component
}
}

BH