'[ 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 * 2.5400013716 '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 +5)
oVec_Y2 = oTG.CreateVector2d(0, oOffset -5)
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 +5)
oVec_Y1 = oTG.CreateVector2d(0, oOffset +5)
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
' Create the hole feature.
oHole = oFlatPattern.Features.HoleFeatures.AddDrilledByThroughAllExtent( _
oHoleCenters, oDiameter , kPositiveExtentDirection)
'oHoleCenters, oDiameter * 2.5400013716 , kPositiveExtentDirection)
oHole.Name = sHoleName
oSketch.Visible = True
Among the above items
' 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)
' 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)
Can not we use a rule?