Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Journal to set cell settings and export Parts List

jtozer

Aerospace
Aug 8, 2018
14
US
We have an internal system that we upload the comma separated text file Parts List Export to. This system reads each line to help automate component ordering for tooling packages. We need all the text in the Parts List cells to be on one line for the exported text file to be formated correctly for this internal system.

I am trying to create a journal to set the Parts List cell preference fit methods to force all the text in the cell to one line (AutoSizeRow and AutoSizeText on, Wrap and all other off) then export the Parts List to a comma separated text file. I started with the example Parts List export journal and figured out how to get the cell preferences set, but it takes over 1 second per cell and that speed is just not acceptable for what I want to accomplish.
When setting the cell preferences manually it only takes a few seconds total, so I don't know why it takes so long this way, aside from the fact that I'm using a different method.

I tried using the TableEditSettingsBuilder from a recorded journal, but I couldn't figure out how to send the correct object to that function.

Can someone tell me how to speed this process up or suggest a different method of automatically changing the Parts List cell settings?

Code that works, but is slow:
Code:
Option Strict Off

Imports System
Imports NXOpen
Imports NXOpen.Annotations
Imports NXOpen.Assemblies
Imports NXOpen.BlockStyler
Imports NXOpen.Diagramming
Imports NXOpen.UF
Imports NXOpen.UI
Imports NXOpen.Utilities

Module NXJournal

    Dim s As Session = Session.GetSession()
    Dim ufs As UFSession = UFSession.GetUFSession()
    Dim lw As ListingWindow = s.ListingWindow
    Dim wPart As NXOpen.Part = s.Parts.Work

    Sub Main()
        lw.Open()
        Dim my_plist As NXOpen.Tag = NXOpen.Tag.Null
        Dim dispPart As NXOpen.Tag = s.Parts.Display.Tag
        Dim markId1 As NXOpen.Session.UndoMarkId = Nothing
        markId1 = s.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Do update")

        my_plist = GetPlistTagVal(dispPart)

        Dim r As Integer
        Dim c As Integer
        Dim i As Integer
        If my_plist <> NXOpen.Tag.Null Then
            Try
                Dim numCol As Integer = 0
                Dim numRow As Integer = 0
                Dim rowTag As NXOpen.Tag = NXOpen.Tag.Null
                Dim colTag As NXOpen.Tag = NXOpen.Tag.Null
                Dim cellTag As NXOpen.Tag = NXOpen.Tag.Null
                Dim cellDispOb() As NXOpen.DisplayableObject
                ReDim cellDispOb(1)
                Dim cPrefs As UFTabnot.CellPrefs = Nothing

                ufs.Tabnot.AskNmColumns(my_plist, numCol)
                ufs.Tabnot.AskNmRows(my_plist, numRow)

                If numCol > 0 And numRow > 0 Then
                    ufs.Disp().SetDisplay(UFConstants.UF_DISP_SUPPRESS_DISPLAY)
                    For r = 0 To numRow - 1
                        ufs.Tabnot.AskNthRow(my_plist, r, rowTag)
                        For c = 0 To numCol - 1
                            ufs.Tabnot.AskNthColumn(my_plist, c, colTag)
                            ufs.Tabnot.AskCellAtRowCol(rowTag, colTag, cellTag)
                            'MsgBox(cellTag.ToString())
                            ufs.Tabnot.AskCellPrefs(cellTag, cPrefs)
                            For i = 0 To cPrefs.fit_methods.Length - 1
                                'MsgBox(cPrefs.fit_methods(i).ToString())
                                cPrefs.fit_methods(1) = UFTabnot.FitMethod.FitMethodNone
                            Next
                            'cPrefs.fit_methods.
                            cPrefs.fit_methods(0) = UFTabnot.FitMethod.FitMethodAutoSizeRow
                            cPrefs.fit_methods(1) = UFTabnot.FitMethod.FitMethodAutoSizeText

                            ufs.Tabnot.SetCellPrefs(cellTag, cPrefs)

                        Next
                    Next
                    ufs.Disp().SetDisplay(UFConstants.UF_DISP_UNSUPPRESS_DISPLAY)
                    ufs.Disp.RegenerateDisplay()
                End If
                MsgBox("Table Formatted")
                's.UpdateManager.DoUpdate(markId1)
                Dim filename As String = "c:\Temp\plist_out.txt"

                'master_model
                'top_level_only
                'leaves_only
                ufs.Plist.ListToFile(my_plist, filename, 1, "")
            Catch ex As Exception
                MsgBox("Row: " & r & " Col: " & c & vbCr & ex.ToString())
            End Try

            ufs.Disp().SetDisplay(UFConstants.UF_DISP_UNSUPPRESS_DISPLAY)
            ufs.Disp.RegenerateDisplay()

        End If

    End Sub

    Public Function GetPlistTagVal(ByRef partTag As NXOpen.Tag) As NXOpen.Tag

        Dim tempTag As NXOpen.Tag = NXOpen.Tag.Null
        Dim type As Integer
        Dim subtype As Integer

        Do
            ufs.Obj.CycleObjsInPart(partTag,
            UFConstants.UF_tabular_note_type, tempTag)

            ufs.Obj.AskTypeAndSubtype(tempTag, type, subtype)

            If subtype = UFConstants.UF_parts_list_subtype Then
                Return tempTag
            End If

        Loop Until tempTag = NXOpen.Tag.Null
        Return NXOpen.Tag.Null
    End Function

    Public Function GetUnloadOption(ByVal dummy As String) As Integer

        Return Session.LibraryUnloadOption.Immediately

    End Function

