Message 1 of 13
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi experts,
I am writing a macro to use in assembly environment, to punch a threaded hole by picking edge of drill hole.
The problem is that after creating the threaded hole, there are projected entities left.
I want to delete the yellow sketch circle and yellow sketch point as shown in the image.
iLogic or VBA are both fine.
Option Explicit
Sub XXX()
Dim oAssemDoc As AssemblyDocument
Dim oAssemDef As AssemblyComponentDefinition
Dim oFace As Object
Dim oOcc As ComponentOccurrence
Dim oPartDoc As PartDocument
Dim oPartDef As PartComponentDefinition
Dim oSketch As PlanarSketch
Dim oEntity As Object
Dim oEntityProxy As Object
Dim oSketchProxy As Object
Dim oEntityOcc As ComponentOccurrence
Dim x As Double
Dim y As Double
Dim oHoleCenters As ObjectCollection
Dim oHoleTapInfo As HoleTapInfo
Dim oTransGeom As TransientGeometry
Dim h As HoleFeature
Set oAssemDoc = ThisApplication.ActiveDocument
Set oAssemDef = oAssemDoc.ComponentDefinition
Set oFace = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFacePlanarFilter, "Select face on part for new sketch")
If oFace Is Nothing Then Exit Sub
Set oOcc = oFace.ContainingOccurrence
oOcc.Edit
Set oPartDoc = ThisApplication.ActiveEditDocument
Set oPartDef = oPartDoc.ComponentDefinition
Set oSketch = oPartDef.Sketches.Add(oFace.NativeObject)
oSketch.Edit
Set oEntity = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAllEntitiesFilter, "Select entity to project")
If oEntity Is Nothing Then Exit Sub
Set oEntityOcc = oEntity.ContainingOccurrence
Call oEntityOcc.CreateGeometryProxy(oEntity, oEntityProxy)
Call oOcc.CreateGeometryProxy(oSketch, oSketchProxy)
Call oSketchProxy.AddByProjectingEntity(oEntityProxy)
oSketch.Adaptive = False
Set oTransGeom = ThisApplication.TransientGeometry
x = oSketch.SketchCircles.item(1).CenterSketchPoint.Geometry.x
y = oSketch.SketchCircles.item(1).CenterSketchPoint.Geometry.y
Set oHoleCenters = ThisApplication.TransientObjects.CreateObjectCollection
Call oHoleCenters.Add(oSketch.SketchPoints.Add(oTransGeom.CreatePoint2d(x, y)))
Set oHoleTapInfo = oPartDef.Features.HoleFeatures.CreateTapInfo(True, "ISO Metric profile", "M6x1", "6H", True)
Set h = oPartDef.Features.HoleFeatures.AddDrilledByThroughAllExtent(oHoleCenters, oHoleTapInfo, kPositiveExtentDirection)
oSketch.ExitEdit
ThisApplication.CommandManager.ControlDefinitions.item("AppReturnTopCmd").Execute
oOcc.Adaptive = False
End Sub
Solved! Go to Solution.

