Ilogic Text box and User Parameter

Ilogic Text box and User Parameter

gildas.lincot
Contributor Contributor
302 Views
2 Replies
Message 1 of 3

Ilogic Text box and User Parameter

gildas.lincot
Contributor
Contributor

Hi everybody!

Today i looking for if it's possible to create automatically a text box with user parameter value in it.

 

For the moment i'm abble to create, with ilogic code, a flat pattern for a sheet metal part and a sketch on top plane of the flat pattern and also create a user parameter in the flat pattern of this sheet metal part.
I wish to find a way to put automatically my user parameter "ParamGravure" in the text box as i can do manually with the "Text " command in a sketch. This text need to be in Font style "TXT" and Font size "3mm". (See image below)

 

Thanks for any help. By!Capture-gravure_LI.jpg

0 Likes
303 Views
2 Replies
Replies (2)
Message 2 of 3

RolfEven
Enthusiast
Enthusiast

@gildas.lincot,

I think the code below does what you are looking for. Some of the code is created with copy past edit from these sources:

https://forums.autodesk.com/t5/inventor-ilogic-api-vba-forum/flat-pattern-reference-parameter-in-ilo...

https://forums.autodesk.com/t5/inventor-ilogic-api-vba-forum/center-justification-of-text/td-p/99783... 

 

Text FlatPattern ParameterText FlatPattern Parameter

Dim partDoc As PartDocument = ThisDoc.Document
Dim sheetDef As SheetMetalComponentDefinition = partDoc.ComponentDefinition
Dim flat = sheetDef.FlatPattern
Dim params = flat.Parameters
Dim param_ParamGravure = params("ParamGravure")

' Check to make sure a sketch is open.
If Not TypeOf ThisApplication.ActiveEditObject Is PlanarSketch Then
MessageBox.Show("A sketch must be active.", "iLogic")
Return
End If

Dim oSketch As PlanarSketch
If TypeOf ThisApplication.ActiveEditObject Is Sketch Then
oSketch = ThisApplication.ActiveEditObject
'MessageBox.Show(oSketch.Name & " is the active Sketch", "iLogic")
Else
'MessageBox.Show("Active Edit Object is not a Sketch", "iLogic")
End If

Dim oTG As TransientGeometry
oTG = ThisApplication.TransientGeometry

oSketchText = oSketch.TextBoxes.AddFitted(oTG.CreatePoint2d(0, 0), "<StyleOverride FontSize='0,3' Font='Txt'>" & param_ParamGravure.Value & "</StyleOverride>")
oSketchText.HorizontalJustification = HorizontalTextAlignmentEnum.kAlignTextCenter
oSketchText.VerticalJustification = VerticalTextAlignmentEnum.kAlignTextMiddle

Code is brifely tested in R2020.

/Rolf Even

0 Likes
Message 3 of 3

theo.bot
Collaborator
Collaborator

To get Formatted text right i always try to reverse engineer. 

So in my first step I manualy create the text and use the first part of the rule to get the formatted text (logger info) . Then create your own defnition by building up the string with all the data. 

 

Dim oDoc As PartDocument
oDoc = ThisDoc.Document

Dim oComdef As SheetMetalComponentDefinition
oComdef = oDoc.ComponentDefinition

'Logger.Info(oComdef.FlatPattern.Sketches.Item(1).TextBoxes.Item(1).FormattedText)

Dim oPara As Inventor.Parameter
oPara = oComdef.FlatPattern.Parameters.Item("MyText")

oComdef.FlatPattern.Sketches.Item(1).TextBoxes.Item(1).FormattedText  = "<StyleOverride Font='Txt' FontSize='0,3'><Parameter Resolved='True' ComponentIdentifier='"& oDoc.FullFileName & "' Name='" & oPara.Name & "' Precision='3'> " & oPara.Value & "</Parameter></StyleOverride>"

 

0 Likes