@simone.custodi
I'd say your best option would be to create your own "Make Components"-function in iLogic instead of calling the controldefinition.
See example below.
You'll get prompted to save the assembly and then the parts will be saved in the same directory.
In this code I use the template names:
Standard.iam
Standard.ipt
Sheet Metal.ipt
If your templates have different names you must replace the names in the code.
Try it and let me know how it works for you 🙂
If ThisDoc.PathAndFileName(False) = ""
MessageBox.Show("Save multibody part before running this rule!", "Part is not saved", _
MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If
Dim oFileDlg As Inventor.FileDialog
ThisApplication.CreateFileDialog(oFileDlg)
oFileDlg.Filter = "Inventor Assembly files|*.iam"
oFileDlg.CancelError = False
oFileDlg.OptionsEnabled = False
oFileDlg.ShowSave
If oFileDlg.FileName = "" Then Exit Sub
Dim oAsm As AssemblyDocument = ThisApplication.Documents.Add(DocumentTypeEnum.kAssemblyDocumentObject, _
ThisApplication.DesignProjectManager.ActiveDesignProject.TemplatesPath & "Standard.iam", True)
oAsm.FullFileName = oFileDlg.FileName
Dim oDoc As PartDocument = ThisDoc.Document
Dim oSurfBods As SurfaceBodies = oDoc.ComponentDefinition.SurfaceBodies
For Each oBod As SurfaceBody In oSurfBods
Dim oPart As PartDocument = ThisApplication.Documents.Add(DocumentTypeEnum.kPartDocumentObject, If (TypeOf (oBod.ComponentDefinition) Is SheetMetalComponentDefinition, _
ThisApplication.DesignProjectManager.ActiveDesignProject.TemplatesPath & "Sheet Metal.ipt", ThisApplication.DesignProjectManager.ActiveDesignProject.TemplatesPath & "Standard.ipt"), False)
Dim DerComps As DerivedPartComponents = oPart.ComponentDefinition.ReferenceComponents.DerivedPartComponents
Dim DerDef As DerivedPartDefinition = DerComps.CreateUniformScaleDef(oDoc.FullFileName)
For Each oSolid As DerivedPartEntity In DerDef.Solids
oSolid.IncludeEntity = If (oSolid.ReferencedEntity Is oBod, True, False)
Next
DerComps.Add(DerDef)
If TypeOf (oPart.ComponentDefinition) Is SheetMetalComponentDefinition
Try
oPart.ComponentDefinition.SheetMetalStyles(oDoc.ComponentDefinition.GetBodySheetMetalStyle(oBod).Name).Activate
Catch
End Try
End If
Dim i As Integer = 0
While True
Try
If i = 0
oPart.SaveAs(System.IO.Path.GetDirectoryName(oFileDlg.FileName) & "\" & oBod.Name & ".ipt", False)
Else
oPart.SaveAs(System.IO.Path.GetDirectoryName(oFileDlg.FileName) & "\" & oBod.Name & "_" & i & ".ipt", False)
End If
Exit While
Catch
i += 1
End Try
End While
oAsm.ComponentDefinition.Occurrences.Add(oPart.FullFileName, ThisApplication.TransientGeometry.CreateMatrix).Grounded = True
Next
oAsm.Activate