Hi @mcm-autodesk. I think I may have something that you can try out. I would copy/paste this into a new/different iLogic rule, instead of overwriting your existing rule, just for safety, because this is slightly different process than your other code was doing. I have attempted to incorporate all of the file naming conventions that you mentioned. I have not tested this myself yet though, so be cautious when testing. I also incorporated a question in the middle of the loop, which will ask you if the new file name looks OK to you, before proceeding to save the new file out. You can get rid of this whole question part later, after you have made sure the name is being formatted the way you want it. I also removed the lines of code that were opening and closing the referenced documents, because those will already be open anyways, because they are loaded into memory when you open the assembly. And they can't be truly closed until that assembly is closed, and there are no other references to those documents.
If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
MsgBox("An Assembly Document must be active for this rule to work. Exiting.",vbCritical, "WRONG DOCUMENT TYPE")
Exit Sub
End If
Dim oADoc As AssemblyDocument = ThisDoc.Document
Dim oOccs As ComponentOccurrences = oADoc.ComponentDefinition.Occurrences
Dim oAsmName As String = System.IO.Path.GetFileNameWithoutExtension(oADoc.FullFileName)
Dim oPath As String = System.IO.Path.GetDirectoryName(oADoc.FullFileName) & "\STEP Files\"
If Not System.IO.Directory.Exists(oPath) Then
System.IO.Directory.CreateDirectory(oPath)
End If
oADoc.SaveAs(oPath & oAsmName & ".stp", True)
Dim oPos As Integer = 0
For Each oRefDoc As Document In oADoc.AllReferencedDocuments
'all referenced documents are already open in memory (may not be visible though)
'get quantity of assembly components representing this referenced document
Dim oQty As Integer = oOccs.AllReferencedOccurrences(oRefDoc).Count
oPos = oPos + 1
Dim oNewFullName As String = oPath & oAsmName & "-P" & Format(oPos, "00") & "-" & oQty & "X" & ".stp"
oAns = MsgBox("Is this OK?" & vbCrLf & "Original FullFileName:" & vbCrLf & oRefDoc.FullFileName _
& vbCrLf & "STEP FullFileName:" & oNewFullName, vbYesNo + vbQuestion, "New Name OK?")
If oAns = vbYes Then
Try
oRefDoc.SaveAs(oNewFullName, True)
Catch
MsgBox("Failed to save '" & oRefDoc.FullFileName & " out as an STEP file.", , "")
End Try
End If
Next
MsgBox("All new STEP files were saved to:" & vbCrLf & oPath, vbOKOnly,"FINISHED")
If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.
Wesley Crihfield

(Not an Autodesk Employee)