How can I add a sketchpoint to a hole feature

How can I add a sketchpoint to a hole feature

MTheDesigner
Advocate Advocate
376 Views
1 Reply
Message 1 of 2

How can I add a sketchpoint to a hole feature

MTheDesigner
Advocate
Advocate

I have a hole feature that I would like to add a point to. I have some code that edits a sketch and adds a sketch point. but when I add that to the hole center points nothing happens. I can't seem to find anything else in the HoleFeature Object documentation on adding a point to a preexisting feature. The centerpoint seems to get added to the collection correctly, but no hole is drilled. What am I missing?

 

Dim oDoc As PartDocument = ThisApplication.ActiveDocument
Dim oSketches As PlanarSketches = oDoc.ComponentDefinition.Sketches
Dim oSketch As PlanarSketch = oSketches.Item("Holes")
Dim oFeatures As PartFeatures = oDoc.ComponentDefinition.Features
Dim oHoleCenterPoints As ObjectCollection = oFeatures.HoleFeatures.Item("Hole1").HoleCenterPoints
Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
Dim oSketchPointCollection As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection()
Dim oHeight As Double = InputBox("Enter height", "Do the height thing")
Dim oPoint As Point2d = oTG.CreatePoint2d(1.75 * 2.54, (-LENGTH + oHeight) * 2.54)
oHoleCenterPoints.Add(oSketch.SketchPoints.Add(oPoint, True))
MsgBox(oHoleCenterPoints.Count)

 

 

0 Likes
Accepted solutions (1)
377 Views
1 Reply
Reply (1)
Message 2 of 2

MTheDesigner
Advocate
Advocate
Accepted solution

I figured it out. HoleCenterPoints was a red herring. The thing I really needed to change was the PlacementDefinition.

 

You need to gather all of your holes into an ObjectCollection and give it to the HoleFeatures.CreateSketchPlacementDefinition() function.

Then set the HoleFeature.PlacementDefinition to your new placement def and botta bing botta boom your holes are added.

 

Dim oDoc As PartDocument = ThisApplication.ActiveDocument
Dim oSketches As PlanarSketches = oDoc.ComponentDefinition.Sketches
Dim oSketch As PlanarSketch = oSketches.Item("Holes")
Dim oFeatures As PartFeatures = oDoc.ComponentDefinition.Features
Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
Dim oSketchPointCollection As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection()
Dim oHeight As Double = InputBox("Enter height", "Do the height thing")
Dim oPoint As Point2d = oTG.CreatePoint2d(1.75 * 2.54, (-LENGTH + oHeight) * 2.54)
oSketch.SketchPoints.Add(oPoint, True)
Dim oSketchPoint As SketchPoint
For Each oSketchPoint In oSketch.SketchPoints
	oSketchPointCollection.Add(oSketchPoint)
Next
Dim PlacementDef As SketchHolePlacementDefinition = oFeatures.HoleFeatures.CreateSketchPlacementDefinition(oSketchPointCollection)
oFeatures.HoleFeatures.Item("Hole1").PlacementDefinition = PlacementDef