Deriving multi-body-part files into merged solid part files

Deriving multi-body-part files into merged solid part files

Daan_M
Collaborator Collaborator
192 Views
3 Replies
Message 1 of 4

Deriving multi-body-part files into merged solid part files

Daan_M
Collaborator
Collaborator

Hi,

 

I have a folder with around 100 .ipt files, each file consisting of multiple solid bodies.

I would like iLogic to make a copy of each of these files in a new folder, where it merges the solid bodies of the original file into one solid.

 

I figured using the 'Derive' functionality would be suitable for this, but i can't fully figure out the code.

 

' Define source and destination folders
Dim sourceFolder As String = "D:\Source\"
Dim targetFolder As String = "D:\Target\"

' Get the list of .ipt files in the source folder
Dim filePaths() As String = System.IO.Directory.GetFiles(sourceFolder, "*.ipt")

' Loop through each file
For Each filePath As String In filePaths
    
    ' Create a new part document
    Dim newPartDoc As PartDocument = ThisApplication.Documents.Add(DocumentTypeEnum.kPartDocumentObject,, True)
    Dim newCompDef As PartComponentDefinition = newPartDoc.ComponentDefinition

    ' Create Derived part definition
    Dim derivedPartDef As DerivedPartUniformScaleDef
    derivedPartDef = newCompDef.ReferenceComponents.DerivedPartComponents.CreateUniformScaleDef(filePath)

    ' Define Derive style
    derivedPartDef.DeriveStyle = DerivedComponentStyleEnum.kDeriveAsSingleBodyNoSeams

    ' Add the derived part to the new part
    newCompDef.ReferenceComponents.DerivedPartComponents.Add(derivedPartDef)

    ' New file save location
    Dim fileNameOnly As String = System.IO.Path.GetFileName(filePath)
    Dim newFilePath As String = System.IO.Path.Combine(targetFolder, fileNameOnly)
    newPartDoc.SaveAs(newFilePath, False)

    ' Close new part
    newPartDoc.Close(True)
Next

 

So far it does create the new file in the target folder and i do see a reference to the original file in my modeltree (FMS_056...), but i don't see a physical 3D model:

 

Daan_M_0-1747664555792.png

 

(The model/derive link can be deleted in the final code)

0 Likes
Accepted solutions (1)
193 Views
3 Replies
Replies (3)
Message 2 of 4

Andrii_Humeniuk
Advisor
Advisor

Hi @Daan_M .
Your code works fine for the test parts I created. Perhaps in your case the body combination is not successful due to the complex geometry of the part.
Can you provide a sample for testing?

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

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

EESignature

0 Likes
Message 3 of 4

Daan_M
Collaborator
Collaborator

Hi @Andrii_Humeniuk,  thanks for the reply.

 

I've attached a sample file for testing.

0 Likes
Message 4 of 4

Andrii_Humeniuk
Advisor
Advisor
Accepted solution

Hi @Daan_M . Thanks for the example, it made it easier to understand what is missing.
In your case, including all solids using the IncludeAllSolids property is missing.

' Define source and destination folders
Dim sourceFolder As String = "D:\Source\"
Dim targetFolder As String = "D:\Target\"

' Get the list of .ipt files in the source folder
Dim filePaths() As String = System.IO.Directory.GetFiles(sourceFolder, "*.ipt")

If filePaths.Count = 0 Then Exit Sub
If Not IO.Directory.Exists(targetFolder) Then IO.Directory.CreateDirectory(targetFolder)
Dim oDocs As Documents = ThisApplication.Documents

' Loop through each file
For Each filePath As String In filePaths
    
    ' Create a new part document
    Dim newPartDoc As PartDocument = oDocs.Add(DocumentTypeEnum.kPartDocumentObject,, False)
    Dim newCompDef As PartComponentDefinition = newPartDoc.ComponentDefinition

    ' Create Derived part definition
    Dim derivedPartDef As DerivedPartUniformScaleDef
    derivedPartDef = newCompDef.ReferenceComponents.DerivedPartComponents.CreateUniformScaleDef(filePath)
	
	derivedPartDef.IncludeAllSolids = DerivedComponentOptionEnum.kDerivedIncludeAll

    ' Define Derive style
    derivedPartDef.DeriveStyle = DerivedComponentStyleEnum.kDeriveAsSingleBodyNoSeams

    ' Add the derived part to the new part
    newCompDef.ReferenceComponents.DerivedPartComponents.Add(derivedPartDef)

    ' New file save location
    Dim fileNameOnly As String = System.IO.Path.GetFileName(filePath)
    Dim newFilePath As String = System.IO.Path.Combine(targetFolder, fileNameOnly)
    newPartDoc.SaveAs(newFilePath, False)

    ' Close new part
    newPartDoc.Close(True)
Next


 

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

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

EESignature