iLogic - Create Text in Flat Pattern

iLogic - Create Text in Flat Pattern

petr.meduna
Advocate Advocate
577 Views
0 Replies
Message 1 of 1

iLogic - Create Text in Flat Pattern

petr.meduna
Advocate
Advocate

Hello,

I have a rule that creates text and then converts it to geometry. It creates a point in the center of the outer edge loop, and then writes the coordinates of that point to the definition of the point where the textbox is to be created(CreatePoint2d). The problem is that this is not always the same, in some cases the text box is inserted completely outside the flat pattern, even though the point in the center is created correctly.

 

The only difference between the components is that they have a different basic sketch. See attached pictures.

 

What am I doing wrong?

 

iLogic Rule:

Dim oPartDoc As PartDocument
oPartDoc = ThisApplication.ActiveDocument
Dim oCompDef As SheetMetalComponentDefinition
oCompDef = oPartDoc.ComponentDefinition
Dim oFlatPattern As FlatPattern
oFlatPattern = ThisApplication.ActiveEditObject
Dim oFace As Face
oFace = oFlatPattern.TopFace
Dim oTG As TransientGeometry
Dim oSketch As PlanarSketch
Dim sText As String
Dim oTextBox As TextBox
oPath = Left(oPartDoc.FullDocumentName, InStrRev(oPartDoc.FullDocumentName, "\") -1)
oNazev = Mid(oPartDoc.FullDocumentName, Len(oPath) + 2, Len(oPartDoc.FullDocumentName) -Len(oPath) -5)
If Not oFace Is Nothing Then
	Try
		Dim oEdgeLoops As EdgeLoops
		oEdgeLoops = oFace.EdgeLoops
		Dim outerLoop As EdgeLoop
		For Each outerLoop In oEdgeLoops
			If outerLoop.IsOuterEdgeLoop Then
				Exit For
			End If
		Next
		Dim oWorkPoint As WorkPoint
		oWorkPoint = oFlatPattern.WorkPoints.AddAtCentroid(outerLoop, False)
		oWorkPoint.Name = "Bod smyčky"
		oSketch = oFlatPattern.Sketches.Add(oFace, False)
		oSketch.AddByProjectingEntity(oWorkPoint)
		oSketch.Name = "Vygravírovaný text"
		oTG = ThisApplication.TransientGeometry
		oBod = oTG.CreatePoint2d(oWorkPoint.Point.X, oWorkPoint.Point.Y)
		sText = oNazev
		oTextBox = oSketch.TextBoxes.AddFitted(oBod, sText)
		oSketch.TextBoxes.Item(1).Style.Font = "ISOCP"
		oSketch.TextBoxes.Item(1).Style.FontSize = 0.2
		With oTextBox
			.VerticalJustification = kAlignTextMiddle
			.HorizontalJustification = kAlignTextLeft
		End With

	Catch
		oSketch = oFlatPattern.Sketches.Add(oFace, False)
		oSketch.Name = "Vygravírovaný text"
		oTG = ThisApplication.TransientGeometry
		Dim oPoint As Point
		oPoint = oFlatPattern.MassProperties.CenterOfMass
		sText = oNazev
		oTextBox = oSketch.TextBoxes.AddFitted(oTG.CreatePoint2d(oPoint.X, oPoint.Y), sText)
		oSketch.TextBoxes.Item(1).Style.Font = "ISOCP"
		oSketch.TextBoxes.Item(1).Style.FontSize = 0.2
		With oTextBox
			.VerticalJustification = kAlignTextMiddle
			.HorizontalJustification = kAlignTextLeft
		End With
	End Try
		oTextBox.ConvertToGeometry("isocp")
End If
End Sub

 

This is how it should be: Sketch in the center

part1.PNG

 

But on the other sheet - there is y coordinate wrong

part2.PNG

 

And another - there is X coordinate wrong

part3.PNG

 

I also attached the sheets.

 

Thanks for any suggestion.

Inventor Professional 2021

0 Likes
578 Views
0 Replies
Replies (0)