Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Automate derive from .step file to single body .ipt file

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
Daan_M
305 Views, 8 Replies

Automate derive from .step file to single body .ipt file

Hi,

 

I have: A folder with 200 .step files of assemblies with multiple bodies.

I want: A folder with 200 .ipt files containing a single body.

 

How i go about this manually:

 

1. Import the .step file into Inventor, this results into a .iam file which i save in the same folder

2. Open a new .ipt file and use 'Derive', select the saved .iam i want and use option 'combine into one body'.

3. Break the derive link and save the .ipt file which now contains a single body

 

This is alot of clicking to repeat for 200 files.

Does anyone know a way to automate this?

8 REPLIES 8
Message 2 of 9
Andrii_Humeniuk
in reply to: Daan_M

Hi @Daan_M . Change the path to your template file (line 24).

 

Imports System.Windows.Forms

Sub main
	oInvApp = ThisApplication
	oProject = oInvApp.DesignProjectManager.ActiveDesignProject
	Dim sPathFolder As String = GetPathFolder(oProject.WorkspacePath)
	If String.IsNullOrEmpty(sPathFolder) Then Exit Sub
	Dim sFiles() As String = System.IO.Directory.GetFiles(sPathFolder & "\", "*.STEP")
	If sFiles.Length = 0 Then Exit Sub
    Dim oPB As Inventor.ProgressBar
	oPB = oInvApp.CreateProgressBar(False, sFiles.Length - 1, "Create parts from step files...")
    oPB.Message = ("Loading...")
	For i As Integer = 0 To sFiles.Length - 1
		Dim oNewAsmName As String = CreateAssemblyFromSTEP(sFiles(i))
		If String.IsNullOrEmpty(oNewAsmName) Then Continue For
		Call CreatePartDriveAsm(oNewAsmName, sFiles(i))
        oPB.Message = ("Create part from step file. Progress " & i & " of " & sFiles.Length - 1 & ".")
        oPB.UpdateProgress
	Next i
	oPB.Close()
End Sub

Dim oInvApp As Inventor.Application
Dim sTemplate As String = "\\Comp59\Work SP\Templates\ru-RU\КТВ_Деталь.ipt"

Private Function GetPathFolder(ByVal sPathStart As String) As String
	Dim Dialog = New FolderBrowserDialog()
	Dialog.SelectedPath = sPathStart
	If DialogResult.OK = Dialog.ShowDialog() Then
		Return Dialog.SelectedPath
	End If
	Return Nothing
End Function

Private Function CreateAssemblyFromSTEP(ByVal sPathFile As String) As String
	Dim oDoc As Document = oInvApp.Documents.Open(sPathFile, False)
	oDoc.Save()
	oDoc.Close(True)
	Return oDoc.FullFileName
End Function

Private Function CreatePartDriveAsm(ByVal oNewAsmName As String, ByVal sPathFile As String)
	Dim oDerivedAssemblyDef As DerivedAssemblyDefinition
	Dim oPDoc As PartDocument = oInvApp.Documents.Add(kPartDocumentObject, sTemplate, False)
	Dim oRefComps As ReferenceComponents = oPDoc.ComponentDefinition.ReferenceComponents
	oDerivedAssemblyDef = oRefComps.DerivedAssemblyComponents.CreateDefinition(oNewAsmName)
	oDerivedAssemblyDef.DeriveStyle = DerivedComponentStyleEnum.kDeriveAsMultipleBodies
	oDerivedAssemblyDef.IncludeAllTopLevelWorkFeatures = DerivedComponentOptionEnum.kDerivedExcludeAll
	oDerivedAssemblyDef.IncludeAllTopLevelSketches = DerivedComponentOptionEnum.kDerivedExcludeAll
	oDerivedAssemblyDef.IncludeAllTopLeveliMateDefinitions = DerivedComponentOptionEnum.kDerivedExcludeAll
	oDerivedAssemblyDef.IncludeAllTopLevelParameters = DerivedComponentOptionEnum.kDerivedExcludeAll
	Dim oDerivedAss As DerivedAssemblyComponent
	oDerivedAss = oRefComps.DerivedAssemblyComponents.Add(oDerivedAssemblyDef)
	Call oDerivedAss.BreakLinkToFile()
	oPDoc.SaveAs(System.IO.Path.ChangeExtension(sPathFile, "(Part).ipt"), False)
	oPDoc.Close(True)
End Function

 

 

Andrii Humeniuk - Leading design engineer

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

Message 3 of 9
Daan_M
in reply to: Andrii_Humeniuk

@Andrii_Humeniuk Thank you, great code, i restructed it a bit and changed some text for my case.

 

 

Imports System.Windows.Forms
Sub Main
	
	oInvApp = ThisApplication
	oProject = oInvApp.DesignProjectManager.ActiveDesignProject
	Dim sPathFolder As String = GetPathFolder(oProject.WorkspacePath)
		
		If String.IsNullOrEmpty(sPathFolder) Then 
			
			MsgBox("geen folder geselecteerd")
			Exit Sub
			
		End If

'/// STEP ///

Dim sFiles() As String = System.IO.Directory.GetFiles(sPathFolder & "\", "*.STEP")
	
	If sFiles.Length = 0 Then 
		Exit Sub
	End If
    
	Dim oPB As Inventor.ProgressBar
	oPB = oInvApp.CreateProgressBar(False, sFiles.Length - 1, "Parts aanmaken uit STP files...")
    oPB.Message = ("Even geduld...")
	
	For i As Integer = 0 To sFiles.Length - 1
		
		Dim oNewAsmName As String = CreateAssemblyFromSTEP(sFiles(i))
'		If String.IsNullOrEmpty(oNewAsmName) Then Continue For
	
		Call CreatePartDriveAsm(oNewAsmName, sFiles(i))
        
		oPB.Message = ("Bezig met " & i & " of " & sFiles.Length - 1 & ".")
        oPB.UpdateProgress
	
	Next i
	
	oPB.Close()
	
End Sub

Dim oInvApp As Inventor.Application
Dim sTemplate As String = "X:\CAD_3D\00 - Inventor standaard (NIET AANKOMEN)\Templates\Metric\Standard (mm).ipt"

Private Function GetPathFolder(ByVal sPathStart As String) As String
	
	Try
	
		Dim Dialog = New FolderBrowserDialog()
		Dialog.SelectedPath = sPathStart
		If DialogResult.OK = Dialog.ShowDialog() Then
			Return Dialog.SelectedPath
		End If
	
	Return Nothing
	
	Catch
		Exit Function
	End Try
	
End Function

Private Function CreateAssemblyFromSTEP(ByVal sPathFile As String) As String
	
'	Try
		
		Dim oDoc As Document = oInvApp.Documents.Open(sPathFile, False)
		oDoc.Save()

		If oDoc.DocumentType = kPartDocumentObject Then
		Dim Svar As Integer = 1
		Return Svar
		End If

		oDoc.Close(True)

	Return oDoc.FullFileName
	
'	Catch
'		Exit Function
'	End Try
	
End Function

Private Function CreatePartDriveAsm(ByVal oNewAsmName As String, ByVal sPathFile As String)

'Try
	
	Dim oDerivedAssemblyDef As DerivedAssemblyDefinition
	Dim oPDoc As PartDocument = oInvApp.Documents.Add(kPartDocumentObject, sTemplate, False)
	Dim oRefComps As ReferenceComponents = oPDoc.ComponentDefinition.ReferenceComponents
	
	oDerivedAssemblyDef = oRefComps.DerivedAssemblyComponents.CreateDefinition(oNewAsmName)
	oDerivedAssemblyDef.DeriveStyle = DerivedComponentStyleEnum.kDeriveAsMultipleBodies
	oDerivedAssemblyDef.IncludeAllTopLevelWorkFeatures = DerivedComponentOptionEnum.kDerivedExcludeAll
	oDerivedAssemblyDef.IncludeAllTopLevelSketches = DerivedComponentOptionEnum.kDerivedExcludeAll
	oDerivedAssemblyDef.IncludeAllTopLeveliMateDefinitions = DerivedComponentOptionEnum.kDerivedExcludeAll
	oDerivedAssemblyDef.IncludeAllTopLevelParameters = DerivedComponentOptionEnum.kDerivedExcludeAll
	
	Dim oDerivedAss As DerivedAssemblyComponent
	oDerivedAss = oRefComps.DerivedAssemblyComponents.Add(oDerivedAssemblyDef)
	
	Call oDerivedAss.BreakLinkToFile()
	oPDoc.SaveAs(System.IO.Path.ChangeExtension(sPathFile, "SIMPLIFIED.ipt"), False)
	oPDoc.Close(True)
	
'	Catch
'		Exit Function
'	End Try
	
End Function

 

 

I have two additional questions;

 

1. some of the .STEP files are translated to a Partdocument instead of an Assembly document. This causes a problem in the function below, since it expects the file to be an assembly and not a part.

Private Function CreatePartDriveAsm

 It would be ok to skip this function for the most part, and it just saved the partfile directly as is.

How can i best do this?

 

2. The output is a bit messy at the moment;

Daan_M_1-1695298420695.png

 

Green = original .STEP file in my folder

Blue = The folder Inventor creates when saving the translated .STEP file to a native assembly.

Red = The output i need

Yellow = All the parts from the assemblies after translation from .STEP

 

Yellow and Blue can be deleted i just need the orinals files (Green) and the output (Red) to be left in the folder

 

 

 

 

 

 

Message 4 of 9
Andrii_Humeniuk
in reply to: Daan_M

I wrote the code according to my template, but added your changes to it. In case, if an .ipt was created after converting the STEP file, it will be renamed to "SIMPLIFIED.ipt" if the ".iam" is followed by the old actions. Added DeleteDontNeedFile function to delete ".iam" folder.

Imports System
Imports System.Windows.Forms
Sub main
	oInvApp = ThisApplication
	oProject = oInvApp.DesignProjectManager.ActiveDesignProject
	Dim sPathFolder As String = GetPathFolder(oProject.WorkspacePath)
	If String.IsNullOrEmpty(sPathFolder) Then Exit Sub
	Dim sFiles() As String = IO.Directory.GetFiles(sPathFolder & "\", "*.STEP")
	If sFiles.Length = 0 Then Exit Sub
    Dim oPB As Inventor.ProgressBar
	oPB = oInvApp.CreateProgressBar(False, sFiles.Length - 1, "Parts aanmaken uit STP files...")
    oPB.Message = ("Even geduld...")
	For i As Integer = 0 To sFiles.Length - 1
		Dim oNewAsmName As String = CreateAssemblyFromSTEP(sFiles(i))
		If String.IsNullOrEmpty(oNewAsmName) Then Continue For
		Call CreatePartDrive(oNewAsmName, sFiles(i))
		Call DeleteDontNeedFile(oNewAsmName)
        oPB.Message = ("Bezig met " & i & " of " & sFiles.Length - 1 & ".")
        oPB.UpdateProgress
	Next i
	oPB.Close()
	Shell("explorer.exe /Open," & sPathFolder, vbNormalFocus)
End Sub

Dim oInvApp As Inventor.Application
Dim sTemplate As String = "X:\CAD_3D\00 - Inventor standaard (NIET AANKOMEN)\Templates\Metric\Standard (mm).ipt"

Private Function GetPathFolder(ByVal sPathStart As String) As String
	Dim Dialog = New FolderBrowserDialog()
	Dialog.SelectedPath = sPathStart
	If DialogResult.OK = Dialog.ShowDialog() Then
		Return Dialog.SelectedPath
	End If
	Return Nothing
End Function

Private Function CreateAssemblyFromSTEP(ByVal sPathFile As String) As String
	Dim oDoc As Document = oInvApp.Documents.Open(sPathFile, False)
	oDoc.Save()
	oDoc.Close(True)
	Return oDoc.FullFileName
End Function

Private Function CreatePartDrive(ByVal oNewAsmName As String, ByVal sPathFile As String)
	If IO.Path.GetExtension(oNewAsmName) = ".ipt" Then
		IO.Path.ChangeExtension(oNewAsmName, "SIMPLIFIED.ipt")
	Else If IO.Path.GetExtension(oNewAsmName) = ".iam" Then	
		Dim oPDoc As PartDocument = oInvApp.Documents.Add(kPartDocumentObject, sTemplate, False)
		Dim oRefComps As ReferenceComponents = oPDoc.ComponentDefinition.ReferenceComponents	
		Dim oDerivedAssemblyDef As DerivedAssemblyDefinition
		oDerivedAssemblyDef = oRefComps.DerivedAssemblyComponents.CreateDefinition(oNewAsmName)
		oDerivedAssemblyDef.DeriveStyle = DerivedComponentStyleEnum.kDeriveAsMultipleBodies
		oDerivedAssemblyDef.IncludeAllTopLevelWorkFeatures = DerivedComponentOptionEnum.kDerivedExcludeAll
		oDerivedAssemblyDef.IncludeAllTopLevelSketches = DerivedComponentOptionEnum.kDerivedExcludeAll
		oDerivedAssemblyDef.IncludeAllTopLeveliMateDefinitions = DerivedComponentOptionEnum.kDerivedExcludeAll
		oDerivedAssemblyDef.IncludeAllTopLevelParameters = DerivedComponentOptionEnum.kDerivedExcludeAll
		Dim oDerivedAss As DerivedAssemblyComponent
		oDerivedAss = oRefComps.DerivedAssemblyComponents.Add(oDerivedAssemblyDef)
		Call oDerivedAss.BreakLinkToFile()
		oPDoc.SaveAs(IO.Path.ChangeExtension(sPathFile, "SIMPLIFIED.ipt"), False)
		oPDoc.Close(True)
	End If
End Function

Private Function DeleteDontNeedFile(ByVal oNewAsmName As String)
	If IO.Path.GetExtension(oNewAsmName) = ".iam" Then
		Dim sDirectory As String = IO.Path.GetDirectoryName(oNewAsmName)
		Try : IO.Directory.Delete(sDirectory, True)
		Catch : MessageBox.Show(sDirectory, "Failed to delete folder!") : End Try
	End If
End Function

 In my situation the Inventor put all the build files in one folder so all I had to do was delete the folder, if you have parts being created outside of the folder then let me know and I will make changes to the DeleteDontNeedFile function.

Andrii Humeniuk - Leading design engineer

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

Message 5 of 9
Daan_M
in reply to: Andrii_Humeniuk

This works perfectly, thank you!

Message 6 of 9
Daan_M
in reply to: Andrii_Humeniuk

Hi @Andrii_Humeniuk,

 

I made a few slight adjustments, all parts get moved to the 'Outputs folder' now (red).

 

Daan_M_1-1695648765354.png

 

Problem: if the STEP/STP file contains a part, then a subfolder is created automatically by Inventor, the result part gets put in there, instead of the original path. So this part will remain in the subfolder (blue) and not moved to the 'Outputs' folder.

 

Full Code

 

 

Imports System
Imports System.Windows.Forms
Sub main
	
	oInvApp = ThisApplication
	oProject = oInvApp.DesignProjectManager.ActiveDesignProject
	Dim sPathFolder As String = GetPathFolder(oProject.WorkspacePath)
	If String.IsNullOrEmpty(sPathFolder) Then Exit Sub
		
	Dim oExtensions(1) As String
	oExtensions(0) = "*.STP"
	oExtensions(1) = "*.STEP"
	
	For Each Extension In oExtensions
		
	Dim sFiles() As String = IO.Directory.GetFiles(sPathFolder & "\", Extension)
	If sFiles.Length = 0 Then Exit Sub
    
	Dim oPB As Inventor.ProgressBar
	oPB = oInvApp.CreateProgressBar(False, sFiles.Length - 1, "Parts aanmaken & Solids hernoemen...")
    oPB.Message = ("Even geduld...")
	
	For i As Integer = 0 To sFiles.Length - 1
		Dim oNewAsmName As String = CreateAssemblyFromSTEP(sFiles(i))
		If String.IsNullOrEmpty(oNewAsmName) Then Continue For
		Call CreatePartDrive(oNewAsmName, sFiles(i))
		Call DeleteDontNeedFile(oNewAsmName)
        oPB.Message = ("Bezig met " & i + 1 & " of " & sFiles.Length & ".")
        oPB.UpdateProgress
	Next i
	
	'hier worden alleen parts aangepakt
	
	Dim iptFiles() As String = IO.Directory.GetFiles(sPathFolder & "\", "*.ipt")
	For i As Integer = 0 To iptFiles.Length - 1
		Dim oCleanNames As String = CleanNames(iptFiles(i))
	Next i
	

	oPB.Close()
	Shell("explorer.exe /Open," & sPathFolder, vbNormalFocus)
	
Next

Dim OutputFolder As IO.DirectoryInfo = IO.Directory.CreateDirectory(sPathFolder & "\Outputs")
	
Dim AllPartFiles() As String = IO.Directory.GetFiles(sPathFolder & "\", "*.ipt")

For Each PartFile As String In AllPartFiles
	Dim Destination As String = OutputFolder.FullName & "\" & IO.Path.GetFileName(PartFile)
	IO.File.Move(PartFile, Destination)	
Next
		


End Sub

Dim oInvApp As Inventor.Application
Dim sTemplate As String = "X:\CAD_3D\00 - Inventor standaard (NIET AANKOMEN)\Templates\Metric\Standard (mm).ipt"

Private Function GetPathFolder(ByVal sPathStart As String) As String
	Dim Dialog = New FolderBrowserDialog()
	Dialog.SelectedPath = sPathStart
	If DialogResult.OK = Dialog.ShowDialog() Then
		Return Dialog.SelectedPath
	End If
	Return Nothing
End Function

Private Function CleanNames(ByVal sPathFile As String) As String
	Dim oDoc As Inventor.Document = oInvApp.Documents.Open(sPathFile, False)
		Dim oPCD As PartComponentDefinition = oDoc.ComponentDefinition		
		Dim oFeature As PartFeature
		i = 1
		For Each oFeature In oPCD.Features
		oFeature.Name = "BodyReset" & i
		i = i + 1
		Next
		oDoc.Save()
		oDoc.Close(True)
End Function

Private Function CreateAssemblyFromSTEP(ByVal sPathFile As String) As String

Dim oDoc As Document = oInvApp.Documents.Open(sPathFile, False)
	
	If oDoc.DocumentType = kAssemblyDocumentObject Then
		Dim i As Integer = 1
	Dim oAsmCompDef As AssemblyComponentDefinition = oDoc.ComponentDefinition
	Dim oOcc As ComponentOccurrence
	For Each oOcc In oAsmCompDef.Occurrences
		oOcc.Name = "BodyReset" & i
		i = i + 1
		Next
	End If
	oDoc.Save()
	oDoc.Close(True)
	Return oDoc.FullFileName
End Function

Private Function CreatePartDrive(ByVal oNewAsmName As String, ByVal sPathFile As String)

	If IO.Path.GetExtension(oNewAsmName) = ".ipt" Then
		IO.Path.ChangeExtension(oNewAsmName, ".ipt") 'Simplified
	Else If IO.Path.GetExtension(oNewAsmName) = ".iam" Then		
		Dim oPDoc As PartDocument = oInvApp.Documents.Add(kPartDocumentObject, sTemplate, False)
		Dim oRefComps As ReferenceComponents = oPDoc.ComponentDefinition.ReferenceComponents	
		Dim oDerivedAssemblyDef As DerivedAssemblyDefinition
		oDerivedAssemblyDef = oRefComps.DerivedAssemblyComponents.CreateDefinition(oNewAsmName)
		oDerivedAssemblyDef.DeriveStyle = DerivedComponentStyleEnum.kDeriveAsMultipleBodies
		oDerivedAssemblyDef.IncludeAllTopLevelWorkFeatures = DerivedComponentOptionEnum.kDerivedExcludeAll
		oDerivedAssemblyDef.IncludeAllTopLevelSketches = DerivedComponentOptionEnum.kDerivedExcludeAll
		oDerivedAssemblyDef.IncludeAllTopLeveliMateDefinitions = DerivedComponentOptionEnum.kDerivedExcludeAll
		oDerivedAssemblyDef.IncludeAllTopLevelParameters = DerivedComponentOptionEnum.kDerivedExcludeAll
		Dim oDerivedAss As DerivedAssemblyComponent
		oDerivedAss = oRefComps.DerivedAssemblyComponents.Add(oDerivedAssemblyDef)
		Call oDerivedAss.BreakLinkToFile()
		oPDoc.SaveAs(IO.Path.ChangeExtension(sPathFile, ".ipt"), False) ' simplified
		oPDoc.Close(True)
	End If
	
End Function

Private Function DeleteDontNeedFile(ByVal oNewAsmName As String)
	If IO.Path.GetExtension(oNewAsmName) = ".iam" Then ' simplified
		Dim sDirectory As String = IO.Path.GetDirectoryName(oNewAsmName)
		Try : IO.Directory.Delete(sDirectory, True)
		Catch : MessageBox.Show(sDirectory, "Kan folder niet verwijderen") : End Try
	End If
End Function

 

 

 

 

Message 7 of 9
Andrii_Humeniuk
in reply to: Daan_M

Hi @Daan_M . Unfortunately, I was unable to reproduce your situation. In my case, Assembly files are constantly being created. But I've optimized your code anyway, and added a line of code (79-81) that I hope will help you. It checks where the .ipt file is located and moves it if necessary.

Imports System
Imports System.Windows.Forms
Sub Main
	
	oInvApp = ThisApplication
	oProject = oInvApp.DesignProjectManager.ActiveDesignProject
	Dim sPathFolder As String = GetPathFolder(oProject.WorkspacePath)
	If String.IsNullOrEmpty(sPathFolder) Then Exit Sub
		
	Dim sFiles() As String = IO.Directory.GetFiles(sPathFolder & "\").Where(Function(s) {".STP", ".STEP" }.
							Contains(IO.Path.GetExtension(s))).OrderBy(Function(s) IO.Path.GetFileName(s)).ToArray()
	If sFiles.Length = 0 Then Exit Sub
    
	Dim oPB As Inventor.ProgressBar
	oPB = oInvApp.CreateProgressBar(False, sFiles.Length, "Parts aanmaken & Solids hernoemen...")
    oPB.Message = ("Even geduld...")
	oPB.UpdateProgress
	
	For i As Integer = 0 To sFiles.Length - 1
		Dim oNewAsmName As String = CreateComponentFromSTEP(sFiles(i))
		If String.IsNullOrEmpty(oNewAsmName) Then Continue For
		Call CreatePartDrive(oNewAsmName, sFiles(i))
		Call DeleteDontNeedFile(oNewAsmName)
        oPB.Message = ("Bezig met " & i + 1 & " of " & sFiles.Length & ".")
        oPB.UpdateProgress
	Next i
	
	oPB.Message = "hier worden alleen parts aangepakt"
	oPB.UpdateProgress
	
	Dim OutputFolder As IO.DirectoryInfo = IO.Directory.CreateDirectory(sPathFolder & "\Outputs")		
	Dim AllPartFiles() As String = IO.Directory.GetFiles(sPathFolder & "\", "*.ipt")
	
	For Each PartFile As String In AllPartFiles
		Dim Destination As String = OutputFolder.FullName & "\" & IO.Path.GetFileName(PartFile)
		IO.File.Move(PartFile, Destination)	
	Next

	oPB.Close()
	Shell("explorer.exe /Open," & sPathFolder, vbNormalFocus)
	
End Sub

Dim oInvApp As Inventor.Application
Dim sTemplate As String = "X:\CAD_3D\00 - Inventor standaard (NIET AANKOMEN)\Templates\Metric\Standard (mm).ipt"

Private Function GetPathFolder(ByVal sPathStart As String) As String
	Dim Dialog = New FolderBrowserDialog()
	Dialog.SelectedPath = sPathStart
	If DialogResult.OK = Dialog.ShowDialog() Then
		Return Dialog.SelectedPath
	End If
	Return Nothing
End Function

Private Function CreateComponentFromSTEP(ByVal sPathFile As String) As String

	Dim oDoc As Document = oInvApp.Documents.Open(sPathFile, False)	
	If oDoc.DocumentType = kAssemblyDocumentObject Then
		Dim oAsmCompDef As AssemblyComponentDefinition = oDoc.ComponentDefinition
		For i As Integer = 1 To oAsmCompDef.Occurrences.Count
			oAsmCompDef.Occurrences(i).Name = "BodyReset" & i
		Next i
	Else
		Dim oPCD As PartComponentDefinition = oDoc.ComponentDefinition
		For i As Integer = 1 To oPCD.Features.Count
			oPCD.Features(i).Name = "BodyReset" & i
		Next i
	End If
	oDoc.Save()
	oDoc.Close(True)
	Return oDoc.FullFileName
	
End Function

Private Function CreatePartDrive(ByVal oNewAsmName As String, ByVal sPathFile As String)

	If IO.Path.GetExtension(oNewAsmName) = ".ipt" Then
		If IO.Path.GetDirectoryName(oNewAsmName) <> sPathFile Then
			IO.File.Move(oNewAsmName, sPathFile & "\" & IO.Path.GetFileName(oNewAsmName))
		End If
	Else If IO.Path.GetExtension(oNewAsmName) = ".iam" Then		
		Dim oPDoc As PartDocument = oInvApp.Documents.Add(kPartDocumentObject, sTemplate, False)
		Dim oRefComps As ReferenceComponents = oPDoc.ComponentDefinition.ReferenceComponents	
		Dim oDerivedAssemblyDef As DerivedAssemblyDefinition
		oDerivedAssemblyDef = oRefComps.DerivedAssemblyComponents.CreateDefinition(oNewAsmName)
		oDerivedAssemblyDef.DeriveStyle = DerivedComponentStyleEnum.kDeriveAsMultipleBodies
		oDerivedAssemblyDef.IncludeAllTopLevelWorkFeatures = DerivedComponentOptionEnum.kDerivedExcludeAll
		oDerivedAssemblyDef.IncludeAllTopLevelSketches = DerivedComponentOptionEnum.kDerivedExcludeAll
		oDerivedAssemblyDef.IncludeAllTopLeveliMateDefinitions = DerivedComponentOptionEnum.kDerivedExcludeAll
		oDerivedAssemblyDef.IncludeAllTopLevelParameters = DerivedComponentOptionEnum.kDerivedExcludeAll
		Dim oDerivedAss As DerivedAssemblyComponent
		oDerivedAss = oRefComps.DerivedAssemblyComponents.Add(oDerivedAssemblyDef)
		Call oDerivedAss.BreakLinkToFile()
		oPDoc.SaveAs(IO.Path.ChangeExtension(sPathFile, ".ipt"), False) ' simplified
		oPDoc.Close(True)
	End If
	
End Function

Private Function DeleteDontNeedFile(ByVal oNewAsmName As String)
	If IO.Path.GetExtension(oNewAsmName) = ".iam" Then ' simplified
		Dim sDirectory As String = IO.Path.GetDirectoryName(oNewAsmName)
		Try : IO.Directory.Delete(sDirectory, True)
		Catch : MessageBox.Show(sDirectory, "Kan folder niet verwijderen") : End Try
	End If
End Function

 

 

Andrii Humeniuk - Leading design engineer

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

Message 8 of 9
Daan_M
in reply to: Andrii_Humeniuk

Almost there, the code gives an error  "on line 81 in rule: Could not find a part of the path."

 which is on line: 

IO.File.Move(oNewAsmName, sPathFile & "\" & IO.Path.GetFileName(oNewAsmName))

To understand better i put in a msgbox before the error giving the file location and the desired location:

MsgBox("current location: " & oNewAsmName & "    desired location: " & sPathFile & "\" & IO.Path.GetFileName(oNewAsmName))

With result:

 

 

Daan_M_0-1695806671492.png

But the "ADM1.STP\" part needs to be left out.


I tried fixing it but my understanding of programming only goes so far 😅

 

Message 9 of 9
Andrii_Humeniuk
in reply to: Daan_M

My mistake, this should help you:

IO.File.Move(oNewAsmName, IO.Path.GetDirectoryName(sPathFile) & "\" & IO.Path.GetFileName(oNewAsmName))

 

Andrii Humeniuk - Leading design engineer

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators


Autodesk Design & Make Report