'[ edit these variables as needed
sSketchName = "Flat Pattern Sketch"
sHoleName = "Locator triangle"
oOffset = 0.100 in'defines offset from edge of flat pattern
']
' 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 cutouts
Dim oCutFeatures
For Each oCutFeatures In oFlatPattern.Features.CutFeatures
oCutFeatures.Delete
MsgBox("Done")
Next
Dim oFace As Face
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 oEdge As Edge
oOffset = oOffset * 2.5400013716 'converts cm to inches
' Get all Bend UP edges on top face
Dim oTopFaceBendUpEdges As Edges
oTopFaceBendUpEdges = _
oFlatPattern.GetEdgesOfType(FlatPatternEdgeTypeEnum.kBendUpFlatPatternEdge, True)
For Each oEdge In oTopFaceBendUpEdges
oPoint = oTG.CreatePoint2d(oEdge.StartVertex.Point.x, oEdge.StartVertex.Point.Y - oOffset)
oHoleCenters.Add ( oSketch.SketchPoints.Add(oPoint, True))
oPoint = oTG.CreatePoint2d(oEdge.StopVertex.Point.x, oEdge.StopVertex.Point.Y + oOffset)
oHoleCenters.Add ( oSketch.SketchPoints.Add(oPoint, True))
Next
' Get all Bend DOWN edges on top face
Dim oTopFaceBendDownEdges As Edges
oTopFaceBendDownEdges = _
oFlatPattern.GetEdgesOfType(FlatPatternEdgeTypeEnum.kBendDownFlatPatternEdge, True)
For Each oEdge In oTopFaceBendDownEdges
oPoint = oTG.CreatePoint2d(oEdge.StartVertex.Point.x, oEdge.StartVertex.Point.Y - oOffset)
oHoleCenters.Add ( oSketch.SketchPoints.Add(oPoint, True))
oPoint = oTG.CreatePoint2d(oEdge.StopVertex.Point.x, oEdge.StopVertex.Point.Y + oOffset)
oHoleCenters.Add ( oSketch.SketchPoints.Add(oPoint, True))
Next
'set a reference to the transient geometry collection.
Dim oTransGeom As TransientGeometry
oTransGeom = ThisApplication.TransientGeometry
' Create a new transaction to wrap the construction of the three lines
' set into a single undo.
Dim oTrans As Transaction
oTrans = ThisApplication.TransactionManager.StartTransaction( _
ThisApplication.ActiveDocument, _
"Create Triangle Sample")
' Create the first line of the triangle. This uses two transient points as
' input to definethe coordinates of the ends of the line. Since a transient
' point is input a sketch point is automatically created at that location and
' the line is attached to it.
Dim oLines(0 To 2) As SketchLine
oLines(0) = oSketch.SketchLines.AddByTwoPoints(oTransGeom.CreatePoint2d(oEdge.StartVertex.Point.x , oEdge.StartVertex.Point.Y - oOffset), _
oTransGeom.CreatePoint2d(oEdge.StartVertex.Point.x -0.5, oEdge.StartVertex.Point.Y - oOffset + 0.5))
' Create a sketch line that is connected to the sketch point the previous lines
' end point is connected to. This will automatically create the constraint to
' tie the new line to the sketch point the previous line is also connected to.
' This will result in the the two lines being connected since they're both tied
' to the same sketch point.
oLines(1) = oSketch.SketchLines.AddByTwoPoints(oLines(0).EndSketchPoint, _
oTransGeom.CreatePoint2d(oEdge.StartVertex.Point.x +0.5, oEdge.StartVertex.Point.Y - oOffset + 0.5))
' Create a third line and connect it to the start point of the first line and the
' end point of the second line. This will result in a connected triangle.
oLines(2) = oSketch.SketchLines.AddByTwoPoints(oLines(1).EndSketchPoint, oLines(0).StartSketchPoint)
Dim oProfile As Profile
oProfile = oSketch.Profiles.AddForSolid
Dim oCutDefinition As CutDefinition
oCutDefinition = oFlatPattern.Features.CutFeatures.CreateCutDefinition(oProfile)
Call oCutDefinition.SetThroughAllExtent(kNegativeExtentDirection)
Dim oCutFeature As CutFeature
oCutFeature = oFlatPattern.Features.CutFeatures.Add(oCutDefinition)
' End the transaction
oTrans.End
iLogicVb.UpdateWhenDone = True