Message 1 of 6
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
TO ACHIEVE
I'm looking for an ilogic to create notches of triangle shapes on the end of every bend lines on both sides pointing outwards.
PROBLEM
I combine a code to resolve the issue but i'm only able to create only single triangle and its not even on the bend line point.
'[ edit these variables as needed sSketchName = "Flat Pattern Sketch" sHoleName = "Locator Holes" oOffset = 0 'defines offset from edge of flat pattern oDiameter = 0.125 'defines hole diameter '] ' a reference to the active document. Dim oPartDoc As PartDocument oPartDoc = ThisApplication.ActiveDocument 'verify document type is sheet metal If oPartDoc.ComponentDefinition.Type <> 150995200 Then MessageBox.Show("File is not a sheet metal part.", "iLogic") Exit Sub End If Dim oCompDef As SheetMetalComponentDefinition oCompDef = oPartDoc.ComponentDefinition ' Check to make sure a flat pattern is open. If Not TypeOf ThisApplication.ActiveEditObject Is FlatPattern Then Try If oCompDef.HasFlatPattern = False Then oCompDef.Unfold Else oCompDef.FlatPattern.Edit End If Catch MessageBox.Show("Error editting the flat pattern.", "iLogic") End Try End If ' a reference to the active flat pattern. Dim oFlatPattern As FlatPattern oFlatPattern = ThisApplication.ActiveEditObject 'clean up existing holes Dim oHole As HoleFeature For Each oHole In oFlatPattern.Features.HoleFeatures oHole.Delete Next Dim oFace As Face 'oFace = oFlatPattern.BottomFace oFace = oFlatPattern.TopFace Dim oSketch As PlanarSketch 'clean up existing sketch For Each oSketch In oFlatPattern.Sketches If oSketch.Name = sSketchName Then oSketch.Delete End If Next ' Create a new sketch. The second argument specifies to include/not include ' the edges of the face in the sketch. oSketch = oFlatPattern.Sketches.Add(oFace, False) ' Change the name. oSketch.Name = sSketchName ' Create a new object collection for the hole center points. oHoleCenters = ThisApplication.TransientObjects.CreateObjectCollection Dim oTG As TransientGeometry oTG = ThisApplication.TransientGeometry Dim oPoint As Point2d Dim oSketchPoint As SketchPoint 'oOffset = oOffset *1 'converts cm to inches Dim oEdge As Edge Dim oEdges As Edges ' Get all Bend UP edges 'where true = top face oEdges = _ oFlatPattern.GetEdgesOfType( _ FlatPatternEdgeTypeEnum.kBendUpFlatPatternEdge, True) For Each oEdge In oEdges Dim oLine As SketchLine = oSketch.AddByProjectingEntity(oEdge) 'yMinPoint = oLine.RangeBox.MinPoint.Y yMaxPoint = oLine.RangeBox.MaxPoint.Y ' Create a vectors along the y-axis. Dim oVec_Y As Vector2d Dim oVec_Y_neg As Vector2d If yMaxPoint < 0 Then oVec_Y1 = oTG.CreateVector2d(0, oOffset) oVec_Y2 = oTG.CreateVector2d(0, oOffset) Else oVec_Y1 = oTG.CreateVector2d(0, oOffset) oVec_Y2 = oTG.CreateVector2d(0, oOffset) End If oSketchPoint = oSketch.SketchPoints.Add(oLine.StartSketchPoint.Geometry, True) oSketchPoint.MoveBy(oVec_Y1) oHoleCenters.Add(oSketchPoint) oSketchPoint = oSketch.SketchPoints.Add(oLine.EndSketchPoint.Geometry, True) oSketchPoint.MoveBy(oVec_Y2) oHoleCenters.Add(oSketchPoint) oLine.Delete() Next ' Get all Bend Down edges 'where true = top face oEdges = _ oFlatPattern.GetEdgesOfType( _ FlatPatternEdgeTypeEnum.kBendDownFlatPatternEdge, True) For Each oEdge In oEdges Dim oLine As SketchLine = oSketch.AddByProjectingEntity(oEdge) 'yMinPoint = oLine.RangeBox.MinPoint.Y yMaxPoint = oLine.RangeBox.MaxPoint.Y ' Create a vectors along the y-axis. Dim oVec_Y As Vector2d Dim oVec_Y_neg As Vector2d If yMaxPoint < 0 Then oVec_Y2 = oTG.CreateVector2d(0, oOffset) oVec_Y1 = oTG.CreateVector2d(0, oOffset) Else oVec_Y2 = oTG.CreateVector2d(0, oOffset) oVec_Y1 = oTG.CreateVector2d(0, oOffset) End If oSketchPoint = oSketch.SketchPoints.Add(oLine.StartSketchPoint.Geometry, True) oSketchPoint.MoveBy(oVec_Y2) oHoleCenters.Add(oSketchPoint) oSketchPoint = oSketch.SketchPoints.Add(oLine.EndSketchPoint.Geometry, True) oSketchPoint.MoveBy(oVec_Y1) oHoleCenters.Add(oSketchPoint) oLine.Delete() Next Dim oBotDia As Double = .144 Dim Sides As Integer = 3 'create check sketch Dim oPolygon As SketchEntitiesEnumerator Dim oCircle As SketchCircle oGC = oSketch.GeometricConstraints oDC = oSketch.DimensionConstraints oCP = oSketch.AddByProjectingEntity(oCompDef.WorkPoints.Item(1)) oPolygon = oSketch.SketchLines.AddAsPolygon(Sides, oSketchPoint, oTG.CreatePoint2d(0,0), True) 'Make Lines Construction For Each oLine In oPolygon oLine.Construction = False Next 'Variable to capture center of Polygon pattern Dim polygonCP As SketchPoint Dim verifyType As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection For Each sp As SketchPoint In oSketch.SketchPoints 'Centerpoint of the Polygon seems to have (2 x Sides) PatternConstraintObjects 'You might need to do extra checks if you will have multiple Polygons in your sketch If sp.Constraints.Count >= 2 * Sides For Each Item In sp.Constraints If Item.Type = ObjectTypeEnum.kPatternConstraintObject Then verifyType.Add(Item) Next If verifyType.Count = 2 * Sides polygonCP = sp Exit For End If End If Next If IsNothing(polygonCP) Then MessageBox.Show("Could Not find a Polygon CenterPoint", "Failure") : Exit Sub 'Constrain sketch oGC.AddCoincident(oCP,oSketchPoint) oGC.AddVertical(oPolygon.Item(2)) oDC.AddOffset(oPolygon.Item(2),polygonCP,oTG.CreatePoint2d(0, oBotDia / 4 * 2.54), True).Parameter.Value = (oBotDia * 2.54) ' Create the hole feature. 'oHole = oFlatPattern.Features.HoleFeatures.AddDrilledByThroughAllExtent( _ 'oHoleCenters, oDiameter , kPositiveExtentDirection) 'oHoleCenters, oDiameter * 2.5400013716 , kPositiveExtentDirection) 'oHole.Name = sHoleName 'oSketch.Visible = True
Solved! Go to Solution.