Ilogic - Text Box (Size and Font) Flat Pattern

Ilogic - Text Box (Size and Font) Flat Pattern

projetos33
Contributor Contributor
600 Views
4 Replies
Message 1 of 5

Ilogic - Text Box (Size and Font) Flat Pattern

projetos33
Contributor
Contributor

I'm trying to create a sketch on the unfolded part, but I'm having trouble.

I'm doing this in iLogic and when I run the rule, it creates a sketch on the face of the unfolded view and creates a text box with the file name.

I need this name to be in the size 6.00mm and Font: "Txt"

This rule works on metal parts with unfolding.

 

Don't need cut the part, only create de sketch , and the user move to position to cut or engrave (-0,1mm). 

 

Sub principal()
    ' Obter o documento ativo
    Dim oPartDoc como PartDocument
    oPartDoc = EsteAplicativo.DocumentoAtivo
 
    ' Verificar se o documento é uma chapa metálica
    Se oPartDoc.ComponentDefinition.Type <> 150995200 Então
        MessageBox.Show("O arquivo não é uma peça de chapa metálica.", "iLogic")
        Sair do Sub
    Fim Se
 
    ' Obter a definição da peça de chapa metálica
    Dim oCompDef como SheetMetalComponentDefinition
    oCompDef = oPartDoc.ComponentDefinition
 
    ' Verificar e ativar a vista planificada
    Se não TypeOf ThisApplication.ActiveEditObject for FlatPattern, então
        Tentar
            Se oCompDef.HasFlatPattern = False Então
                oCompDef.Desdobrar
            Outro
                oCompDef.FlatPattern.Edit
            Fim Se
        Pegar
            MessageBox.Show("Erro ao ativar a vista planificada.", "iLogic")
            Sair do Sub
        Fim da tentativa
    Fim Se
 
    ' Obter a vista planificada
    Dim oFlatPattern como FlatPattern
    oFlatPattern = EsteAplicativo.ActiveEditObject
 
    ' Obter a face do padrão planificado
    Dim oFace como rosto
    oFace = oFlatPattern.TopFace
 
    ' Nome do esboço e do corte
    Dim sSketchName como String
    Dim sTextFeatureName como string
    sSketchName = "Esboço de marcação de texto"
    sTextFeatureName = "Marcação de texto"
 
    ' Remover esboço existente, se houver
    Dim oSketch como PlanarSketch
    Para cada oSketch em oFlatPattern.Sketches
        Se oSketch.Name = sSketchName Então
            oSketch.Excluir
        Fim Se
    Próximo
 
    ' Criar um novo esboço na face planificada
    oSketch = oFlatPattern.Sketches.Add(oFace, Falso)
    oSketch.Nome = sSketchNome
 
    ' Obter o nome do arquivo (sem extensão)
    Dim sFileName como String
    sFileName = System.IO.Path.GetFileNameWithoutExtension(oPartDoc.FullFileName)
 
    ' Criar um ponto de origem para o texto
    Dim oTransGeom como TransientGeometry
    oTransGeom = EsteAplicativo.TransientGeometry
    Dim oTextPosition como Point2d
    oTextPosition = oTransGeom.CreatePoint2d(0, 0) ' Posição inicial (pode ser ajustada)
 
    ' Adicionar um texto ao esboço
Dim oTextBox como Inventor.TextBox
oTextBox = oSketch.TextBoxes.AddFitted(oTextPosition, sFileName)
 
    ' Mensagem de sucesso
    MsgBox ("Marcação com o nome da peça foi adicionada!", vbInformation, "Concluído")
 
Fim do sub
0 Likes
Accepted solutions (1)
601 Views
4 Replies
Replies (4)
Message 2 of 5

Curtis_Waguespack
Consultant
Consultant

Hi @projetos33 ,

 

Here is a quick rule that will create a sketch on a flat pattern

 

Hope this helps,
Curtis

 

oPartDoc = ThisDoc.Document
oFileName = IO.Path.GetFileNameWithoutExtension(oPartDoc.FullFileName)

'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

Dim oFace As Face
oFace = oFlatPattern.TopFace

Dim oSketch As PlanarSketch

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


'trying to choose an appropriate point
'assume this planar face has one edge loop only
oEdgeLoop = oFace.EdgeLoops(1)

oMinPt = oEdgeLoop.RangeBox.MinPoint
oMaxPt = oEdgeLoop.RangeBox.MaxPoint

CenterPt = ThisApplication.TransientGeometry.CreatePoint((oMaxPt.X + oMinPt.X) / 2#, (oMaxPt.Y + oMinPt.Y) / 2#, (oMaxPt.Z + oMinPt.Z) / 2#)

'get one point on the face and transform to the point2d on the sketch 
oTextPt = oSketch.ModelToSketchSpace(CenterPt)

'add the textbox
oSketchText = oSketch.TextBoxes.AddFitted(oTextPt, oFileName)


'oCompDef.FlatPattern.ExitEdit

EESignature

0 Likes
Message 3 of 5

projetos33
Contributor
Contributor

Thanks, but i need change the font to "Txt" and the Size to 6,00mm. it's possible?

0 Likes
Message 4 of 5

Curtis_Waguespack
Consultant
Consultant
Accepted solution

Hi @projetos33 

ooops! I forgot that part. See updated example.

Hope that helps,

Curtis

 

oPartDoc = ThisDoc.Document
oFileName = IO.Path.GetFileNameWithoutExtension(oPartDoc.FullFileName)

'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

Dim oFace As Face
oFace = oFlatPattern.TopFace

Dim oSketch As PlanarSketch

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


'trying to choose an appropriate point
'assume this planar face has one edge loop only
oEdgeLoop = oFace.EdgeLoops(1)

oMinPt = oEdgeLoop.RangeBox.MinPoint
oMaxPt = oEdgeLoop.RangeBox.MaxPoint

CenterPt = ThisApplication.TransientGeometry.CreatePoint((oMaxPt.X + oMinPt.X) / 2#, (oMaxPt.Y + oMinPt.Y) / 2#, (oMaxPt.Z + oMinPt.Z) / 2#)

'get one point on the face and transform to the point2d on the sketch 
oTextPt = oSketch.ModelToSketchSpace(CenterPt)

'add the textbox
oSketchTextBox = oSketch.TextBoxes.AddFitted(oTextPt, oFileName)

oStyle = oSketchTextBox.Style
oStyle.Font = "Txt"
oStyle.FontSize = 0.6 'size in cm
oStyle.HorizontalJustification = HorizontalTextAlignmentEnum.kAlignTextCenter
oStyle.VerticalJustification = VerticalTextAlignmentEnum.kAlignTextMiddle


'oCompDef.FlatPattern.ExitEdit

 

EESignature

Message 5 of 5

projetos33
Contributor
Contributor

Thank you very much.
I was able to use your code and adapt some more details.