Ilogic to tell the parent feature of a bend line edge in a sheet metal flat pattern?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello All,
I'm looking for a way to determine which feature in the model browser was responsible for creating a specific bend line in the sheet metal function. We currently have the following code to identify upward bend lines (the ones that need located are only upward) and place a small hole that our cam software will recognize as a bend mark location. We only need to identify 6 points on the part (the endpoints for the base 3 bends though occasionally the third is not needed and we'll switch to 2 main bends) but there are other bends on the part and those are currently being picked up by the script as well. They have to be manually deleted in a dxf editor. I'm wondering if there's a way to identify which feature created the bend after identifying the bend curves and tracing back the part feature responsible for their creation. I can then check and see if it is an upward bend line we actually want to bother marking and ignore it if its not.
'[ edit these variables as needed
sSketchName = "Flat Pattern Sketch"
sHoleName = "Locator Holes"
oOffset = 0 'defines offset from edge of flat pattern
oDiameter = .5/10 '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)
yMaxPoint = oLine.RangeBox.MaxPoint.Y
xMaxPoint = oLine.RangeBox.MaxPoint.X
yMinPoint = oLine.RangeBox.MinPoint.Y
xMinPoint = oLine.RangeBox.MinPoint.X
slope = Atan((yMaxPoint - yMinPoint) / (xMaxPoint - xMinPoint))
Xa1 = Cos(slope)/10
Ya1 = Sin(slope)/10
oVec_Y1 = oTG.CreateVector2d(Xa1, Ya1)
oVec_Y2 = oTG.CreateVector2d(-Xa1, -Ya1)
' Create a vectors along the y-axis.
Dim oVec_Y As Vector2d
oSketchPoint = oSketch.SketchPoints.Add(oLine.StartSketchPoint.Geometry, True)
oSketchPoint.MoveBy(oVec_Y1)
oHoleCenters.Add(oSketchPoint)
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)
oSketchPoint = oSketch.SketchPoints.Add(oLine.EndSketchPoint.Geometry, True)
oSketchPoint.MoveBy(oVec_Y2)
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
InventorVb.DocumentUpdate()
MessageBox.Show("Message", "Title")
On a more broad note the issues we're facing here are stemming from not really having a reference that is consistent between the flat and folded models. A lot of times these parts will have cut features that remove what I would like to use as a reference point. What I would love is a feature like a point or line that isn't physical geometry but still unfolds with it so I could use it as a reference. That way when I'm automatically running a batch of these things I don't have to worry about my reference being deleted while still being in a predicable spot on the flat.