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

Found the problem, for future people, this code lets you:

- Select a windows folder

- It will find all .ipt files in it

- Mirror all the .ipt files, regardless if they are  a single or multibody part

- Save the .ipt files as COPY into a new folder called "Output"

- Dont forget to set your own part template file location in the code

 

Imports System.Windows.Forms
Imports System
Sub Main
	
	oInvApp = ThisApplication
	Dim oTemplate As String = '.IPT TEMPLATE FILE e.g. "X\Templates\Partemplate.ipt"
	
	Dim oFBD = New FolderBrowserDialog()
	oFBD.ShowDialog()
	Dim oSFolder = oFBD.SelectedPath	
	If String.IsNullOrEmpty(oSFolder) Then Exit Sub
	Dim oFiles() As String = IO.Directory.GetFiles(oSFolder, "*.ipt")
	If oFiles.Length = 0 Then Exit Sub
	Dim i As Integer = 0 
		For Each oFile In oFiles
			Dim oFileName As String = IO.Path.GetFileName(oFiles(i))
			Dim oFileNameWE As String = IO.Path.GetFileNameWithoutExtension(oFiles(i))
			Call MirDer(oFiles(i), oFileNameWE, oSFolder)
			i = i + 1
		Next
End Sub
	
	Dim oInvApp = ThisApplication
	
Private Function MirDer(ByVal oFileName As String, ByVal oFileNameWE As String, ByVal oSFolder As String)
	
	Dim CopyDoc As PartDocument = oInvApp.Documents.Add(kPartDocumentObject, oTemplate, False)
	Dim oPCD As Inventor.PartComponentDefinition = CopyDoc.ComponentDefinition
	Dim oDPD As Inventor.DerivedPartDefinition 
	oDPD = oPCD.ReferenceComponents.DerivedPartComponents.CreateUniformScaleDef(oFileName)
	oDPD.IncludeAllSolids = DerivedComponentOptionEnum.kDerivedIncludeAll
	
	
	oDPD.MirrorPlane = kDerivedPartMirrorPlaneXY
	
	Dim oDPC As DerivedPartComponent = oPCD.ReferenceComponents.DerivedPartComponents.Add(oDPD)
 	oDPC.BreakLinkToFile()
	
	CopyDoc.Update()
	
	Dim OutputFolder As IO.DirectoryInfo = IO.Directory.CreateDirectory(oSFolder & "\Output")
	CopyDoc.SaveAs(OutputFolder.FullName & "\" & oFileNameWE & "_MIRROR_.ipt", False)
	CopyDoc.Close(True)
	
End Function