Imports System Imports NXOpen Imports NXOpen.UF Imports NXOpen.UI Imports System.Windows.Forms Imports System.Environment Module NXJournal Dim theSession As Session = Session.GetSession() Dim theUfSession As UFSession = UFSession.GetUFSession() Dim workPart As Part = theSession.Parts.Work Sub Main() theUfSession.Text.SetTextMode(UFText.ModeS.AllUtf8) Dim lw As ListingWindow = theSession.ListingWindow lw.Open() Dim tabular_note As NXOpen.Tag Dim tabular_note_section As NXOpen.Tag Dim numRows As Integer = 0 Dim numCols As Integer = 0 Dim rowTag As Tag = Nothing Dim colTag As Tag = Nothing Dim cellTag As Tag = Nothing Dim comp As Assemblies.Component While select_comp("Select Componente", comp) = Selection.Response.Ok Dim historyList1() As BasePart.HistoryEventInformation historyList1 = comp.Prototype.OwningPart.GetHistoryInformation() Dim date1 As Date = historyList1(0).Time If select_a_tabular_note(tabular_note_section) = Selection.Response.Ok Then theUfSession.Disp.SetHighlight(tabular_note_section, 0) theUfSession.Tabnot.AskTabularNoteOfSection(tabular_note_section, tabular_note) theUfSession.Tabnot.AskNmColumns(tabular_note, numCols) theUfSession.Tabnot.AskNmRows(tabular_note, numRows) For j As Integer = 0 To numRows - 1 theUfSession.Tabnot.AskNthRow(tabular_note, j, rowTag) For k As Integer = 0 To numCols - 1 theUfSession.Tabnot.AskNthColumn(tabular_note, k, colTag) theUfSession.Tabnot.AskCellAtRowCol(rowTag, colTag, cellTag) Dim cellText As String = "" theUfSession.Tabnot.AskCellText(cellTag, cellText) For Each satz As String In cellText.Split(vbCrLf.ToCharArray, StringSplitOptions.RemoveEmptyEntries) For Each wort As String In satz.Split(" ") If wort = "#Datum" Then theUfSession.Tabnot.SetCellText(cellTag, Format$(Now, "dd.MM.yyyy")) ElseIf wort = "#PrtDatum" Then theUfSession.Tabnot.SetCellText(cellTag, Format$(date1, "dd.MM.yyyy")) ElseIf wort = "#Dateiname" Then cellText = cellText.Replace(wort,comp.Prototype.OwningPart.Leaf ) theUfSession.Tabnot.SetCellText(cellTag, cellText) ElseIf wort.IndexOf("#") = 0 Then cellText = cellText.Replace(wort, replace_text(comp, wort)) theUfSession.Tabnot.SetCellText(cellTag, cellText) End If Next Next Next Next End If End While End Sub Function replace_text(ByVal component1 As Assemblies.Component, ByVal attr As String) As String Dim draftingNoteBuilder1 As Annotations.DraftingNoteBuilder draftingNoteBuilder1 = workPart.Annotations.CreateDraftingNoteBuilder(Nothing) Dim text1(0) As String text1(0) = "" draftingNoteBuilder1.Text.TextBlock.SetText(text1) Dim objects1(0) As NXObject objects1(0) = component1 Dim attributePropertiesBuilder1 As AttributePropertiesBuilder attributePropertiesBuilder1 = theSession.AttributeManager.CreateAttributePropertiesBuilder(workPart, objects1, AttributePropertiesBuilder.OperationType.None) draftingNoteBuilder1.Text.TextBlock.AddAttributeReference(component1, "$PART_NAME", False, 1, 1) Dim split() As String = draftingNoteBuilder1.Text.TextBlock.GetText(0).Split("@") Dim text As String = "" text = split(0) + "@" + attr.Replace("#", "") + ">" draftingNoteBuilder1.Destroy() Return text End Function Function select_a_tabular_note(ByRef tabular_note As NXOpen.Tag) As Selection.Response Dim message As String Dim title As String = "Select a tabular note" Dim scope As Integer = UFConstants.UF_UI_SEL_SCOPE_ANY_IN_ASSEMBLY Dim response As Integer Dim obj As NXOpen.Tag Dim view As NXOpen.Tag Dim cursor(2) As Double Dim ip As UFUi.SelInitFnT = AddressOf init_proc theUfSession.Ui.LockUgAccess(UFConstants.UF_UI_FROM_CUSTOM) Try theUfSession.Ui.SelectWithSingleDialog(message, title, scope, ip, Nothing, response, tabular_note, cursor, view) Finally theUfSession.Ui.UnlockUgAccess(UFConstants.UF_UI_FROM_CUSTOM) End Try If response <> UFConstants.UF_UI_OBJECT_SELECTED Then Return Selection.Response.Cancel Else Return Selection.Response.Ok End If End Function Function init_proc(ByVal select_ As IntPtr, ByVal userdata As IntPtr) As Integer ' Selection initialization Dim num_triples As Integer = 1 Dim mask_triples(0) As UFUi.Mask mask_triples(0).object_type = UFConstants.UF_tabular_note_type mask_triples(0).object_subtype = UFConstants.UF_tabular_note_section_subtype mask_triples(0).solid_type = 0 theUfSession.Ui.SetSelMask(select_, UFUi.SelMaskAction.SelMaskClearAndEnableSpecific, num_triples, mask_triples) Return UFConstants.UF_UI_SEL_SUCCESS End Function Function select_comp(ByVal prompt As String, ByRef obj As Assemblies.Component) Dim ui As UI = GetUI() Dim mask(0) As Selection.MaskTriple With mask(0) .Type = 63 'UFConstants.UF_component_type .Subtype = 1 .SolidBodySubtype = 0 End With Dim cursor As Point3d = Nothing Dim ufs As UFSession = UFSession.GetUFSession() ufs.Ui.SetCursorView(0) Dim resp As Selection.Response = ui.SelectionManager.SelectObject(prompt, prompt, Selection.SelectionScope.AnyInAssembly, Selection.SelectionAction.ClearAndEnableSpecific, False, False, mask, obj, cursor) If resp = Selection.Response.ObjectSelected Or resp = Selection.Response.ObjectSelectedByName Then Return Selection.Response.Ok Else Return Selection.Response.Cancel End If End Function End Module