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: 

Mutibody

13 REPLIES 13
Reply
Message 1 of 14
dhanshri_gavas
680 Views, 13 Replies

Mutibody

dhanshri_gavas
Contributor
Contributor

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

 

0 Likes

Mutibody

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

 

13 REPLIES 13
Message 2 of 14
WCrihfield
in reply to: dhanshri_gavas

WCrihfield
Mentor
Mentor

HI @dhanshri_gavas.  We may need more information from you.

  • Are you trying to do these things manually, or by code?
  • Are you only trying to do the export steps, or are you only trying to do the import steps, or are you actually trying to to both the export and the import steps?
  • What are you expecting to see in the part after bringing in 4 different exported bodies into it?
    • Is it OK if they are essentially on top of each other, or within each other's volumes, or do they need to be located and oriented in specific ways within the 3D coordinate space of the part?
  • Have you tried doing these things manually before?
    • If so, were your attempts successful?
    • Often, if we can do things manually, then we can find a way to do them by code, but if we can not do them manually, we often can not do them by code either.
  • Do 'links' or records need to be maintained between foreign files and Inventor files?

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes

HI @dhanshri_gavas.  We may need more information from you.

  • Are you trying to do these things manually, or by code?
  • Are you only trying to do the export steps, or are you only trying to do the import steps, or are you actually trying to to both the export and the import steps?
  • What are you expecting to see in the part after bringing in 4 different exported bodies into it?
    • Is it OK if they are essentially on top of each other, or within each other's volumes, or do they need to be located and oriented in specific ways within the 3D coordinate space of the part?
  • Have you tried doing these things manually before?
    • If so, were your attempts successful?
    • Often, if we can do things manually, then we can find a way to do them by code, but if we can not do them manually, we often can not do them by code either.
  • Do 'links' or records need to be maintained between foreign files and Inventor files?

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 14
chris
in reply to: dhanshri_gavas

chris
Advisor
Advisor

@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?

0 Likes

@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?

Message 4 of 14
chris
in reply to: dhanshri_gavas

chris
Advisor
Advisor

@dhanshri_gavas Have you tried the "make" components" option? Just right click on one of the "solids" and choose "make components".

0 Likes

@dhanshri_gavas Have you tried the "make" components" option? Just right click on one of the "solids" and choose "make components".

Message 5 of 14
WCrihfield
in reply to: dhanshri_gavas

WCrihfield
Mentor
Mentor

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

EESignature

(Not an Autodesk Employee)

0 Likes

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

EESignature

(Not an Autodesk Employee)

Message 6 of 14
chris
in reply to: dhanshri_gavas

chris
Advisor
Advisor

@WCrihfield is it not possible to write out as step or iges with iLogic?

0 Likes

@WCrihfield is it not possible to write out as step or iges with iLogic?

Message 7 of 14
chris
in reply to: dhanshri_gavas

chris
Advisor
Advisor

@dhanshri_gavas what software are you using the exported files in, if you don't mind me asking?

 

0 Likes

@dhanshri_gavas what software are you using the exported files in, if you don't mind me asking?

 

Message 8 of 14
WCrihfield
in reply to: chris

WCrihfield
Mentor
Mentor

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

EESignature

(Not an Autodesk Employee)

0 Likes

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

EESignature

(Not an Autodesk Employee)

Message 9 of 14
chris
in reply to: dhanshri_gavas

chris
Advisor
Advisor

@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.

0 Likes

@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.

Message 10 of 14
WCrihfield
in reply to: dhanshri_gavas

WCrihfield
Mentor
Mentor

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:

https://forums.autodesk.com/t5/inventor-programming-ilogic/export-multi-body-part-as-separate-stl/m-... 

https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-code-that-allows-to-export-an-indi... 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes

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:

https://forums.autodesk.com/t5/inventor-programming-ilogic/export-multi-body-part-as-separate-stl/m-... 

https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-code-that-allows-to-export-an-indi... 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 11 of 14

dhanshri_gavas
Contributor
Contributor

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.

0 Likes

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.

Message 12 of 14
WCrihfield
in reply to: dhanshri_gavas

WCrihfield
Mentor
Mentor

Hi @dhanshri_gavas.  I think you may be looking for the following API paths.

PartComponentDefinition 

PartComponentDefinition.ReferenceComponents 

ReferenceComponents 

ReferenceComponents.ImportedComponents 

ImportedComponents 

ImportedComponents.CreateDefinition 

ImportedComponentDefinition 

ImportedComponents.Add 

ImportedComponent 

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

EESignature

(Not an Autodesk Employee)

0 Likes

Hi @dhanshri_gavas.  I think you may be looking for the following API paths.

PartComponentDefinition 

PartComponentDefinition.ReferenceComponents 

ReferenceComponents 

ReferenceComponents.ImportedComponents 

ImportedComponents 

ImportedComponents.CreateDefinition 

ImportedComponentDefinition 

ImportedComponents.Add 

ImportedComponent 

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

EESignature

(Not an Autodesk Employee)

Message 13 of 14
chris
in reply to: dhanshri_gavas

chris
Advisor
Advisor

@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?

0 Likes

@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?

Message 14 of 14
WCrihfield
in reply to: chris

WCrihfield
Mentor
Mentor

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.

WCrihfield_1-1718022785893.png

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.

WCrihfield_0-1718022721372.png

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

EESignature

(Not an Autodesk Employee)

0 Likes

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.

WCrihfield_1-1718022785893.png

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.

WCrihfield_0-1718022721372.png

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

EESignature

(Not an Autodesk Employee)

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

Post to forums  

Autodesk Design & Make Report