End Module


Recorded journal of setting the preferences of a single cell:
C#:
// NX 2206
// Journal created by 212331576 on Thu Oct 31 10:47:16 2024 Eastern Daylight Time
//
using System;
using NXOpen;

public class NXJournal
{
  public static void Main(string[] args)
  {
    NXOpen.Session theSession = NXOpen.Session.GetSession();
    NXOpen.Part workPart = theSession.Parts.Work;
    NXOpen.Part displayPart = theSession.Parts.Display;
    // ----------------------------------------------
    //   Menu: Edit->Table->Settings...
    // ----------------------------------------------
    NXOpen.Session.UndoMarkId markId1;
    markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start");
   
    NXOpen.DisplayableObject[] objects1 = new NXOpen.DisplayableObject[1];
    NXOpen.DisplayableObject displayableObject1 = ((NXOpen.DisplayableObject)workPart.FindObject("HANDLE R-171268"));
    objects1[0] = displayableObject1;
    NXOpen.Annotations.TableEditSettingsBuilder tableEditSettingsBuilder1;
    tableEditSettingsBuilder1 = workPart.SettingsManager.CreateTableEditSettingsBuilder(objects1);
   
    theSession.SetUndoMarkName(markId1, "Settings Dialog");
   
    NXOpen.Drafting.BaseEditSettingsBuilder[] editsettingsbuilders1 = new NXOpen.Drafting.BaseEditSettingsBuilder[1];
    editsettingsbuilders1[0] = tableEditSettingsBuilder1;
    workPart.SettingsManager.ProcessForMultipleObjectsSettings(editsettingsbuilders1);
   
    NXOpen.Session.UndoMarkId markId2;
    markId2 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Settings");
   
    NXOpen.Annotations.TableCellStyleBuilder.FitMethodType[] fitmethods1 = new NXOpen.Annotations.TableCellStyleBuilder.FitMethodType[3];
    fitmethods1[0] = NXOpen.Annotations.TableCellStyleBuilder.FitMethodType.Wrap;
    fitmethods1[1] = NXOpen.Annotations.TableCellStyleBuilder.FitMethodType.AutoSizeRow;
    fitmethods1[2] = NXOpen.Annotations.TableCellStyleBuilder.FitMethodType.AutoSizeText;
    tableEditSettingsBuilder1.TableCell.SetFitMethods(fitmethods1);
   
    theSession.SetUndoMarkName(markId2, "Settings - FIt Methods");
   
    theSession.SetUndoMarkVisibility(markId2, null, NXOpen.Session.MarkVisibility.Visible);
   
    theSession.SetUndoMarkVisibility(markId1, null, NXOpen.Session.MarkVisibility.Invisible);
   
    NXOpen.Session.UndoMarkId markId3;
    markId3 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Settings");
   
    NXOpen.Annotations.TableCellStyleBuilder.FitMethodType[] fitmethods2 = new NXOpen.Annotations.TableCellStyleBuilder.FitMethodType[2];
    fitmethods2[0] = NXOpen.Annotations.TableCellStyleBuilder.FitMethodType.AutoSizeRow;
    fitmethods2[1] = NXOpen.Annotations.TableCellStyleBuilder.FitMethodType.AutoSizeText;
    tableEditSettingsBuilder1.TableCell.SetFitMethods(fitmethods2);
   
    theSession.SetUndoMarkName(markId3, "Settings - FIt Methods");
   
    theSession.SetUndoMarkVisibility(markId3, null, NXOpen.Session.MarkVisibility.Visible);
   
    theSession.SetUndoMarkVisibility(markId1, null, NXOpen.Session.MarkVisibility.Invisible);
   
    NXOpen.Session.UndoMarkId markId4;
    markId4 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Settings");
   
    NXOpen.Session.UndoMarkId markId5;
    markId5 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Settings");
   
    NXOpen.NXObject nXObject1;
    nXObject1 = tableEditSettingsBuilder1.Commit();
   
    theSession.DeleteUndoMark(markId5, null);
   
    theSession.SetUndoMarkName(markId1, "Settings");
   
    tableEditSettingsBuilder1.Destroy();
   
    theSession.DeleteUndoMark(markId4, null);
   
    theSession.SetUndoMarkVisibility(markId1, null, NXOpen.Session.MarkVisibility.Visible);
   
    theSession.DeleteUndoMark(markId3, null);
   
    theSession.DeleteUndoMark(markId2, null);
   
    // ----------------------------------------------
    //   Menu: Tools->Journal->Stop Recording
    // ----------------------------------------------
   
  }
  public static int GetUnloadOption(string dummy) { return (int)NXOpen.Session.LibraryUnloadOption.Immediately; }
}
 
