Split a part in Inventor

By Xiaodong Liang

Issue
How can I split a part using the API? Is there any difference from part context and assembly context?

Solution
Before Inventor  2010, you can call the SplitFeatures.SplitPart method to split a part. This method takes two parameters and returns the newly created SplitFeature. Input Object SplitTool that specifies the entity that will be used to define the split. The input can be a WorkPlane, WorkSurface, or 2D Path. A Path object is obtained using the CreatePath method of the SplitFeatures object. Optional input Boolean value RemovePositiveSide that indicates which portion of the split part is to be removed. The default value is True, which indicates that the positive side will be removed.

From Inventor 2010 ,  Inventor supports multiple surface bodies. SplitFeatures.SplitPart is hidden. It will split all surface bodies. A new method is provided: SplitFeatures.TrimSolid which can split the specific surface body. 

The following code demonstrate how to use the methods,  based on the attached sample model.

The first sample passes a WorkSurface as the input to create a SplitFeature: 

Sub splitByWorkSurface() 
  
        ' assume we have had Inventor application 
        Try
 
            Dim oDoc As PartDocument = 
                _InvApplication.Documents.Add( 
                   DocumentTypeEnum.kPartDocumentObject, 
                 _InvApplication.FileManager.GetTemplateFile( 
                 DocumentTypeEnum.kPartDocumentObject))
 
            Dim oDef As PartComponentDefinition = 
                oDoc.ComponentDefinition
 
            Dim oSketch As PlanarSketch = 
                oDef.Sketches.Add(oDef.WorkPlanes.Item(3))
 
            Dim oTG As TransientGeometry =
                _InvApplication.TransientGeometry
 
            oSketch.SketchLines.AddAsTwoPointRectangle( 
                oTG.CreatePoint2d(0, 0), 
            oTG.CreatePoint2d(6, 3))
 
            Dim oProfile As Profile =
                oSketch.Profiles.AddForSolid()
 
            Dim oBaseExtrude As ExtrudeFeature =
                oDef.Features.ExtrudeFeatures.
                          AddByDistanceExtent(
                              oProfile,
                              4,                    PartFeatureExtentDirectionEnum.kPositiveExtentDirection,
                    PartFeatureOperationEnum.kJoinOperation)
 
            oSketch =
                oDef.Sketches.Add(oDef.WorkPlanes.Item(3))
            Dim oLine As SketchLine =
                oSketch.SketchLines.AddByTwoPoints
                       (oTG.CreatePoint2d(2, -1),
                        oTG.CreatePoint2d(3, 2))
            oLine =
                oSketch.SketchLines.AddByTwoPoints 
                  (oLine.EndSketchPoint,
                                                
            oTG.CreatePoint2d(2, 4))
            oProfile =
                oSketch.Profiles.AddForSurface()
 
            Dim oCutExtrude As ExtrudeFeature =               
                  oDef.Features.ExtrudeFeatures.
                       AddByDistanceExtent(
                                       oProfile,
                                       5,            PartFeatureExtentDirectionEnum.kPositiveExtentDirection,
PartFeatureOperationEnum.kSurfaceOperation)
 
            Dim oWorkSurface As WorkSurface =
                   oCutExtrude.SurfaceBody.Parent
 
            Dim oSplit As SplitFeature
 
            'before Inventor 2010
            'Set oSplit = oDef.Features.SplitFeatures.SplitPart(oWorkSurface)
 
            'From Inventor 2010
 
            ' e.g. split the first body
            oDef.Features.SplitFeatures.TrimSolid(
                oWorkSurface,
                oDef.SurfaceBodies(1),
                False)
 
        Catch ex As Exception
            MsgBox(ex.ToString())
        End Try
     End Sub

This second example passes in a 2D Path as the input to create a SplitFeature. Before running this sample, please confirm that the sketch with some SketchSpline exists and there is the part that can be split. You can use the attached part document "partTobeSplit.ipt" for the test.

 

