Add hole in multi-body part document

<?xml encoding=”UTF-8″>By Adam Nagy

If you try to insert a hole feature in a single-body part document based on a sketch point that should work fine. But in case of a multi-body part document nothing will happen because Inventor does not know which solid body you want to include in the hole feature.

This is what you can use the HoleFeature‘s SetAffectedBodies function for. 

If in the attached 2015 part document you select the solid body and the sketch with the sketch point in it, then the below code will create the hole feature:

Holefeature

Sub CreateHoleFeature()
Dim pd As PartDocument
Set pd = ThisApplication.ActiveDocument
Dim sb As SurfaceBody
Set sb = pd.SelectSet(1)
Dim ps As PlanarSketch
Set ps = pd.SelectSet(2)
Dim pcd As PartComponentDefinition
Set pcd = pd.ComponentDefinition
Dim tr As TransientObjects
Set tr = ThisApplication.TransientObjects
Dim hfs As HoleFeatures
Set hfs = pcd.Features.HoleFeatures
Dim oc As ObjectCollection
Set oc = tr.CreateObjectCollection
Call oc.Add(ps.SketchPoints(2))
Dim shpd As SketchHolePlacementDefinition
Set shpd = hfs.CreateSketchPlacementDefinition(oc)
Dim hf As HoleFeature
Set hf = hfs.AddDrilledByThroughAllExtent(shpd, 0.2, kNegativeExtentDirection)
Set oc = tr.CreateObjectCollection
Call oc.Add(sb)
Call hf.SetAffectedBodies(oc)
End Sub

  Download HoleFeatureTest2015


Comments

Leave a Reply

Discover more from Autodesk Developer Blog

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

Continue reading