Replies continue below

Recommended for you

Have you tried the "theUfSession.Plist.ListToFile" method? You'd probably have to post process the file to get CSV output, but it may get you close.
 
Have you tried the "theUfSession.Plist.ListToFile" method? You'd probably have to post process the file to get CSV output, but it may get you close.
I am using the Plist.ListToFile method to export the list, however I didn't realize it only exported in tab-delimited, I'll have to look into that.

The issue with wrapped text that I am trying to solve is still an issue with that method. Each line of text in the parts list gets a line in the output file, so if an attribute is large enough to wrap the text to a new line inside the cell, the output file will have a mostly blank line, except for the wrapped text and that messes with the system we are importing the list into.
An example is below. The last column has "AUTOMATION" and "DIRECT" on 2 separate lines even though they are in the same cell in the parts list as "AUTOMATION DIRECT"
Code:
        17      1       STK              -               -                         TERMINAL WIRING BLOCK       DN-T10-A        AUTOMATION             
                                                                                                                                DIRECT

If I'm already post-processing the file programmatically to convert it to csv, this problem may no longer be an NX function problem though.
 
Sorry, I should have read your code more closely. I saw that you were iterating through each cell and assumed you were writing out the text yourself.... Which may be the way to go here. You could grab the displayed text from each cell and not have to worry about cell style preferences.
 

Part and Inventory Search

Sponsor

Back
Top