Message 1 of 5
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
i am trying to create a text field in a sketch during the editing of an ipt. the text field should simply contain the component number.
' Set a reference to the part document Dim oDoc As Inventor.Document oDoc = ThisDoc.Document ' Set a reference to the component definition Dim oCompDef As PartComponentDefinition oCompDef = oDoc.ComponentDefinition ' Create a new sketch on the X-Y work plane (WorkPlanes(3) is typically the X-Y plane) Dim oSketch As PlanarSketch oSketch = oCompDef.Sketches.Add(oCompDef.WorkPlanes(3)) ' Edit the sketch oSketch.Edit ' Project the origin point Dim oOriginSketchPoint As SketchPoint oOriginSketchPoint = oSketch.AddByProjectingEntity(oCompDef.WorkPoints.Item(1)) ' Add a text field containing the part name or a parameter Dim oText As String = oDoc.DisplayName ' Use the part name as text ' Alternatively, use a parameter: oText = Parameter("ParameterName") ' Define the position for the text (offset from the origin point) Dim oTextPoint As Point2d oTextPoint = oSketch.SketchPoints.Add(10, 10).Geometry ' Adjust coordinates as needed ' Add the text to the sketch Dim oSketchText As SketchText oSketchText = oSketch.SketchTexts.Add(oTextPoint, oText) ' Format the text (optional) oSketchText.FontSize = 5.0 ' Set font size oSketchText.HorizontalJustification = HorizontalTextAlignmentEnum.kAlignTextLeft ' Set alignment ' Exit the sketch oSketch.ExitEdit()
the sketch is successfully created but “Sketchtext” is not declared. I hope you can help me.
Thank you
Solved! Go to Solution.