Cancel
Showing results for 
Search instead for 
Did you mean: 

How to detect "Part List" - "Edit level" in nx open c#?

Experimenter
Experimenter

How to find part list - edit level details i.e. it is 1] Master Model 2] Top Level Only or 3] Leaves Only. from nx open c#.

 

Thanks in advance.

2 REPLIES

Re: How to detect "Part List" - "Edit level" in nx open c#?

Honored Contributor
Honored Contributor

The options are not necessarily mutually exclusive (e.g. the list may be "master model" and "leaves only"); also, there could be manual edits to the parts list. You can check the parts list with the .Plist.AskTraversalSettings function. The code below is in VB, but C# would be very similar.

 

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF

Module Module1

    Sub Main()

        Dim theSession As Session = Session.GetSession()
        Dim theUfSession As UFSession = UFSession.GetUFSession()
        If IsNothing(theSession.Parts.BaseWork) Then
            'active part required
            Return
        End If

        Dim workPart As Part = theSession.Parts.Work
        Dim lw As ListingWindow = theSession.ListingWindow
        lw.Open()

        Dim pListTags() As Tag
        Dim numPlist As Integer
        theUfSession.Plist.AskTags(pListTags, numPlist)

        For Each pTag As Tag In pListTags
            Dim traversalSettings As UFPlist.TraversalSettings
            theUfSession.Plist.AskTraversalSettings(pTag, traversalSettings)

            Dim i As Integer = 1

            lw.WriteLine("parts list: " & i.ToString)
            lw.WriteLine("  master model: " & traversalSettings.master_model.ToString)
            lw.WriteLine("  top level only: " & traversalSettings.top_level_only.ToString)
            lw.WriteLine("  leaves only: " & traversalSettings.leaves_only.ToString)

            i += 1

        Next

        lw.Close()

    End Sub


    Public Function GetUnloadOption(ByVal dummy As String) As Integer

        'Unloads the image immediately after execution within NX
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately

    End Function

End Module

 

Re: How to detect "Part List" - "Edit level" in nx open c#?

Experimenter
Experimenter

Thanks cowski1,

 

This is really helpfull for me, u did this in smarter and efficient way. Thank you very much.

 

I did like this..

 

 

#region "Get Information from File"
NXOpen.NXObject[] selectedObjects1 = new NXOpen.NXObject[1];
NXObject objSelected = (NXObject)NXOpen.Utilities.NXObjectManager.Get(tempTag);
selectedObjects1[0] = objSelected; 

theSession.Information.DisplayObjectsDetails(selectedObjects1);
ListingWindow lw = theSession.ListingWindow;
lw.Open();
string myDocs = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
string outputFile = System.IO.Path.Combine(myDocs, "NXOpenComponentLog.log");
theUfSession.Ui.SaveListingWindow(outputFile);

lw.Close();
lw.CloseWindow();
theUfSession.Disp.Refresh();
#endregion
#region "Fetch Informationf from File"
Hashtable htCurrentPartlistProrperties = new Hashtable();
if (System.IO.File.Exists(outputFile))
{ 
string[] lines = System.IO.File.ReadAllLines(outputFile);
string text = "Master Model:"; 
string strreturn = Array.Find(lines, element => element.Contains(text));
if (strreturn != "")
{
string[] strPartItem = strreturn.Split(':');
htCurrentPartlistProrperties.Add(strPartItem[0].Trim(), strPartItem[1].Trim());
}
text = "Top Level Only:";
strreturn = Array.Find(lines, element => element.Contains(text));
if (strreturn != "")
{
string[] strPartItem = strreturn.Split(':');
htCurrentPartlistProrperties.Add(strPartItem[0].Trim(), strPartItem[1].Trim());
}
text = "Leaves Only:";
strreturn = Array.Find(lines, element => element.Contains(text));
if (strreturn != "")
{
string[] strPartItem = strreturn.Split(':');
htCurrentPartlistProrperties.Add(strPartItem[0].Trim(), strPartItem[1].Trim());
}
}
#endregion

Now i am going to replay this thanks.Smiley Happy