Sub splitByPath()
  
    Try
        Dim oPart As PartDocument = 
        _InvApplication.ActiveDocument 
 
        Dim oDocDef = oPart.ComponentDefinition 
 
    ' assume there is a sketch named 'sketch2'
    Dim oSketch As Sketch = 
        oDocDef.Sketches.Item("sketch2")
 
     ' find a spline in the sketch
    Dim oSkSpLine As SketchSpline
    If oSketch.Consumed = False Then
        Dim findit As Boolean
        findit = False        
        For Each oSkSpLine In oSketch.SketchSplines
            If oSkSpLine.Construction = False Then
                findit = True
                Exit For
            End If
        Next
 
        If findit Then
            Dim oPath As Inventor.Path
            oPath = 
                oDocDef.Features.
                        CreatePath(oSkSpLine)
 
            'before Inventor 2010
            'oPart.ComponentDefinition.
            'Features.SplitFeatures.SplitPart oPath, False
 
            'From Inventor 2010
            'just split second surface body
            oDocDef.Features.SplitFeatures.
                    TrimSolid(oPath, 
                              oDocDef.SurfaceBodies(2), 
                              False)
        End If
    End If
 
    Catch ex As Exception
        MsgBox(ex.ToString())
    End Try
 
End Sub

In the assembly context there is not much difference, you just need to pass in the NativeObject of the proxy object in the assembly environment to the CreatePath method when retrieving the SpitTool object. Here is an example that demonstrates how to split a part after the user selects a SketchSpline in the assembly document. Moreover, you can change the side of an existing split feature by deleting and re-creating the SplitFeature and passing in the new side parameter as shown by the last several lines.

Private Function getPath(invApp As Inventor.Application,
                         ByVal oPrtDoc As PartDocument ) _
            As Inventor.Path
 
    Dim oSks As SketchSplineProxy
 
    'We assume the user selected the sketch spline
   ' in the assembly context
    oSks = 
        invApp.ActiveDocument.SelectSet(1)
 
    Dim oPrtFeats As PartFeatures = 
        oPrtDoc.ComponentDefinition.Features
 
    getPath = 
        oPrtFeats.SplitFeatures.CreatePath(oSks.NativeObject)
End Function

 

private Sub SplitPartInAssembly()

  

 ' assume we have had Inventor application

    Try

        Dim oAss As AssemblyDocument =

            _InvApplication.ActiveDocument

 

        'Get the first component to be split

        Dim oSelectedOcc As ComponentOccurrence =

            oAss.ComponentDefinition.Occurrences(1)

 

        Dim oPrtDoc As PartDocument =

            oSelectedOcc.Definition.Document

 

        'Get the 2D path SplitTool

        Dim oSelectedTool As Inventor.Path =

            getPath(_InvApplication,oPrtDoc)

 

        Dim oPrtFeats As PartFeatures =

            oPrtDoc.ComponentDefinition.Features

 

        ''**************before Inventor 2010***********

 

        'Create Split Part with negative side

        'Dim spFeature As SplitFeature =

   'oPrtFeats.SplitFeatures.SplitPart(oSelectedTool, False)

 

        ''Change the negative side to positive side

        'Dim skObj As Object = spFeature.SplitTool

        'spFeature.Delete(True, True, True)

 

        'spFeature =

   'oPrtFeats.SplitFeatures.SplitPart(oSelectedTool, True)

        '**************

 

        '********from Inventor 2010**********

        'Create Split Part with negative side

        Dim spFeature As SplitFeature =

            oPrtFeats.SplitFeatures.TrimSolid(

                oSelectedTool,

                oSelectedOcc.Definition.SurfaceBodies(1),

                False)

 

        'Change the negative side to positive side

        Dim skObj As Object =

            spFeature.SplitTool

        spFeature.Delete(True, True, True)

 

        spFeature = oPrtFeats.SplitFeatures.TrimSolid(

            oSelectedTool,

            oSelectedOcc.Definition.SurfaceBodies(1),

            True)

        '************************************

    Catch ex As Exception

        MsgBox(ex.ToString())

    End Try

 

End Sub

 

Download Test-part-split


Comments

3 responses to “Split a part in Inventor”

  1. Marco Suurlant Avatar
    Marco Suurlant

    Hello Xiaodong,
    I can’t see the attached sample model for the Split a part function?
    Is it possible that you provide the sample model?
    Best regards, Marco

  2. Hi Marco, the file is uploaded. Thanks.
    Regards,Xiaodong

  3. Hello,
    I want to split a solid body to multiple bodies. Inventor always splits a body to two body. But sometimes i need 3 or more bodies from one body.
    Sample: Split a model look like ” E ” vertically. Inventor makes two body. But i want to have a 4 seperate bodies from this model.
    Regards,

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading