@amillsLD4X8 @grahov Hi, i can't remember where exactly the problem was, but im using it in a sub.
"marksrting" is a function , "markedexport ", and "numberlessexport" are subs
Edit: Imporant! I just recalled that you can't do it in Inventor Version 2023.1, you will get a missing Member exception, i dont know for 2023.2 and 2023.3, but it will work in 2023.4
Also, if you want to test my code, be sure to set the Name of the Markstyle to match one of yours, and check if you have the Simplex Text Font Installed, or change the override to another one.
Sub marktextbox(ByVal position As Point, ByRef stringlength As Double, ByRef stringheight As Double, ByRef offset As Double)
'declared ahead to make deletion in case of errors possible
Dim marksketch As PlanarSketch
Dim markfeature As MarkFeature
Try
Dim transgeom As TransientGeometry = ThisApplication.TransientGeometry
Dim sheetmetalcomponentdefinition As SheetMetalComponentDefinition = ThisDoc.Document.ComponentDefinition
Dim flatpattern As FlatPattern = sheetmetalcomponentdefinition.FlatPattern
' create the sketch
marksketch = flatpattern.Sketches.AddWithOrientation(flatpattern.TopFace, _
sheetmetalcomponentdefinition.WorkAxes.Item(1), True,True, sheetmetalcomponentdefinition.WorkPoints(1),False)
marksketch.Visible = False
marksketch.Name = "MarkierskizzeBauteilnummer"
' set the cornerpoints of the textbox
Dim markcorner As Point2d = marksketch.ModelToSketchSpace(transgeom.CreatePoint((position.X+offset), (position.Y+offset), 0))
Dim markcorner2 As Point2d = marksketch.ModelToSketchSpace(transgeom.CreatePoint((position.X + (offset + stringlength)), (position.Y + (offset + stringheight)), 0))
' get the string, and create the textbox, "markstring" is a function here
Dim text As String = markstring
Dim textbox As Inventor.TextBox = marksketch.TextBoxes.AddByRectangle(markcorner,markcorner2,text)
textbox.FormattedText = "<StyleOverride Font='SIMPLEX' FontSize='1'>" & text & "</StyleOverride>"
' put the text into an object collection
Dim markobjects As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
For Each markbox As Inventor.TextBox In marksketch.TextBoxes
markobjects.Add(markbox)
Next markbox
' get the style per Name
Dim markstyle As MarkStyle
For Each searchstyle As markstyle In ThisDoc.Document.MarkStyles
If searchstyle.Name = "Fläche markieren" Then
markstyle = searchstyle
Exit For
End If
Next searchstyle
' create the mark
Dim MarkFeatures As MarkFeatures = flatpattern.Features.MarkFeatures
Dim markdefinition As MarkDefinition = markfeatures.CreateMarkDefinition(markobjects, markstyle)
markfeature = markfeatures.Add(markdefinition)
markfeature.Name = "Bauteilnummer"
Call markedexport
GoTo cleanup
Catch
Call numberlessexport
GoTo cleanup
End Try
cleanup :
Try : markfeature.Delete : Catch : End Try
Try : marksketch.Delete : Catch : End Try
End Sub
Fanden Sie diesen Beitrag hilfreich? Fühlen Sie sich frei, diesen Beitrag zu liken.
Wurde Ihre Frage erfolgreich beantwortet? Klicken Sie dann auf die Schaltfläche LÖSUNG AKZEPTIEREN
Inventor Versionen:
2025.2