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

Hi @paulo.correia98ZAP.  This is basically performing the same actions as @bradeneuropeArthur 's code, but lets you choose a directory/folder to process, instead of selecting multiple specific files.  It will then process all Part documents in that folder.  There is also a simple setting near the end of the oFiles() definition line, where you can change this from just processing the top/main directory, to then process all sub-folders if you wanted, but it is currently set to only process the top selected directory.  It uses a regular 'Open File' dialog, that is set up to only select a folder (glorified folder selection dialog.)

Sub Main
	Dim oTargetFolder As String = ChooseFolder
	Dim oFileNames As New List(Of String)
	Dim oFilter As String = "*.ipt"
	Dim oFiles() As String = System.IO.Directory.GetFiles(oTargetFolder, oFilter, IO.SearchOption.TopDirectoryOnly)
	oFileNames.AddRange(oFiles)
	If oFileNames.Count = 0 Then
		MsgBox("No files match the search criteria in the selected folder. Exiting.", , "")
		Exit Sub
	End If
	
	For Each oFile As String In oFiles
		Dim oPDoc As PartDocument = ThisApplication.Documents.Open(oFile, False)
		If oPDoc.ComponentDefinition.IsiPartMember Then
			oPDoc.ComponentDefinition.iPartMember.BreakLinkToFactory
			oPDoc.Save2(False)
			oPDoc.Close(True)
		Else
			'MsgBox(oFile & vbCrLf & "Is not an iPart.",,"")
			oPDoc.Close(True)
		End If
	Next
End Sub

Private Function ChooseFolder() As String
	Dim ThisApplication As Inventor.Application = GetObject(,"Inventor.Application")
	Dim oFolder As String = ""
	Dim oPlaceHolder As String = "PlaceHolderText"
	Dim oDirSepChar As Char = System.IO.Path.DirectorySeparatorChar
	Dim oOpenDlg As New System.Windows.Forms.OpenFileDialog
	oOpenDlg.Title = "Select A Folder."
	oOpenDlg.InitialDirectory = ThisApplication.DesignProjectManager.ActiveDesignProject.WorkspacePath
	oOpenDlg.Filter = ""
	oOpenDlg.Multiselect = False
	oOpenDlg.RestoreDirectory = False
	oOpenDlg.CheckFileExists = False
	oOpenDlg.CheckPathExists = True
	oOpenDlg.ValidateNames = False
	oOpenDlg.FileName = oPlaceHolder
	oOpenDlg.Filter = ""
	oOpenDlg.AddExtension = False
	oOpenDlg.DefaultExt = ""
	Dim oResult = oOpenDlg.ShowDialog
	If oResult = vbOK Then
		If oOpenDlg.FileName <> vbNullString Then
			oFolder = oOpenDlg.FileName
		Else
			MsgBox("No file was selected. Exiting.", vbOKOnly + vbExclamation, "FILE NOT SELECTED")
			Exit Function
		End If
	ElseIf oResult = vbCancel Then
		MsgBox("The dialog was Canceled. Exiting.", vbOKOnly + vbInformation, "CANCELED")
		Exit Function
	End If
	'count the number of characters from the end, until it finds the directory separator character
	Dim oPos As Integer = InStr(StrReverse(oFolder), oDirSepChar)
	'check if the directory separator character was at the end, if so, perfect, if not, eliminate end text
	If oPos <> 1 Then
		'the directory seperator character was not at the end, so...
		oFolder = Strings.Left(oFolder, InStrRev(oFolder, oDirSepChar))
	End If
	Return oFolder
End Function

Wesley Crihfield

EESignature

(Not an Autodesk Employee)