Hi Team,
I am trying to export the separate step files for each bodies from part. So, if I have 4 bodies in part am creating 4 step files. now i want to insert all four in one as single part file using Inventor API.
Is there any workaround for this?
Thanks in advance
Hi Team,
I am trying to export the separate step files for each bodies from part. So, if I have 4 bodies in part am creating 4 step files. now i want to insert all four in one as single part file using Inventor API.
Is there any workaround for this?
Thanks in advance
HI @dhanshri_gavas. We may need more information from you.
Wesley Crihfield
(Not an Autodesk Employee)
HI @dhanshri_gavas. We may need more information from you.
Wesley Crihfield
(Not an Autodesk Employee)
@dhanshri_gavas Unless I'm reading this wrong, it appears you have a single part with multiple bodies and you want to export them each as an independent part, is this first part correct?
Then you want to bring those "same" exported parts back into Inventor? Is that correct?
@dhanshri_gavas Unless I'm reading this wrong, it appears you have a single part with multiple bodies and you want to export them each as an independent part, is this first part correct?
Then you want to bring those "same" exported parts back into Inventor? Is that correct?
@dhanshri_gavas Have you tried the "make" components" option? Just right click on one of the "solids" and choose "make components".
@dhanshri_gavas Have you tried the "make" components" option? Just right click on one of the "solids" and choose "make components".
On the export side of things, if doing the task by code, I see one primary way of exporting each individual part to another file type. Each body can be written out as either a SAT or SAB file type, with some variations available in those two file types. The following is an iLogic rule example that you may be able to use to test this, but those will not be STEP (".stp") files.
Sub Main
Dim oPDoc As PartDocument = TryCast(ThisDoc.Document, Inventor.PartDocument)
If oPDoc Is Nothing Then Return
Dim sPathAndName As String = ThisDoc.PathAndFileName(False)
If sPathAndName = "" Then
MsgBox("Save part first. (no file path or file name)", vbCritical, "iLogic")
Return
End If
Dim oPDef As PartComponentDefinition = oPDoc.ComponentDefinition
Dim oBodies As SurfaceBodies = oPDef.SurfaceBodies
If oBodies.Count > 0 Then
'these are the only options for exporting individual bodies using DataIO route (".sat" or ".sab")
Dim sFormat As String = "ACIS SAT"
'Dim sFormat As String = "ACIS SAB"
'Dim sFormat As String = "ACIS SAT with TransientKeys"
'Dim sFormat As String = "ACIS SAB with TransientKeys"
'Dim sFormat As String = "ACIS SAT with ProceduralToNURBS"
'Dim sFormat As String = "ACIS SAB with ProceduralToNURBS"
'Dim sFormat As String = "ACIS SAT ProceduralToNURBS with TransientKeys"
'Dim sFormat As String = "ACIS SAB ProceduralToNURBS with TransientKeys"
'Dim sFormat As String = "ACIS SAT ProceduralToNURBS with TransientKeys DocUnits"
'Dim sFormat As String = "ACIS SAB ProceduralToNURBS with TransientKeys DocUnits"
For Each oBody As SurfaceBody In oBodies
Dim sNewFile As String = sPathAndName & oBody.Name & ".sat"
oBody.DataIO.WriteDataToFile(sFormat, sNewFile)
Next oBody
End If
End Sub
Wesley Crihfield
(Not an Autodesk Employee)
On the export side of things, if doing the task by code, I see one primary way of exporting each individual part to another file type. Each body can be written out as either a SAT or SAB file type, with some variations available in those two file types. The following is an iLogic rule example that you may be able to use to test this, but those will not be STEP (".stp") files.
Sub Main
Dim oPDoc As PartDocument = TryCast(ThisDoc.Document, Inventor.PartDocument)
If oPDoc Is Nothing Then Return
Dim sPathAndName As String = ThisDoc.PathAndFileName(False)
If sPathAndName = "" Then
MsgBox("Save part first. (no file path or file name)", vbCritical, "iLogic")
Return
End If
Dim oPDef As PartComponentDefinition = oPDoc.ComponentDefinition
Dim oBodies As SurfaceBodies = oPDef.SurfaceBodies
If oBodies.Count > 0 Then
'these are the only options for exporting individual bodies using DataIO route (".sat" or ".sab")
Dim sFormat As String = "ACIS SAT"
'Dim sFormat As String = "ACIS SAB"
'Dim sFormat As String = "ACIS SAT with TransientKeys"
'Dim sFormat As String = "ACIS SAB with TransientKeys"
'Dim sFormat As String = "ACIS SAT with ProceduralToNURBS"
'Dim sFormat As String = "ACIS SAB with ProceduralToNURBS"
'Dim sFormat As String = "ACIS SAT ProceduralToNURBS with TransientKeys"
'Dim sFormat As String = "ACIS SAB ProceduralToNURBS with TransientKeys"
'Dim sFormat As String = "ACIS SAT ProceduralToNURBS with TransientKeys DocUnits"
'Dim sFormat As String = "ACIS SAB ProceduralToNURBS with TransientKeys DocUnits"
For Each oBody As SurfaceBody In oBodies
Dim sNewFile As String = sPathAndName & oBody.Name & ".sat"
oBody.DataIO.WriteDataToFile(sFormat, sNewFile)
Next oBody
End If
End Sub
Wesley Crihfield
(Not an Autodesk Employee)
@WCrihfield is it not possible to write out as step or iges with iLogic?
@WCrihfield is it not possible to write out as step or iges with iLogic?
@dhanshri_gavas what software are you using the exported files in, if you don't mind me asking?
@dhanshri_gavas what software are you using the exported files in, if you don't mind me asking?
Hi @chris. It is likely possible, but would require a lot more complication than usual, since we can not simply suppress individual SurfaceBody objects. We can turn their visibility on/off easily enough, but we would have to do something with the feature that created the body to eliminate the body. So, as you suggested, we could do the 'make part' type of process, just to get to the point where we have individual part files, then we could export those individual part files to STEP files, but that requires a lot of code work, and is not very efficient if only the STEP file is needed. The 'make part' essentially requires creating a new part document, then save it to a file, then deriving just that one body from the source part into the new part. Then once we export that individual part file out as a STEP file, we would need to get rid of the part file that we created along the way, and no longer need. And I am not 100% sure if the resulting exported STEP file model will retain its position & orientation from the original multi-body part, so that when importing each of the STEP files into one part again, they will end up in the same positions / orientations. All that is likely possible to handle by code, but would likely be a long and complex code, and still not absolutely sure if this is what is wanted/needed here until some questions get answered.
Wesley Crihfield
(Not an Autodesk Employee)
Hi @chris. It is likely possible, but would require a lot more complication than usual, since we can not simply suppress individual SurfaceBody objects. We can turn their visibility on/off easily enough, but we would have to do something with the feature that created the body to eliminate the body. So, as you suggested, we could do the 'make part' type of process, just to get to the point where we have individual part files, then we could export those individual part files to STEP files, but that requires a lot of code work, and is not very efficient if only the STEP file is needed. The 'make part' essentially requires creating a new part document, then save it to a file, then deriving just that one body from the source part into the new part. Then once we export that individual part file out as a STEP file, we would need to get rid of the part file that we created along the way, and no longer need. And I am not 100% sure if the resulting exported STEP file model will retain its position & orientation from the original multi-body part, so that when importing each of the STEP files into one part again, they will end up in the same positions / orientations. All that is likely possible to handle by code, but would likely be a long and complex code, and still not absolutely sure if this is what is wanted/needed here until some questions get answered.
Wesley Crihfield
(Not an Autodesk Employee)
@WCrihfield I know when exporting .stp and .iges to MODO, C4D the parts keep their position, that's why I asked what he was using them for. The reason I bought up the "create components" is that he made it sound like he wanted to export individual parts only to bring them back into Inventor, which at that point it doesn't make sense to export them.
@WCrihfield I know when exporting .stp and .iges to MODO, C4D the parts keep their position, that's why I asked what he was using them for. The reason I bought up the "create components" is that he made it sound like he wanted to export individual parts only to bring them back into Inventor, which at that point it doesn't make sense to export them.
I did figure out an easier way to do the export steps. Instead of needing to go through the whole 'make part' process for each body, we could simply manipulate the visibility of the bodies to make the one body we want to export visible, while making all other bodies not visible just before we export the whole original part document out to a STEP file each time, and the resulting STEP file will only contain the one visible body. I forgot that was possible with the STEP format, and assumed that suppression was the only way, but I was wrong.
I have attached two text files. Each one is the complete code for an iLogic rule that could be used just for the export task. #1 does it the easier way (with body visibility), and does it with the help of a TranslatorAddIn helper, so that you can specify options for the export to STEP file. Then #2 does it the 'make part' way, but does it with simple SaveAs methods, instead of the main translator, so no options input for the export. These are just examples, and I am sure they could be customized as needed. Nothing new either, because both routes have actually been discussed here on the forum before.
Edit: Here are some of the links to existing topics like this, just for the added references:
Wesley Crihfield
(Not an Autodesk Employee)
I did figure out an easier way to do the export steps. Instead of needing to go through the whole 'make part' process for each body, we could simply manipulate the visibility of the bodies to make the one body we want to export visible, while making all other bodies not visible just before we export the whole original part document out to a STEP file each time, and the resulting STEP file will only contain the one visible body. I forgot that was possible with the STEP format, and assumed that suppression was the only way, but I was wrong.
I have attached two text files. Each one is the complete code for an iLogic rule that could be used just for the export task. #1 does it the easier way (with body visibility), and does it with the help of a TranslatorAddIn helper, so that you can specify options for the export to STEP file. Then #2 does it the 'make part' way, but does it with simple SaveAs methods, instead of the main translator, so no options input for the export. These are just examples, and I am sure they could be customized as needed. Nothing new either, because both routes have actually been discussed here on the forum before.
Edit: Here are some of the links to existing topics like this, just for the added references:
Wesley Crihfield
(Not an Autodesk Employee)
Hi @chris,
I am using Inventor 2024 and saving as step file using Inventor API. I don't have an issue while exporting a single step file for each body that I have managed using C# code. now my issue is how I can import those steps files in a single part which was generated from part environment only (part having multiple bodies).
Because ideally there should be one part if I import.
Hi @chris,
I am using Inventor 2024 and saving as step file using Inventor API. I don't have an issue while exporting a single step file for each body that I have managed using C# code. now my issue is how I can import those steps files in a single part which was generated from part environment only (part having multiple bodies).
Because ideally there should be one part if I import.
Hi @dhanshri_gavas. I think you may be looking for the following API paths.
PartComponentDefinition.ReferenceComponents
ReferenceComponents.ImportedComponents
ImportedComponents.CreateDefinition
And below is an iLogic rule example code including that API object path, and a List(Of String) for holding multiple full path & name Strings for the files you want to import, so that they can very easily iterated through, once filled in. This code example could have also included the use of an Inventor.FileDialog for browsing for those files to import, but I suspect you may already know how to do that part, if needed.
Sub Main
Dim oPDoc As PartDocument = TryCast(ThisDoc.Document, Inventor.PartDocument)
If oPDoc Is Nothing Then
MsgBox("The iLogic rule named '" & iLogicVb.RuleName & "' exited, because no PartDocument was obtained.", vbCritical, "")
Exit Sub
End If
Dim oPDef As PartComponentDefinition = oPDoc.ComponentDefinition
Dim oImportedComps As Inventor.ImportedComponents = oPDef.ReferenceComponents.ImportedComponents
'<<< specify which files you want to import here >>>
Dim oFilesToImport As New List(Of String)
oFilesToImport.Add("C:\Temp\FileToImport1.stp")
oFilesToImport.Add("C:\Temp\FileToImport2.stp")
oFilesToImport.Add("C:\Temp\FileToImport3.stp")
oFilesToImport.Add("C:\Temp\FileToImport4.stp")
'<<< iterate through those file names and import them >>>
For Each sFileToImport In oFilesToImport
Dim oImportedCompDef As Inventor.ImportedComponentDefinition = Nothing
Try
oImportedCompDef = oImportedComps.CreateDefinition(sFileToImport)
Catch
Logger.Error("Error creating ImportedComponentDefinition from specified file!")
Continue For 'skip to next file name, if any
End Try
If oImportedCompDef Is Nothing Then Continue For 'skip to next file name, if any
Dim oImportedComp As Inventor.ImportedComponent = Nothing
Try
oImportedComp = oImportedComps.Add(oImportedCompDef)
Catch
Logger.Error("Error adding ImportedComponent based on definition from specified file!")
Continue For 'skip to next file name, if any
End Try
Next sFileToImport
oPDoc.Update2(True)
End Sub
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)
Hi @dhanshri_gavas. I think you may be looking for the following API paths.
PartComponentDefinition.ReferenceComponents
ReferenceComponents.ImportedComponents
ImportedComponents.CreateDefinition
And below is an iLogic rule example code including that API object path, and a List(Of String) for holding multiple full path & name Strings for the files you want to import, so that they can very easily iterated through, once filled in. This code example could have also included the use of an Inventor.FileDialog for browsing for those files to import, but I suspect you may already know how to do that part, if needed.
Sub Main
Dim oPDoc As PartDocument = TryCast(ThisDoc.Document, Inventor.PartDocument)
If oPDoc Is Nothing Then
MsgBox("The iLogic rule named '" & iLogicVb.RuleName & "' exited, because no PartDocument was obtained.", vbCritical, "")
Exit Sub
End If
Dim oPDef As PartComponentDefinition = oPDoc.ComponentDefinition
Dim oImportedComps As Inventor.ImportedComponents = oPDef.ReferenceComponents.ImportedComponents
'<<< specify which files you want to import here >>>
Dim oFilesToImport As New List(Of String)
oFilesToImport.Add("C:\Temp\FileToImport1.stp")
oFilesToImport.Add("C:\Temp\FileToImport2.stp")
oFilesToImport.Add("C:\Temp\FileToImport3.stp")
oFilesToImport.Add("C:\Temp\FileToImport4.stp")
'<<< iterate through those file names and import them >>>
For Each sFileToImport In oFilesToImport
Dim oImportedCompDef As Inventor.ImportedComponentDefinition = Nothing
Try
oImportedCompDef = oImportedComps.CreateDefinition(sFileToImport)
Catch
Logger.Error("Error creating ImportedComponentDefinition from specified file!")
Continue For 'skip to next file name, if any
End Try
If oImportedCompDef Is Nothing Then Continue For 'skip to next file name, if any
Dim oImportedComp As Inventor.ImportedComponent = Nothing
Try
oImportedComp = oImportedComps.Add(oImportedCompDef)
Catch
Logger.Error("Error adding ImportedComponent based on definition from specified file!")
Continue For 'skip to next file name, if any
End Try
Next sFileToImport
oPDoc.Update2(True)
End Sub
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)
@dhanshri_gavas Just to clarify, when a single ipt has multiple solid bodies, each body is treated as a separate mesh when exported. This is my daily workflow, as I mainly render my parts using MODO and C4D. This is actually a good thing, as it helps with selection in those programs for different materials, instead of selecting poly groups. A couple things can happen in Inventor to curb this:
1. you can combine solids before your export
2. You can create a derived part, leaving seams, and export that part
I have not tried @WCrihfield above code yet, @WCrihfield can you give a brief explanation of what that code is doing?
@dhanshri_gavas Just to clarify, when a single ipt has multiple solid bodies, each body is treated as a separate mesh when exported. This is my daily workflow, as I mainly render my parts using MODO and C4D. This is actually a good thing, as it helps with selection in those programs for different materials, instead of selecting poly groups. A couple things can happen in Inventor to curb this:
1. you can combine solids before your export
2. You can create a derived part, leaving seams, and export that part
I have not tried @WCrihfield above code yet, @WCrihfield can you give a brief explanation of what that code is doing?
Not sure if you wanted me to explain my codes in Message 10 or in Message 12, but I will assume Message 12 for now. It is doing a similar task to if you went to the Manage tab, Insert panel, and clicked on the 'Import' tool.
There is also this other, very similar manual tool that could be used, but this other one will always create a new document. That behavior could also be copied, but the code above is not. This other tool can be used if you go to the File menu, hovered your mouse over the Open arrow, then chose the 'Import CAD Files' tool.
Then chose changed the file filter to STEP files, then chose a few of them. But that code example did not include the 'browse for a file' functionality. Right now it just contains 4 hard-coded example file names, then the rest of the code focuses on the task of importing those files into the current part. That code example expects that the part you want to import them into is already open when you started the rule. But the code could definitely be expanded in many ways to add additional functionality, such as creating a new part to start with, or including a file browser routine.
Wesley Crihfield
(Not an Autodesk Employee)
Not sure if you wanted me to explain my codes in Message 10 or in Message 12, but I will assume Message 12 for now. It is doing a similar task to if you went to the Manage tab, Insert panel, and clicked on the 'Import' tool.
There is also this other, very similar manual tool that could be used, but this other one will always create a new document. That behavior could also be copied, but the code above is not. This other tool can be used if you go to the File menu, hovered your mouse over the Open arrow, then chose the 'Import CAD Files' tool.
Then chose changed the file filter to STEP files, then chose a few of them. But that code example did not include the 'browse for a file' functionality. Right now it just contains 4 hard-coded example file names, then the rest of the code focuses on the task of importing those files into the current part. That code example expects that the part you want to import them into is already open when you started the rule. But the code could definitely be expanded in many ways to add additional functionality, such as creating a new part to start with, or including a file browser routine.
Wesley Crihfield
(Not an Autodesk Employee)
Can't find what you're looking for? Ask the community or share your knowledge.