Showing results for 
Search instead for 
Did you mean: 

Call other journal inside a Journal

langauge : VB

Is it possible to call other journal inside current journal.

As Ken replied in other forum  there is no "#include" mechanism in VB at all, Can someone give an idea how should i approach ?






Re: Call other journal inside a Journal

Gears Esteemed Contributor Gears Esteemed Contributor
Gears Esteemed Contributor

You will have to merge the VB source codes together to form one single source code file.

You can specify classes, if you like to have the things a bit separate.

Stefan Pendl, Systemmanager CAx, HAIDLMAIR GmbH
Production: NX10.0.3, VERICUT 8.1, FBM, MRL 3.1.7 | TcUA 10.1 MP7 Patch 0 ( | TcVis 11.4
Development: C (ITK), .NET, Tcl/Tk Testing: NX12.0 | AWC 3.4 Preparing: NX12.0

Employees of the customers, together we are strong Smiley Wink
How to Get the Most from Your Signature in the Community
NX Customization - Best Practice Guide

Re: Call other journal inside a Journal


You can load and run methods from an other journal with some .net magic (sorry, my example is c#):


using System;
using System.Reflection;
using System.IO;
using System.CodeDom.Compiler;
using Microsoft.CSharp;
using NXOpen;
//Create compiler
ICodeCompiler compiler = new CSharpCodeProvider().CreateCompiler();
CompilerParameters parameters = new CompilerParameters();
//Add dlls required
parameters.ReferencedAssemblies.Add(@"E:\Programme\UGS\NX 6.0\ugii\managed\NXOpen.UF.dll");
parameters.ReferencedAssemblies.Add(@"E:\Programme\UGS\NX 6.0\ugii\managed\NXOpen.Utilities.dll");
//Compile it
parameters.GenerateInMemory = true;
CompilerResults compiled = compiler.CompileAssemblyFromFile(parameters,@"<Pfad>\NXJournal.cs");
if (compiled.Errors.HasErrors)
	string errorMsg = "";
	errorMsg = compiled.Errors.Count.ToString() + " Errors:";
	for (int x = 0; x < compiled.Errors.Count; x++)
	errorMsg = errorMsg + "\r\nLine: " +
		compiled.Errors[x].Line.ToString() + " - " +
	            throw new Exception(errorMsg);
//Run the Main
Assembly assembly = compiled.CompiledAssembly;
Type mainClass = assembly.GetType("NXJournal");
mainClass.GetMethod("Main").Invoke(null, new Object[] { args });

But I don't think that this is what you really want. If you only wan't to #include an other journal, do it, as stefan said, by merging the files.




Jan Böttcher

Re: Call other journal inside a Journal

Siemens Phenom Siemens Phenom
Siemens Phenom

First, let's be clear what we mean by a "journal" -- it's a bunch of source code that you're running from within the NX Journal Editor. It could be VB, C#, or Python code. There are (at least) two basic limitations with journals:


(1) Your source code has to all be in a single file


(2) The functions you call must reside in a certain small set of libraries. Specifically, in the .NET world, the special libraries are: NXOpen.dll, NXOpen.UF.dll, Snap.dll, MiniSnap.dll, System.dll, System.Windows.Forms.dll, System.Drawing.dll, and a few others. So, you can't just write some code, compile it into your own DLL, and call it from a journal.


These limitations are deliberate. The idea is that journals are for programs that you create by making small-ish modifications to recorded code. If you want to do serious large-scale programming, the assumption is that you'll buy an NXOpen or SNAP author license, and then you can compile your code, rather than running it from the Journal Editor. Compiled code doesn't have the two limitations mentioned above.


Re: Call other journal inside a Journal

Siemens Phenom Siemens Phenom
Siemens Phenom

A couple points of clarification:


  • Java code cannot be run as a journal. Only .NET (VB / C#) and Ptyhon can be executed without compilation.
  • You are limited to the small set of libraries mentioned IF you do not add any import statements in your code. The full set of .NET and Python (including NumPy, SciPy, MatPlotLob, etc.) libraries are available if you simply reference the appropriate libraries via import statements at the top of your journal.


Thus, the limitations of Journals are:

  • They must be a single file
  • That file is an ASCII format. When you distribute a journal, you are distributing source code. IP in the code cannot be protected and there is no guarantee that anyone running the code has not made improper, unauthorized or even accidental edits.

Re: Call other journal inside a Journal

Siemens Phenom Siemens Phenom
Siemens Phenom

> The full set of .NET and Python libraries are available if you simply reference the

> appropriate libraries via import statements at the top of your journal.


Let's consider .NET and Python one at a time.


In the .NET world, there is a difference between imports and references. The "Imports" statement simply reduces the amount of typing you have to do. So, for example, if you write "Imports System.Diagnostics" at the top of your file, then you can write 


instead of the long-hand


On the other hand, your "references" dictate what functions/objects you can use -- you can only use functions that reside in DLLs that you have referenced. The code in the journal editor only has references to a small number of specific DLLS (as outlined earlier), and you can only call the code in these DLLs. Adding an "Imports" statement will not change this.


So, for example, consider the following VB code (in the Journal Editor): 

Imports System.Diagnostics
Imports System.Numerics

Public Class MyProgram

    Public Shared Sub Main

      System.Diagnostics.Process.Start("notepad.exe")  ' [1] Works
      Process.Start("notepad.exe")                     ' [2] Works

      Dim z1 As New System.Numerics.Complex(2, 3)      ' [3] Fails

      Dim z2 As New Complex(4, 5)                      ' [4] Fails

    End Sub

End Class

Line [1] works because the System.Diagnostics.Process.Start function resides in System.dll, and this is one of the special DLLs referenced from the Journal Editor.


Line [2] works. The Imports statement in the first line of code allows us to use the short name "Process.Start" instead of the full name  "System.Diagnostics.Process.Start".


Lines [3] and [4] both fail because the Complex class is defined in the System.Numerics DLL, and this is not referenced from the Journal Editor. Writing "Imports System.Numerics" does not change this.


I don't know much about Python, but I think it doesn't have "references" in the .NET sense. So, I expect that Python code in the Journal Editor can call any function you like, in any library/module whatsoever.