This ended up being the best solution and I finally got it working.
The key was swapping out the adaptive occurrence first and then setting ComponentOccurrence.LocalAdaptive = True. Without that line, every adaptive part would still become not adaptive even though the locals window still showed Adaptive = True.
Dim curDoc As Document
' Open the document
' rpFile is the replacement filename, determined elsewhere in code
Set curDoc = ThisApplication.Documents.Open(rpFile, False)
' Loop to replace adaptive occurrences first
Dim loopOcc As ComponentOccurrence
If curDoc.DocumentType = kAssemblyDocumentObject Then
For Each loopOcc In curDoc.ComponentDefinition.Occurrences
If loopOcc.Adaptive Then
Call loopOcc.Replace2(GetReplacementFile(loopOcc.ReferencedFileDescriptor.FullFileName), False, , True)
loopOcc.LocalAdaptive = True
End If
Next
End If
' Next replace all file references
If curDoc.file.ReferencedFileDescriptors.Count > 0 Then
For Each fd In curDoc.file.ReferencedFileDescriptors
' ReplaceReferences is another function that opens up each referenced file and does the same thing, checks for an adaptive occurrence, replaces it, then replaces file descriptors, then recursively opens each file and keeps looping until it makes its way through all the sub-assemblies of each level.
ReplaceReferences fd
Next fd
End If
ReplaceReferences function below
Private Sub ReplaceReferences(fd As FileDescriptor)
Dim rpFile As String
rpFile = GetReplacementFile(fd.FullFileName)
If Not rpFile = "" Then
fd.ReplaceReference rpFile
Dim curDoc As Document
Set curDoc = ThisApplication.Documents.Open(rpFile, False)
If Len(curDoc.DisplayName) > 4 Then
'Reset Part Number
'EDITED WP 4-29-21
curDoc.PropertySets("Design Tracking Properties")("Part Number").value = Left(curDoc.DisplayName, Len(curDoc.DisplayName) - 4)
End If
' Loop to replace adaptive occurrences first
Dim loopOcc As ComponentOccurrence
If curDoc.DocumentType = kAssemblyDocumentObject Then
For Each loopOcc In curDoc.ComponentDefinition.Occurrences
If loopOcc.Adaptive Then
Call loopOcc.Replace2(GetReplacementFile(loopOcc.ReferencedFileDescriptor.FullFileName), False, , True)
loopOcc.LocalAdaptive = True
End If
Next
End If
If curDoc.Dirty = True Then
curDoc.Save2
End If
If curDoc.file.ReferencedFileDescriptors.Count > 0 Then
Dim sFD As FileDescriptor
For Each sFD In curDoc.file.ReferencedFileDescriptors
ReplaceReferences sFD
Next sFD
End If
If curDoc.Dirty = True Then
curDoc.Save2
End If
curDoc.Close
End If
End Sub