How to do a SplitFaces with VB / Api?

How to do a SplitFaces with VB / Api?

HermJan.Otterman
Advisor Advisor
423 Views
2 Replies
Message 1 of 3

How to do a SplitFaces with VB / Api?

HermJan.Otterman
Advisor
Advisor

Hello,

 

I want to do a split of a worksurface, with a sketchblock (can also be a normale sketch)

 

with my code, Inventor 2017 is crashing.

and when not crashing, VB will give me an error.

 

what am I missing here?

 

thanks!

 

my code:

 

Private Sub CreatesplitHole()

Dim oPartDoc As Inventor.PartDocument = _inventorApplication.ActiveDocument

Dim oCompDef As PartComponentDefinition = oPartDoc.ComponentDefinition

'Dim oSelectSet As SelectSet = oPartDoc.SelectSet

Dim oSketch As PlanarSketch = oPartDoc.ComponentDefinition.Sketches(2)

Dim oTobjs As TransientObjects = _inventorApplication.TransientObjects

Dim objectCollection As ObjectCollection = oTobjs.CreateObjectCollection

Dim oWSFace As WorkSurface = oPartDoc.ComponentDefinition.WorkSurfaces(1)

Dim oSurfBody As SurfaceBody = oWSFace.SurfaceBodies(1)

Dim oFace As Face = oSurfBody.Faces(1)

objectCollection.Add(oFace)

Dim oSplitfeatures As SplitFeatures = oPartDoc.ComponentDefinition.Features.SplitFeatures

Dim oSketchBlocks As SketchBlocks = oSketch.SketchBlocks

For Each oSketchBlock As SketchBlock In oSketchBlocks

Dim oPath As Path = Nothing

Dim oSketchEntities As SketchEntitiesEnumerator = oSketchBlock.Definition.SketchEntities

For Each oSketchEntity As Object In oSketchEntities

If oSketchEntity.Construction = False Then

If oSketchEntity.Type <> ObjectTypeEnum.kSketchPointObject Then

oPath = oCompDef.Features.CreatePath(oSketchEntity)

 

Exit For

End If

End If

Next

Dim oSplit As SplitFeature

' Why does the split not work?

'oSplit = oSplitfeatures.SplitFaces(oPath, False, oSurfBody)

oSplit = oSplitfeatures.SplitFaces(oPath, False, objectCollection)

Next

End Sub

If this answers your question then please select "Accept as Solution"
Kudo's are also appreciated Smiley Wink

Succes on your project, and have a nice day

Herm Jan


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

Owner2229
Advisor
Advisor
Accepted solution

I've changed your code to work with normal sketch entities and it seems to work:

I've created a testing spline in your part, so you can test it out.

I can look in to the sketchblocks if you "need" to use them.

 

Private Sub CreateSplitHole()
    Dim oDoc As Inventor.PartDocument = _inventorApplication.ActiveDocument
    Dim oCD As PartComponentDefinition = oDoc.ComponentDefinition
    Dim oSketch As PlanarSketch = oCD.Sketches(2)
    Dim oTO As TransientObjects = _inventorApplication.TransientObjects
    Dim OC As ObjectCollection = oTO.CreateObjectCollection
    Dim oWSFace As WorkSurface = oCD.WorkSurfaces(1)
    Dim oSurfBody As SurfaceBody = oWSFace.SurfaceBodies(1)
    Dim oFace As Face = oSurfBody.Faces(1)
    OC.Add(oFace)
    Dim oPath As Object = Nothing
    For Each oSE As Object In oSketch.SketchEntities
        If oSE.Construction Then Continue For
        If oSE.Type = ObjectTypeEnum.kSketchPointObject Then Continue For
        oPath = oCD.Features.CreatePath(oSE)
        Exit For
    Next
    If oPath Is Nothing Then Exit Sub
    Dim oSplitFeatures As SplitFeatures = oCD.Features.SplitFeatures
    Dim oSplit As SplitFeature = oSplitFeatures.SplitFaces(oPath, False, OC)
End Sub
Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
Message 3 of 3

HermJan.Otterman
Advisor
Advisor

THANKS!!

 

still don't see what I did wrong.

I thought it would be easier with a sketch block but apperently it is not.

I can manage with a normal sketch

 

thanks for your help!

If this answers your question then please select "Accept as Solution"
Kudo's are also appreciated Smiley Wink

Succes on your project, and have a nice day

Herm Jan


0 Likes