Not applicable
05-24-2018
11:07 AM
I am struggling to select a single edge of a cylindrical tube with a key to chamfer. The top edge (the face the key is closest to) needs to be chamfered as does the exterior edge of the key closest to the top face (circled in picture.) I have a decent grasp of how to chamfer an edge once selected, but I cannot figure out how to select only a single edge. I'm coding in VB.net as a standalone application, but VBA is not a problem for me to translate.
Thanks,
Chris
'Allows Inventor assets Imports Inventor Imports System 'Creates a structure for variables Structure Data Dim KeyHeight As Double Dim KeyWidth As Double Dim OD As Double Dim ID As Double Dim ConnectorDepth As Double End Structure 'Establishes the form to open Inventor and draw connector Public Class ShellExtrude Dim m_inventorApp As Inventor.Application = Nothing Private Sub ShellExtrude_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles Button1.Click Try Try m_inventorApp = System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application") Catch ex As Exception Dim inventorAppType As Type = System.Type.GetTypeFromProgID("Inventor.Application") m_inventorApp = System.Activator.CreateInstance(inventorAppType) m_inventorApp.Visible = True End Try Catch System.Windows.Forms.MessageBox.Show("Error: couldn't create Inventor instance") End Try Dim oPartDoc As PartDocument = m_inventorApp.Documents.Add(DocumentTypeEnum.kPartDocumentObject, m_inventorApp.FileManager.GetTemplateFile(DocumentTypeEnum.kPartDocumentObject)) Dim oCompDef As PartComponentDefinition = oPartDoc.ComponentDefinition Dim oTG As TransientGeometry = m_inventorApp.TransientGeometry 'Open the file. 'Dim FileName As String = "C:\Users\Chris\Desktop\text.txt" Dim PartData() As Data Dim PartCount As Long PartCount = 0 ' Open the file 'FileOpen(1, "C:\Users\Christian's PC\Desktop\Connector C++\Test Connector\data.csv", OpenMode.Input) FileOpen(1, "C:\Users\Chris\Desktop\data.csv", OpenMode.Input) ' Read through the file until we reach the end. Do While Not EOF(1) ' Read the next line from the file. Dim strLine = LineInput(1) strLine = Trim$(strLine) If strLine <> "" Then ' Break the line up, using commas as the delimiter. Dim astrPieces() As String astrPieces = Split(strLine, ",") If UBound(astrPieces) <> 4 Then MessageBox.Show("Invalid line in the file: " & strLine) Exit Sub End If ' Increase the size of the array of part data. PartCount = PartCount + 1 ReDim Preserve PartData(PartCount - 1) ' Save the data in the part data array. PartData(PartCount - 1).KeyHeight = astrPieces(0) PartData(PartCount - 1).KeyWidth = astrPieces(1) PartData(PartCount - 1).ID = astrPieces(2) PartData(PartCount - 1).OD = astrPieces(3) PartData(PartCount - 1).ConnectorDepth = astrPieces(4) 'MessageBox.Show(astrPieces(0) & astrPieces(1) & astrPieces(2) & astrPieces(3) 'Create a sketch on the origin plane XY Dim oSketch As PlanarSketch = oCompDef.Sketches.Add(oCompDef.WorkPlanes(3)) 'Sketch the outer diameter circle on the sketch Dim oOD As SketchCircle = oSketch.SketchCircles.AddByCenterRadius(oTG.CreatePoint2d(0, 0), astrPieces(3) / 2) 'Sketch the inner diamter circle on the sketch Dim oID As SketchCircle = oSketch.SketchCircles.AddByCenterRadius(oTG.CreatePoint2d(0, 0), astrPieces(2) / 2) 'Create a profile. Dim oShellProfile As Profile = oSketch.Profiles.AddForSolid 'Determine which profile to extrude Dim oProfPath As ProfilePath For Each oProfPath In oShellProfile If oProfPath.Item(1).SketchEntity Is oOD Then oProfPath.AddsMaterial = False ElseIf oProfPath.Item(1).SketchEntity Is oID Then oProfPath.AddsMaterial = False End If Next 'Extrude profile Dim oExtOD As ExtrudeDefinition = oCompDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(oShellProfile, PartFeatureOperationEnum.kJoinOperation) Call oExtOD.SetDistanceExtent(astrPieces(4), PartFeatureExtentDirectionEnum.kNegativeExtentDirection) Dim oExtrude As ExtrudeFeature = oCompDef.Features.ExtrudeFeatures.Add(oExtOD) 'Create work plane offset from XY plane Dim WorkPlane1 As WorkPlane = oCompDef.WorkPlanes.AddByPlaneAndOffset(oCompDef.WorkPlanes(3), (-1.3716)) 'Create sketch on offset plane Dim oSketch2 As PlanarSketch = oCompDef.Sketches.Add(WorkPlane1) WorkPlane1.Visible = False 'Create lines to form the key Dim oKeyLines(0 To 3) As SketchLine oKeyLines(0) = oSketch2.SketchLines.AddByTwoPoints(oTG.CreatePoint2d(-astrPieces(1) / 2, 0.95 * astrPieces(3) / 2), oTG.CreatePoint2d(-astrPieces(1) / 2, astrPieces(0))) oKeyLines(1) = oSketch2.SketchLines.AddByTwoPoints(oKeyLines(0).EndSketchPoint, oTG.CreatePoint2d(astrPieces(1) / 2, astrPieces(0))) oKeyLines(2) = oSketch2.SketchLines.AddByTwoPoints(oKeyLines(1).EndSketchPoint, oTG.CreatePoint2d(astrPieces(1) / 2, 0.95 * astrPieces(3) / 2)) oKeyLines(3) = oSketch2.SketchLines.AddByTwoPoints(oKeyLines(2).EndSketchPoint, oKeyLines(0).StartSketchPoint) 'Create profile for the key extrusion Dim oKeyProfile As Profile = oSketch2.Profiles.AddForSolid 'Extrude key Dim oExtKey As ExtrudeDefinition = oCompDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(oKeyProfile, PartFeatureOperationEnum.kJoinOperation) Call oExtKey.SetDistanceExtent(1.2192, PartFeatureExtentDirectionEnum.kPositiveExtentDirection) Dim oExtrude2 As ExtrudeFeature = oCompDef.Features.ExtrudeFeatures.Add(oExtKey) 'Create sketch on XY plane to cut away part of key Dim oSketch3 As PlanarSketch = oCompDef.Sketches.Add(oCompDef.WorkPlanes(3)) 'Circle to be removed Dim oKeyRadius As SketchCircle = oSketch3.SketchCircles.AddByCenterRadius(oTG.CreatePoint2d(0, 0), astrPieces(0)) Dim oKeyRadiusCut As SketchCircle = oSketch3.SketchCircles.AddByCenterRadius(oTG.CreatePoint2d(0, 0), astrPieces(0) * 1.05) 'Profile for cut Dim oKeyRadiusCutaway As Profile = oSketch3.Profiles.AddForSolid 'Select which to cut Dim oProfPath2 As ProfilePath For Each oProfPath2 In oKeyRadiusCutaway If oProfPath2.Item(1).SketchEntity Is oKeyRadius Then oProfPath2.AddsMaterial = False ElseIf oProfPath2.Item(1).SketchEntity Is oKeyRadiusCut Then oProfPath2.AddsMaterial = False End If Next 'Cut away part of key Dim oKeyCutaway As ExtrudeDefinition = oCompDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(oKeyRadiusCutaway, PartFeatureOperationEnum.kCutOperation) Call oKeyCutaway.SetThroughAllExtent(PartFeatureExtentDirectionEnum.kNegativeExtentDirection) Dim oExtrude3 As ExtrudeFeature = oCompDef.Features.ExtrudeFeatures.Add(oKeyCutaway) 'Set up edge collection for chamfer Dim oEdges As EdgeCollection = m_inventorApp.TransientObjects.CreateEdgeCollection Dim oEdge As Edge For Each oEdge In oExtrude.StartFaces.Item(1).Edges oEdges.Add(oEdge) Next 'Chamfer top edge Dim oKeyChamfer As ChamferFeature = oCompDef.Features.ChamferFeatures.AddUsingDistance(oEdges, 0.0254) oSketch3.Visible = False End If Close() Loop End Sub
End Class
Solved! Go to Solution.
Link copied