cancel
Showing results for 
Search instead for 
Did you mean: 

Run a Journal in Post

Valued Contributor
Valued Contributor

Hello there,

 

I have written a journal to get a snapshot of the model shown in NX. I want to run this journal in a post, so that when I post processed a machining operation, I can get a setup picture. This picture will be used in a tool sheet.

 

How can I run a journal in a post?

 

Thanks,

Kai

3 REPLIES

Re: Run a Journal in Post

Esteemed Contributor
Esteemed Contributor

I don't think you can run a *journal*.

 

You can register & run a compiled/linked DLL (I've done it in C/C++, but I believe it can be written in any "common API" supported language).

 

In the docs, search for MOM_run_user_function (post command) and UF_MOM_extend_translator (API call)

I believe there are some examples in the Solutions database (https://solutions.industrysoftware.automation.siemens.com/)

Ken Akerboom Sr CAx Systems Engr, Moog, Inc.
Production: NX10.0.3.5 MP5 + patch/TC11.2
I'd rather be e-steemed than e-diseaseled


Re: Run a Journal in Post

Valued Contributor
Valued Contributor

Thanks, Ken. I found relevant examples on the link, and created the following vb file:

  

Option Strict Off
Imports System
Imports System.IO
Imports NXOpen
Imports NXOpen.CAM
Imports NXOpen.UF
Imports NXOpen.Utilities

Module SnapShot

    Dim theSession As Session = Session.GetSession()
    Dim m_UI As UI = UI.GetUI()
    Dim theUfSession As UFSession = UFSession.GetUFSession()
	
	Function Entry_snap_shot(ByVal Param As String) As Integer
	
		Dim mom_id As System.IntPtr 
		theUfSession.Mom.AskMom(Param, mom_id) 
		theUfSession.Mom.ExtendXlator(mom_id, "EXTN_snap_shot", AddressOf extn_snap_shot) 
		Return 0 
		
	End Function
	
	Function extn_snap_shot(ByVal argv() As String) As Integer
	
		'Dim imageFile As String = "D:\\WORK\\SetupImage.gif"
		Dim imageFile As String = argv
		
		Dim image_format As UFDisp.ImageFormat = UFDisp.ImageFormat.Gif
		Dim background_color As UFDisp.BackgroundColor = UFDisp.BackgroundColor.White
		
		Try
            Dim path As String = IO.Path.GetFullPath(imageFile)
            theUfSession.Disp.CreateImage(imageFile, image_format, background_color)
            Echo("Image Generated at :-" & path)
        Catch ex As Exception
            Echo("Image Generated Failed" & ex.Message)
        End Try
	
	End Function
	
	Sub Echo(ByVal output As String)

        theSession.ListingWindow.Open()
        theSession.ListingWindow.WriteLine(output)
        theUfSession.UF.PrintSyslog(output & vbCrLf, False)

        End Sub
	
	Function GetUnloadOption(ByVal dummy As String) As Integer

        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Explicitly

        End Function
	
End Module	

 

I call the functions in a post with the following tcl code:

  

global URC_external_lib_doc_functions

    #   Tell PB where to find the user-function
	set URC_external_lib_doc_functions "D:\\WORK\\Snapshot.dll"
    #   Initialize the entry point as defined in the .dll file
    MOM_run_user_function $URC_external_lib_doc_functions "Entry_snap_shot"
	
    global mom_operation_name
    global mom_group_name
    global mom_output_file_directory
    global mom_output_file_basename
    global mom_output_file_suffix
    global mom_path_name

  if {[info exists mom_group_name] == 1} {
           set name ${mom_output_file_directory}${mom_output_file_basename}${mom_output_file_suffix}
   } else {
           set name ${mom_output_file_directory}${mom_path_name}
   }


  #   Define the file extension as well as the folder where the generated
    #   images will be saved.
    set suffix ".gif"
    set name "${name}$suffix"

    #   Create the snap-shot
    EXTN_snap_shot $name

When I postprocessed an operation with the post, NX gave me the following error:

  

Caught exception while running: Entry_snap_shot
System.InvalidCastException: Conversion from string "      " to type 'Long' is not valid. ---> System.FormatException: Input string was not in a correct format.
   at Microsoft.VisualBasic.CompilerServices.Conversions.ParseDecimal(String Value, NumberFormatInfo NumberFormat)
   at Microsoft.VisualBasic.CompilerServices.Conversions.ToLong(String Value)
***TCL_ERROR***: Event Handler: D:\WORK\post\Mats\Matsuura_RA-3G2_list.tcl, Event: MOM_machine_mode, Error: invalid command name "EXTN_snap_shot"
    while executing
"EXTN_snap_shot $name"
    (procedure "PB_CMD_init_for_extended_libraries" line 49)
    invoked from within
"PB_CMD_init_for_extended_libraries"
    (procedure "PB_start_of_program" line 9)

Do you have any ideas?

 

Thanks,

Kai

Re: Run a Journal in Post

Esteemed Contributor
Esteemed Contributor

You need a Main() function, which is then called by the ufusr entry point.

NX does only support a limited set of pre-defined entry points, see the .NET programmers reference for the list and syntax.

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

Learn online





Solution Information