Triangular Fold Line Notching

Triangular Fold Line Notching

MattyB92
Explorer Explorer
249 Views
4 Replies
Message 1 of 5

Triangular Fold Line Notching

MattyB92
Explorer
Explorer

I have a specific problem, I for the life of me can not figure out this issue.

I have used a code from this forum for automating the notching, however it is in the wrong orientation. See attached pictures.

I would like 1 of the peaks of the triangle notches to align with the bend lines.

These are incorrect done by the iLogic automation code:

Screenshot 2025-01-28 100428.png

Screenshot 2025-01-28 100423.png

As an example here is a manual one I have done:

Screenshot 2025-01-28 100351.png

 

Code as attached:

Sub Main
	'[ edit these variables as needed
	sSketchName = "Flat Pattern Sketch"
	sCutName = "Triangles"
	']	

	'  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 Sketch, oEdges As Edges)

	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)

	' Set a reference to the transient geometry object.
	Dim oTransGeom As TransientGeometry
	oTransGeom = ThisApplication.TransientGeometry


	For Each oEdge In oEdges

		'create line
		Dim skLine As SketchLine
		skLine = oSketch.AddByProjectingEntity(oEdge)

		Dim oLineSegment1 As LineSegment2d
		oLineSegment1 = skLine.Geometry

		Dim startPt As Point2d
		startPt = skLine.StartSketchPoint.Geometry

		Dim endPt As Point2d
		endPt = skLine.EndSketchPoint.Geometry

		Dim oInterSectPoint As Point2d

		'create triangle
		Dim oBotDia As Double = .144 * oConversion
		
		For i = 1 To 2
			Dim oPolygon As SketchEntitiesEnumerator
			oPolygon = oSketch.SketchLines.AddAsPolygon(3, endPt, startPt, True)

			Dim oCircle As SketchCircle
			oCircle = oSketch.SketchCircles.AddByCenterRadius(endPt, oBotDia)
			oCircle.Construction = True
			oDim = oSketch.DimensionConstraints.AddDiameter(oCircle, endPt)

			'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)


			If i = 1 Then
				oSketch.GeometricConstraints.AddCoincident(skLine.StartSketchPoint, oCircle.CenterSketchPoint)
				oSketch.GeometricConstraints.AddHorizontal(oPolygon.Item(2))
			Else
				oSketch.GeometricConstraints.AddCoincident(skLine.EndSketchPoint, oCircle.CenterSketchPoint)
				oSketch.GeometricConstraints.AddHorizontal(oPolygon.Item(1))
			End If

		Next
	Next


End Sub

0 Likes
Accepted solutions (1)
250 Views
4 Replies
Replies (4)
Message 2 of 5

BM_Ashraf
Advocate
Advocate

Hi is it possible to share the test file. To find the exact Problem.

I think the Problem cound be because of the  Geomtic Constrains

Sub Main
	'[ edit these variables as needed
	sSketchName = "Flat Pattern Sketch"
	sCutName = "Triangles"
	']	

	'  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 Sketch, oEdges As Edges)

	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)

	' Set a reference to the transient geometry object.
	Dim oTransGeom As TransientGeometry
	oTransGeom = ThisApplication.TransientGeometry


	For Each oEdge In oEdges

		'create line
		Dim skLine As SketchLine
		skLine = oSketch.AddByProjectingEntity(oEdge)

		Dim oLineSegment1 As LineSegment2d
		oLineSegment1 = skLine.Geometry

		Dim startPt As Point2d
		startPt = skLine.StartSketchPoint.Geometry

		Dim endPt As Point2d
		endPt = skLine.EndSketchPoint.Geometry

		Dim oInterSectPoint As Point2d

		'create triangle
		Dim oBotDia As Double = .144 * oConversion
		
		For i = 1 To 2
			Dim oPolygon As SketchEntitiesEnumerator
			oPolygon = oSketch.SketchLines.AddAsPolygon(3, endPt, startPt, True)

			Dim oCircle As SketchCircle
			oCircle = oSketch.SketchCircles.AddByCenterRadius(endPt, oBotDia)
			oCircle.Construction = True
			oDim = oSketch.DimensionConstraints.AddDiameter(oCircle, endPt)

			'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)


			If i = 1 Then
				oSketch.GeometricConstraints.AddCoincident(skLine.StartSketchPoint, oCircle.CenterSketchPoint)
				'oSketch.GeometricConstraints.AddHorizontal(oPolygon.Item(2))
				oSketch.GeometricConstraints.AddPerpendicular(oPolygon.Item(2),skLine)
			Else
				oSketch.GeometricConstraints.AddCoincident(skLine.EndSketchPoint, oCircle.CenterSketchPoint)
				'oSketch.GeometricConstraints.AddHorizontal(oPolygon.Item(1))
				oSketch.GeometricConstraints.AddPerpendicular(oPolygon.Item(1),skLine)
			End If

		Next
	Next


End Sub

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.

Blue Mech

Add-ins for Inventor!

0 Likes
Message 3 of 5

MattyB92
Explorer
Explorer

See attached 🙂

0 Likes
Message 4 of 5

J-Camper
Advisor
Advisor
Accepted solution

Instead of making a line Horizontal, I would coincident one of your polygon points to the edge's SketchLine.  You can then validate it is in the correct direction, and move the point if needed.  Try replacing your "CreateSketch" Sub with this:

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
	
	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


Let me know if you have any questions, or if this is not working as intended

 

0 Likes
Message 5 of 5

MattyB92
Explorer
Explorer

That worked fantastically, thank you so much.

Screenshot 2025-02-03 054331.png


They are now in the correct orientation 🙂

0 Likes