cancel
Showing results for 
Search instead for 
Did you mean: 

How toget NX Version of any*.prt File in which it was last saved?(in Windows / without NXopen/Ufunc)

Creator
Creator

How Get NX Version of any*.prt File in which it was last saved?

 

Preferably without initializing NXOpen.

 

Is there some calls in VB.net which can fetch a particular attribute or some metadeta in a *.prt file which a standalone Windows Application can fetch?

8 REPLIES

Re: How Get NX Version of any*.prt File in which it was last saved?

Solution Partner Genius Solution Partner Genius
Solution Partner Genius

Hello,

 

You can init with this: BasePart.HistoryEventInformation

 

              //Creo variable groupTag de tipo Tag
              Tag groupTag = Tag.Null;
              //Creo variable aGroup de tipo grupo
              Group aGroup = null;
              //Creo variable groupBuilder1 de tipo GroupBuilder
              GroupBuilder groupBuilder1 = default(GroupBuilder);
              //Creo una variable miembros de tipo TaggedObject[]
              TaggedObject[] members = null;
              //Tag[] ufmembers = null;
              //int n_members = 0;
              //Creo variable gName de tipo string
              string gName = "NoName";
              
              //Aqui debo comparar versión de cada una de las piezas
              BasePart.HistoryEventInformation[] info = aPart.GetHistoryInformation();
              comparar_version(info[0], info[1], aPart.Leaf);         

 

          public static void comparar_version (BasePart.HistoryEventInformation actual, BasePart.HistoryEventInformation anterior, string nombre )
          {
              
              
              try {
                  
                  //Mbox.Show("Comparando", NXMessageBox.DialogType.Information,"Comparando pieza: " + nombre);
                  
                  //Declaro dos string para modificar los originales
                  string version_actual = null;
                  string version_anterior = null;
                  
                  //Mbox.Show("Versión actual", NXMessageBox.DialogType.Information,"valor actual: " + actual.Program);
                  //Mbox.Show("Versión anterior", NXMessageBox.DialogType.Information,"valor anterior: " + anterior.Program);
                  
                  //Me quedo con la parte de la versión
                  version_actual = actual.Program.Substring( 3, 2);
                  version_anterior = anterior.Program.Substring( 3, 2);
                  
                  //Quito el punto si la versión es menor de 10
                  char[] charsToTrim = {'.'};
                  string[] coger_version_actual = version_actual.Split(charsToTrim);
                  string[] coger_version_anterior = version_anterior.Split(charsToTrim);
                  
                  //Convierto el string a int
                  int valor_actual = Int32.Parse(coger_version_actual[0]);
                  int valor_anterior = Int32.Parse(coger_version_anterior[0]);
                  
                  //Saco un mensaje de información en el caso de que la version actual sea mayor que la version anterior
                  if (valor_actual > valor_anterior)
                  {
                      
                      if (flag_respuesta) {
                          
                          respuesta = Mbox.Show("Versión de pieza",
                                                NXMessageBox.DialogType.Question,
                                                "La pieza " + displayPart.Leaf + " fue guardada con la version NX"
                                                + valor_anterior.ToString() + "\n\n¿Desea dejar esta pieza y las siguientes como solo lectura?");
                          flag_respuesta = false;
                          
                      }
                      
                      // Si respondo que si pongo la pieza como solo lectura, sino quito el atributo de solo lectura
                      if (respuesta == 1) {
                          Rus.SetFileWritable(displayPart.FullPath, false);
                      } else {
                          Rus.SetFileWritable(displayPart.FullPath, true);
                      }
                      
                      //informe.Add("*       ==>Pieza con diferentes versiones verificada: " + nombre);
                      //return " ==>Pieza con diferentes versiones verificada: ";
                      
                  } else {
                      
                      //informe.Add("*       ==>Pieza en la misma versión verificada: " + nombre);
                      //return " ==>Pieza en la misma versión verificada: ";
                  }
                  
              } catch (Exception) {
                  
                  //Echo("Numero de valor de error: " + valorError.ToString());
                  informe.Add("*       ==>No ha sido posible verificar versión de pieza por no tener suficiente historico en la pieza: " + nombre);
                  valorError++;
                  
                  
              }
              
          }

 

 

