Message 1 of 9

Not applicable
01-17-2021
04:12 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
I would like to create a cut extrusion on an extruded part and then chamfer all edges on the top face of the extrusion using Autdesk Inventor VBA. I am able to create the cut extrusion but I am placing the chamfer on the bottom of the extrusion and not the top. The names and descriptions of attached jpgs illustrate what I am trying to accomplish:
- BeforeRunningVBACutExtrude.jpg: Part before running VBA
- AfterRunningVBACutExtrude.JPG: Part after running VBA where chamfer is not placed in the right location.
- DesiredAfterRunningVBACutExtrude.JPG: How I want the part to look like after I run the vba code
Here is the vba code:
Sub CreateIndentation()
'This sub creates an indentation on the plane named IndentPlane
'User creates a plane and names it 'IndentPlane'
Dim oPDoc As PartDocument
Set oPDoc = ThisApplication.ActiveDocument
Dim oPDef As PartComponentDefinition
Set oPDef = oPDoc.ComponentDefinition
'Loop Through planes of model and find plane named 'IndentPlane'
Dim oWP As WorkPlane
Dim oExists As Boolean
For Each oWP In oPDef.WorkPlanes
If oWP.Name = "IndentPlane" Then
oExists = True
Exit For
End If
Next
If oExists = False Then
Call MsgBox("WorkPlane named ""IndentPlane"" was not found. Exiting.", , "")
Exit Sub
End If
Dim oSketch As Inventor.PlanarSketch
Set oSketch = oPDef.Sketches.Add(oWP)
'Create transGeom
Dim oTG As TransientGeometry
Set oTG = ThisApplication.TransientGeometry
'1: Create and Define four points of Rectangle
Dim D1, D2 As Double
D1 = 0.3
D2 = 1.25
Dim oCoord1 As Point2d
Set oCoord1 = oTG.CreatePoint2d(D1, D1)
Dim oCoord2 As Point2d
Set oCoord2 = oTG.CreatePoint2d(D2, D1)
Dim oCoord3 As Point2d
Set oCoord3 = oTG.CreatePoint2d(D2, D2)
Dim oCoord4 As Point2d
Set oCoord4 = oTG.CreatePoint2d(D1, D2)
'1b: Create four lines
Dim oLine(1 To 4) As SketchLine
'Define Four Lines
Set oLine(1) = oSketch.SketchLines.AddByTwoPoints(oCoord1, oCoord2)
Set oLine(2) = oSketch.SketchLines.AddByTwoPoints(oCoord2, oCoord3)
Set oLine(3) = oSketch.SketchLines.AddByTwoPoints(oCoord3, oCoord4)
Set oLine(4) = oSketch.SketchLines.AddByTwoPoints(oCoord4, oCoord1)
'Define and Create 8 points for filleting
Dim radFilSize As Double
radFilSize = 0.3
Dim oInputPt1 As Point2d
Set oInputPt1 = oTG.CreatePoint2d(D2 - radFilSize, D1)
Dim oInputPt2 As Point2d
Set oInputPt2 = oTG.CreatePoint2d(D2, D1 + radFilSize)
Dim oInputPt3 As Point2d
Set oInputPt3 = oTG.CreatePoint2d(D2, D2 - radFilSize)
Dim oInputPt4 As Point2d
Set oInputPt4 = oTG.CreatePoint2d(D2 - radFilSize, D2)
Dim oInputPt5 As Point2d
Set oInputPt5 = oTG.CreatePoint2d(D1 + radFilSize, D2)
Dim oInputPt6 As Point2d
Set oInputPt6 = oTG.CreatePoint2d(D1, D2 - radFilSize)
Dim oInputPt7 As Point2d
Set oInputPt7 = oTG.CreatePoint2d(D1, D2 + radFilSize)
Dim oInputPt8 As Point2d
Set oInputPt8 = oTG.CreatePoint2d(D1 + radFilSize, D1)
'Create saArc and Define four fillets of Rectangle
Dim saArc As SketchArc
Set saArc = oSketch.SketchArcs.AddByFillet(oLine(1), oLine(2), radFilSize, oInputPt1, oInputPt2)
Set saArc = oSketch.SketchArcs.AddByFillet(oLine(2), oLine(3), radFilSize, oInputPt3, oInputPt4)
Set saArc = oSketch.SketchArcs.AddByFillet(oLine(3), oLine(4), radFilSize, oInputPt5, oInputPt6)
Set saArc = oSketch.SketchArcs.AddByFillet(oLine(4), oLine(1), radFilSize, oInputPt7, oInputPt8)
'Create and define Profile for extrusion
Dim oProfile As Profile
Set oProfile = oSketch.Profiles.AddForSolid
'Create Cut Extrusion that is 1 cm deep
Dim oEDef As ExtrudeDefinition
Set oEDef = oPDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(oProfile, kCutOperation)
Call oEDef.SetDistanceExtent(1, kNegativeExtentDirection)
Dim oExtrude1 As ExtrudeFeature
Set oExtrude1 = oPDef.Features.ExtrudeFeatures.Add(oEDef)
'Create oEdges Collection
Dim oEdges As EdgeCollection
Set oEdges = ThisApplication.TransientObjects.CreateEdgeCollection
'This print call shows that there is only one face belonging to oExtrude1 which is the bottom face
Debug.Print oExtrude1.EndFaces.Count
Call oEdges.Add(oExtrude1.EndFaces.Item(1).EdgeLoops.Item(1).Edges.Item(1))
'Create Chamfer on last Edge
Dim oChamfer As ChamferFeature
Set oChamfer = oPDef.Features.ChamferFeatures.AddUsingDistance(oEdges, 0.05, False, False, False)
End Sub
Solved! Go to Solution.