Hello,
Task:
I want to paste a text from the clipboard into a text annotation to my Drawing.
Problem:
For some reason, as soon as I paste it with the Journal, in NX I see a shortert text, the first few characters are always cut off.
Someone can help the fix my Code?
Details:
Original text copied from Excel::
Material: Stahl
Guete: Anlehnend an S235
Qualitaetsrichtlinie: QRL 10.18-001 Ergebnis
Results after Execution of the Journal::
Material: Stahl
te: Anlehnend an S235
taetsrichtlinie: QRL 10.18-001 Ergebnis
Option Strict Off
Imports System
Imports NXOpen
Module NXJournal
Sub Main (ByVal args() As String)
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
Dim drawingSheet1 As Drawings.DrawingSheet = Workpart.DrawingSheets.CurrentDrawingSheet
Dim drawingSheetBuilder1 As Drawings.DrawingSheetBuilder
drawingSheetBuilder1 = workPart.DrawingSheets.DrawingSheetBuilder(drawingSheet1)
Dim Hoehe As String = drawingSheetBuilder1.Height
Dim Laenge As String = drawingSheetBuilder1.Length
Dim Pos_X As String = Laenge/4
Dim Pos_Y As String = Hoehe/4
Dim text1(1000) As String
text1(0) = My.Computer.Clipboard.GetText
Dim nullAnnotations_SimpleDraftingAid As Annotations.SimpleDraftingAid = Nothing
Dim draftingNoteBuilder1 As Annotations.DraftingNoteBuilder
draftingNoteBuilder1 = workPart.Annotations.CreateDraftingNoteBuilder(nullAnnotations_SimpleDraftingAid)
Dim letteringPreferences1 As Annotations.LetteringPreferences
letteringPreferences1 = workPart.Annotations.Preferences.GetLetteringPreferences()
draftingNoteBuilder1.Text.TextBlock.SetText(text1)
draftingNoteBuilder1.Style.LetteringStyle.Angle = 0.0
draftingNoteBuilder1.Style.LetteringStyle.GeneralTextCharSpaceFactor = 1.0
draftingNoteBuilder1.Style.LetteringStyle.GeneralTextSize = 2.50
Dim nullView As View = Nothing
Dim point1 As Point3d = New Point3d(Pos_X, Pos_Y, 0.0)
draftingNoteBuilder1.Origin.Origin.SetValue(Nothing, nullView, point1)
Dim nXObject1 As NXObject
nXObject1 = draftingNoteBuilder1.Commit()
draftingNoteBuilder1.Destroy()
End Sub
End Module
re: clipboard to note
Please try the following:
Option Strict Off
Imports System
Imports NXOpen
Module clipboard_to_note
Sub Main(ByVal args() As String)
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
Dim drawingSheet1 As Drawings.DrawingSheet = workPart.DrawingSheets.CurrentDrawingSheet
Dim drawingSheetBuilder1 As Drawings.DrawingSheetBuilder
drawingSheetBuilder1 = workPart.DrawingSheets.DrawingSheetBuilder(drawingSheet1)
Dim Hoehe As String = drawingSheetBuilder1.Height
Dim Laenge As String = drawingSheetBuilder1.Length
Dim Pos_X As String = Laenge / 4
Dim Pos_Y As String = Hoehe / 4
If Not My.Computer.Clipboard.ContainsText Then
'no text on the clipboard
Return
End If
Dim text1 As String = Nothing
text1 = My.Computer.Clipboard.GetText()
Dim lines As String() = text1.Split(New String() {Environment.NewLine}, StringSplitOptions.None)
Dim nullAnnotations_SimpleDraftingAid As Annotations.SimpleDraftingAid = Nothing
Dim draftingNoteBuilder1 As Annotations.DraftingNoteBuilder
draftingNoteBuilder1 = workPart.Annotations.CreateDraftingNoteBuilder(nullAnnotations_SimpleDraftingAid)
Dim letteringPreferences1 As Annotations.LetteringPreferences
letteringPreferences1 = workPart.Annotations.Preferences.GetLetteringPreferences()
draftingNoteBuilder1.Text.TextBlock.SetText(lines)
draftingNoteBuilder1.Style.LetteringStyle.Angle = 0.0
draftingNoteBuilder1.Style.LetteringStyle.GeneralTextCharSpaceFactor = 1.0
draftingNoteBuilder1.Style.LetteringStyle.GeneralTextSize = 2.5
Dim nullView As View = Nothing
Dim point1 As Point3d = New Point3d(Pos_X, Pos_Y, 0.0)
draftingNoteBuilder1.Origin.Origin.SetValue(Nothing, nullView, point1)
Dim nXObject1 As NXObject
nXObject1 = draftingNoteBuilder1.Commit()
draftingNoteBuilder1.Destroy()
End Sub
End Module
Thank you :)
Great it works. Thank you.
String.Split Methode
Just a simple EngineerGuy :)