Re: How toget NX Version of any*.prt File in which it was last saved?(in Windows / without NXopen/Uf

Esteemed Contributor
Esteemed Contributor

There is a command line utility that can be used to get the release information of a part file without using NXOpen.

For NX 10 and below use the following for more information:

"%UGII_BASE_DIR%\UGII\ug_inspect.exe" -help

For NX 11 and above it is this:

"%UGII_BASE_DIR%\NXBIN\ug_inspect.exe" -help
Stefan Pendl, Systemmanager CAx, HAIDLMAIR GmbH
Production: NX10.0.3, VERICUT 8.0, FBM, MRL 3.1.4 | TcUA 10.1 MP7 Patch 0 (10.1.7.0) | TcVis 10.1
Development: VB.NET, Tcl/Tk    Testing: NX11.0 EAP, NX12.0 EAP

How to Get the Most from Your Signature in the Community

Re: How toget NX Version of any*.prt File in which it was last saved?(in Windows / without NXopen/Uf

Creator
Creator

Stefan_Pendl wrote:

There is a command line utility that can be used to get the release information of a part file without using NXOpen.

For NX 10 and below use the following for more information:

"%UGII_BASE_DIR%\UGII\ug_inspect.exe" -help

For NX 11 and above it is this:

"%UGII_BASE_DIR%\NXBIN\ug_inspect.exe" -help

@Stefan_Pendl Thanks for the response. This does provide me with the NX Version the part was Last Saved in, but along with huge amount of other part related data. If I were to write another exe to fetch the just the reqd details, I would need to have this exe called(referenced) in the backgound.

 

I was more keenly looking at what function calls this EXE makes(or any other way/approach) to fetch just the specific information i.e the Last saved NX version of a given *.prt file. So that a single utility(exe) can be written similar to this one which specifically provides just the last saved NX version of a *.prt file.

 

Thanks in Advance,

Vinay

 

Re: How Get NX Version of any*.prt File in which it was last saved?

Creator
Creator

CristianMiguel wrote:

Hello,

 

You can init with this: BasePart.HistoryEventInformation

 

              //Creo variable groupTag de tipo Tag
              Tag groupTag = Tag.Null;
              //Creo variable aGroup de tipo grupo
              Group aGroup = null;
              //Creo variable groupBuilder1 de tipo GroupBuilder
              GroupBuilder groupBuilder1 = default(GroupBuilder);
              //Creo una variable miembros de tipo TaggedObject[]
              TaggedObject[] members = null;
              //Tag[] ufmembers = null;
              //int n_members = 0;
              //Creo variable gName de tipo string
              string gName = "NoName";
              
              //Aqui debo comparar versión de cada una de las piezas
              BasePart.HistoryEventInformation[] info = aPart.GetHistoryInformation();
              comparar_version(info[0], info[1], aPart.Leaf);         

 

          public static void comparar_version (BasePart.HistoryEventInformation actual, BasePart.HistoryEventInformation anterior, string nombre )
          {
              
              
              try {
                  
                  //Mbox.Show("Comparando", NXMessageBox.DialogType.Information,"Comparando pieza: " + nombre);
                  
                  //Declaro dos string para modificar los originales
                  string version_actual = null;
                  string version_anterior = null;
                  
                  //Mbox.Show("Versión actual", NXMessageBox.DialogType.Information,"valor actual: " + actual.Program);
                  //Mbox.Show("Versión anterior", NXMessageBox.DialogType.Information,"valor anterior: " + anterior.Program);
                  
                  //Me quedo con la parte de la versión
                  version_actual = actual.Program.Substring( 3, 2);
                  version_anterior = anterior.Program.Substring( 3, 2);
                  
                  //Quito el punto si la versión es menor de 10
                  char[] charsToTrim = {'.'};
                  string[] coger_version_actual = version_actual.Split(charsToTrim);
                  string[] coger_version_anterior = version_anterior.Split(charsToTrim);
                  
                  //Convierto el string a int
                  int valor_actual = Int32.Parse(coger_version_actual[0]);
                  int valor_anterior = Int32.Parse(coger_version_anterior[0]);
                  
                  //Saco un mensaje de información en el caso de que la version actual sea mayor que la version anterior
                  if (valor_actual > valor_anterior)
                  {
                      
                      if (flag_respuesta) {
                          
                          respuesta = Mbox.Show("Versión de pieza",
                                                NXMessageBox.DialogType.Question,
                                                "La pieza " + displayPart.Leaf + " fue guardada con la version NX"
                                                + valor_anterior.ToString() + "\n\n¿Desea dejar esta pieza y las siguientes como solo lectura?");
                          flag_respuesta = false;
                          
                      }
                      
                      // Si respondo que si pongo la pieza como solo lectura, sino quito el atributo de solo lectura
                      if (respuesta == 1) {
                          Rus.SetFileWritable(displayPart.FullPath, false);
                      } else {
                          Rus.SetFileWritable(displayPart.FullPath, true);
                      }
                      
                      //informe.Add("*       ==>Pieza con diferentes versiones verificada: " + nombre);
                      //return " ==>Pieza con diferentes versiones verificada: ";
                      
                  } else {
                      
                      //informe.Add("*       ==>Pieza en la misma versión verificada: " + nombre);
                      //return " ==>Pieza en la misma versión verificada: ";
                  }
                  
              } catch (Exception) {
                  
                  //Echo("Numero de valor de error: " + valorError.ToString());
                  informe.Add("*       ==>No ha sido posible verificar versión de pieza por no tener suficiente historico en la pieza: " + nombre);
                  valorError++;
                  
                  
              }
              
          }

 

 



Thanks @CristianMiguel for the response,

 

Im afraid this references to NXopen calls, Looking for a approach that doesnot involve NXopen.

 

Regards,

Vinay

Re: How toget NX Version of any*.prt File in which it was last saved?(in Windows / without NXopen/Uf

Esteemed Contributor
Esteemed Contributor

The last line displayed by the help switch says:

-release   Just print release information about the part.

Should be strait forward when reading the entire usage information Smiley Wink

Stefan Pendl, Systemmanager CAx, HAIDLMAIR GmbH
Production: NX10.0.3, VERICUT 8.0, FBM, MRL 3.1.4 | TcUA 10.1 MP7 Patch 0 (10.1.7.0) | TcVis 10.1
Development: VB.NET, Tcl/Tk    Testing: NX11.0 EAP, NX12.0 EAP

How to Get the Most from Your Signature in the Community

Re: How toget NX Version of any*.prt File in which it was last saved?(in Windows / without NXopen/Uf

Creator
Creator

@Stefan_Pendl Thanks for that information, I had tried the -release switch earlier and had worked well, was trying to see if I could get the sub version also if possible.

 

Neverthe less, the solution what you have mentioned is acceptable. Thanks a lot.

Re: How toget NX Version of any*.prt File in which it was last saved?(in Windows / without NXopen/Uf

Esteemed Contributor
Esteemed Contributor

UG_INSPECT will only display the major release with the -release switch.

To get the full release string with major, minor and patch, you would need to parse the filing history.

You could always create an enhencement request at GTAC for a -full_release switch.

Stefan Pendl, Systemmanager CAx, HAIDLMAIR GmbH
Production: NX10.0.3, VERICUT 8.0, FBM, MRL 3.1.4 | TcUA 10.1 MP7 Patch 0 (10.1.7.0) | TcVis 10.1
Development: VB.NET, Tcl/Tk    Testing: NX11.0 EAP, NX12.0 EAP

How to Get the Most from Your Signature in the Community

Re: How toget NX Version of any*.prt File in which it was last saved?(in Windows / without NXopen/Uf

Esteemed Contributor
Esteemed Contributor

Created an ER on my own, so anyone interested in this feature can ask to be added to ER#7915103 through GTAC.

In addition the service engineer was so kind to provide a temporary solution through NXOpen API. The drawback of the NXOpen API method is that it consumes a NX license, so if run on a server it uses an additional NX gateway license.

report_specified_part_version_from_history.cs:

using System;
using NXOpen;
using NXOpen.UF;
using NXOpen.Utilities;
 
public class PartVersion
{
    static Session theSession = Session.GetSession();
    static UFSession theUFSession = UFSession.GetUFSession();
    static ListingWindow theLW = theSession.ListingWindow;
    static Part workPart = theSession.Parts.Work;
 
    static void DoIt()
    {
        BasePart.HistoryEventInformation[] histories = workPart.GetHistoryInformation();
        if( histories.Length > 1 )
        {
            // The first entry is the 'loaded' version
            // The second entry is the 'last saved' version
            Echo( "Last saved version: " + histories[1].Program.Split(new Char[]{','})[0] );
        }
        else
            Echo( "Part not saved yet." );
    }
 
    public static void Main(string[] args)
    {
        if (workPart != null)
        {
            DoIt();
            return;
        }
 
        PartLoadStatus loadStatus;
 
        for (int ii = 0; ii < args.Length; ii++)
        {
            Echo("Processing: " + args[ii]);
            workPart = (Part)theSession.Parts.OpenBaseDisplay(args[ii], out loadStatus);
            reportPartLoadStatus(loadStatus);
 
            if (workPart != null)
            {
                DoIt();
                workPart.Close(BasePart.CloseWholeTree.True, BasePart.CloseModified.CloseModified, null);
            }
        }
    }
 
    static void Echo(string output)
    {
        if( !theLW.IsOpen ) theLW.Open();
        theLW.WriteLine(output);
    }
 
    static void reportPartLoadStatus(PartLoadStatus load_status)
    {
        if (load_status.NumberUnloadedParts == 0) return;
 
        Echo("  Load notes:");
 
        for (int ii = 0; ii < load_status.NumberUnloadedParts; ii++)
        {
            Echo("  " + load_status.GetPartName(ii) + " - "
                    + load_status.GetStatusDescription(ii));
        }
    }
 
    public static int GetUnloadOption(string arg)
    {
        return System.Convert.ToInt32(Session.LibraryUnloadOption.Immediately);
    }
}

External Usage from a NX Command Prompt:

  1. either compiled as C# Executable:
    • report_specified_part_version_from_history.exe gtac.prt
  2. or non-compiled:
    • run_journal report_specified_part_version_from_history.cs -args gtac.prt

Sample output:

  • "Last saved version: NX 11.0.0.33 MP2"

 

Stefan Pendl, Systemmanager CAx, HAIDLMAIR GmbH
Production: NX10.0.3, VERICUT 8.0, FBM, MRL 3.1.4 | TcUA 10.1 MP7 Patch 0 (10.1.7.0) | TcVis 10.1
Development: VB.NET, Tcl/Tk    Testing: NX11.0 EAP, NX12.0 EAP

How to Get the Most from Your Signature in the Community