Create Solid bodies from lumps

Create Solid bodies from lumps

Raider_71
Collaborator Collaborator
1,197 Views
3 Replies
Message 1 of 4

Create Solid bodies from lumps

Raider_71
Collaborator
Collaborator

Hi guys,

 

Unless I am missing an obvious piece of workflow needed to do the following in Inventor using default commands, what would the approach be using the API?

 

Here is the issue. If a part is split using a workplane and the section split off contains more than one "lump", would there be a way to convert the lumps into separate solid bodies using API?

 

Here is an example:

 

Split 03.jpgSplit 04.jpg

 

Now that I have these pieces I would have wanted to move them closer together for CNC.

 

Any ideas?

 

Thanks

Pieter

Accepted solutions (1)
1,198 Views
3 Replies
Replies (3)
Message 2 of 4

ekinsb
Alumni
Alumni
Accepted solution

There might be a more straightforward approach but I was able to get this to work. If you run the VBA macro below it will prompt you to select the body you want to break up and will result in creating new bodies for each "lump" and turning off the visibility of the selected body.

 

Public Sub CreateIndividualBodies()
    Dim partDoc As PartDocument
    Set partDoc = ThisApplication.ActiveDocument
    
    ' Have the body to break apart selected and make sure it has multiple "lumps".
    Dim selectedBody As SurfaceBody
    Set selectedBody = ThisApplication.CommandManager.Pick(kPartBodyFilter, "Select the body")
    
    If selectedBody.FaceShells.count < 2 Then
        MsgBox "The selected body should have more than one ""Lump""."
        Exit Sub
    End If
    
    ' Create a collection to store the individual bodies.
    Dim transBodies As ObjectCollection
    Set transBodies = ThisApplication.TransientObjects.CreateObjectCollection
        
    Dim features As PartFeatures
    Set features = partDoc.ComponentDefinition.features
    
    ' Iterate over each of the shells in the selected body.
    Dim i As Integer
    For i = 1 To selectedBody.FaceShells.count
        Dim currentShell As FaceShell
        Set currentShell = selectedBody.FaceShells.Item(i)
        
        ' Collect all of the faces in the body that are NOT in the current shell.
        Dim shell As FaceShell
        Dim facesToDelete As ObjectCollection
        Set facesToDelete = ThisApplication.TransientObjects.CreateFaceCollection
        For Each shell In selectedBody.FaceShells
            If Not shell Is currentShell Then
                Dim fc As Face
                For Each fc In shell.faces
                    Call facesToDelete.Add(fc)
                Next
            End If
        Next
        
        ' Start a transaction and delete the faces.
        Dim tran As Transaction
        Set tran = ThisApplication.TransactionManager.StartTransaction(ThisApplication.ActiveDocument, "Temp")
        Call features.DeleteFaceFeatures.Add(facesToDelete)
        
        ' Copy the body in the current state where only the current shell is part of it.
        Call transBodies.Add(ThisApplication.TransientBRep.Copy(selectedBody))
        
        ' Abort the transaction.
        tran.Abort
    Next
    
    ' Create a base feature for each of the bodies.
    Set tran = ThisApplication.TransactionManager.StartTransaction(ThisApplication.ActiveDocument, "Break Lumps")
    Dim body As SurfaceBody
    For Each body In transBodies
        Dim baseFeature As NonParametricBaseFeature
        Set baseFeature = features.NonParametricBaseFeatures.Add(body)
    Next
    
    ' Turn off the visibility of the original body.
    selectedBody.Visible = False
    
    ' End the transaction.
    tran.End
End Sub

Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 3 of 4

Raider_71
Collaborator
Collaborator

Hi Brian,

 

Thank you so much for the feedback. I have adapted it to my needs and its working perfectly! Thanks again much appreciated!

 

Pieter

0 Likes
Message 4 of 4

sjxyz
Enthusiast
Enthusiast

This is ALMOST very useful for me... in my trial ipt, the new separate bodies are all surfaces. I have to "manually" Repair Bodies, and choose Stitch,  one by one, to get separate solids. Is there a way to go the extra mile and end up with all separate solid bodies with minimal clicking? The file is attached, with 2 bodies repaired. I have several of these files, and no, it would not be "easy" to make the parts as separate solids in the first place.

Any help welcome.

0 Likes