Message 1 of 2
iLogic Rule - Current triangular notches of fold lines for flat patterns, need rectangular notches now.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Below is the current iLogic rule I am using, I have tried using ChatGPT to just modify the triangular notching to use either square or rectangular notching to no avail.
All iterations from ChatGPT have resulted in error after erro after running the rule so I am hoping someone may be able to point me in the right direction of how to excute it?
Sub Main
'[ edit these variables as needed
sSketchName = "Flat Pattern Notch Sketch"
sCutName = "Fold Notches"
']
' 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 oCut As ExtrudeFeature
For Each oCut In oFlatPattern.Features.ExtrudeFeatures
oCut.Delete
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
Dim oEdges As Edges
' Create a new object collection for the hole center points.
oHoleCenters = ThisApplication.TransientObjects.CreateObjectCollection
' Get all Bend UP edges
'where true = top face
oEdges = _
oFlatPattern.GetEdgesOfType( _
FlatPatternEdgeTypeEnum.kBendUpFlatPatternEdge, True)
'process the Bend Edges
Call CreateSketch(oSketch, oEdges)
' Get all Bend Down edges
'where true = top face
oEdges = _
oFlatPattern.GetEdgesOfType( _
FlatPatternEdgeTypeEnum.kBendDownFlatPatternEdge, True)
'process the Bend Edges
Call CreateSketch(oSketch, oEdges)
Dim oProfile As Profile
oProfile = oSketch.Profiles.AddForSolid
' Create an extrusion
Dim oExtrude As ExtrudeFeature
oExtrude = oFlatPattern.Features.ExtrudeFeatures.AddByThroughAllExtent(oProfile, kSymmetricExtentDirection, kCutOperation)
oExtrude.Name = sCutName
'oCompDef.FlatPattern.ExitEdit
' oPartDoc.Save
End Sub
Sub CreateSketch (oSketch As PlanarSketch, oEdges As Edges)
Dim SketchFace As Face = TryCast(oSketch.PlanarEntity, Face)
If SketchFace Is Nothing Then MessageBox.Show("Sketch Not created on face.") : Exit Sub
Dim oUOM As UnitsOfMeasure
oUOM = ThisDoc.Document.UnitsOfMeasure
oLenUnits = oUOM.GetStringFromType(UnitsTypeEnum.kDefaultDisplayLengthUnits)
oInvUnits = UnitsTypeEnum.kCentimeterLengthUnits
oInvUnitString = oUOM.GetStringFromType(oInvUnits)
oConversion = oUOM.ConvertUnits(1, oUOM.LengthUnits, oInvUnits)
'Dim oBotDia As Double = .144 * oConversion
'Dim oBotDia As Double = 0.425 * oConversion
'Dim oBotDia As Double = 0.15 * oConversion
Dim oBotDia As Double = 0.4 * oConversion
For Each oEdge In oEdges
'create line
Dim skLine As SketchLine = oSketch.AddByProjectingEntity(oEdge)
Call AddTriangleToLinePoint(SketchFace, oBotDia, skLine, "Start")
Call AddTriangleToLinePoint(SketchFace, oBotDia, skLine, "End")
Next
End Sub
Sub AddTriangleToLinePoint(TestFace As Face, CircleDiameter As Double, skLine As SketchLine, PointSelection As String)
Dim TargetPoint As SketchPoint
Dim TempPoint As SketchPoint
Select Case PointSelection
Case "Start"
TargetPoint = skLine.StartSketchPoint
TempPoint = skLine.EndSketchPoint
Case "End"
TargetPoint = skLine.EndSketchPoint
TempPoint = skLine.StartSketchPoint
Case Else
MessageBox.Show("Can only add triangle to ""Start"" or ""End"" point of SketchLine")
Exit Sub
End Select
Dim oSketch As PlanarSketch = skLine.Parent
Dim oPolygon As SketchEntitiesEnumerator = oSketch.SketchLines.AddAsPolygon(3, TargetPoint.Geometry, TempPoint.Geometry, True)
Dim oCircle As SketchCircle = oSketch.SketchCircles.AddByCenterRadius(TargetPoint.Geometry, CircleDiameter)
oCircle.Construction = True
oSketch.DimensionConstraints.AddDiameter(oCircle, TargetPoint.Geometry)
oSketch.GeometricConstraints.AddCoincident(TargetPoint, oCircle.CenterSketchPoint)
'Constrain Circle tangent to Lines of Polygon
oSketch.GeometricConstraints.AddTangent(oPolygon.Item(1), oCircle)
oSketch.GeometricConstraints.AddTangent(oPolygon.Item(2), oCircle)
oSketch.GeometricConstraints.AddTangent(oPolygon.Item(3), oCircle)
'Constrian polygon to line
Dim coincidentPoint As SketchPoint = oPolygon.Item(1).StartSketchPoint
oSketch.GeometricConstraints.AddCoincident(skLine, coincidentPoint)
'Adjust coincident point if not on face
Dim TestPoint As Point = TestFace.GetClosestPointTo(coincidentPoint.Geometry3d)
Dim AdjustmentVector As Vector2d = Nothing
If Round(TestPoint.DistanceTo(coincidentPoint.Geometry3d), 9) <> 0
AdjustmentVector = coincidentPoint.Geometry.VectorTo(oCircle.CenterSketchPoint.Geometry)
AdjustmentVector.ScaleBy(2)
coincidentPoint.MoveBy(AdjustmentVector)
End If
End Sub