Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

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

How to play a NXJournal (.dll) or a Macro inside a NX open code?

Status
Not open for further replies.

gongi

Computer
Joined
Jul 2, 2015
Messages
2
[pre]Hi everybody!
I've been looking for the way to execute several NXJournal dll or several Macros in a certain order and I found two examples about it but neither of them work in the proper way.[/pre]

For example:
In the case of NXJournal
I found this example:

'' This example demonstrates launching another VB .NET application's Main entrypoint.

'' The Launching application might look like this:

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF

Module NXJournal
Sub Main()

Dim s As Session = Session.GetSession()
Dim ufs As UFSession = UFSession.GetUFSession()
Dim lw As ListingWindow = s.ListingWindow
lw.Open()

Dim libname As String = "launch_it.dll"
Dim fullpath As String = Nothing
ufs.UF.FindFile("application", libname, fullpath)

If fullpath Is Nothing Then
lw.WriteLine("application\" & libname & " not found")
Else
Dim nada() As Object = {} ' Main doesn't take any arguments
lw.WriteLine("Launcher will now attempt to Execute " & fullpath)
s.Execute(fullpath, "NXJournal", "Main", nada)
End If
End Sub

Function GetUnloadOption(ByVal arg As String) As Integer
Return CType(Session.LibraryUnloadOption.Immediately, Integer)
End Function
End Module



You can find that here :
but since this line: "ufs.UF.FindFile("application", libname, fullpath)" It has an error an the program stops working
the error message that is shown is: "Fatal error detected unable to continue, unhandled operating system exception: e0434352"

then I have the second solution with the macros

I found this:

Module NXJournal

Declare Sub MACRO_playback_from_usertool Lib "libugui" Alias "?MACRO_playback_from_usertool@@YAXPEBD@Z" (ByVal lpName As String)

Sub Main

MACRO_playback_from_usertool("C:\temp\test.macro")

End Sub

End Module

and it works well when I use just one macro but if I want to execute several macros like this:
Dim macro As New List(Of String)()
macro.Add("D:\Users\212464629\Desktop\run\base")
macro.Add("D:\Users\212464629\Desktop\run\componente1")
macro.Add("D:\Users\212464629\Desktop\run\componente2")
Try
For Each path As String In macro
MACRO_playback_from_usertool(path)
Next
Catch ex As Exception
MsgBox(ex.Message)
End Try

so then it just play the last Macro in the array.

So I've been searching for more information about this problem but I haven't found it yet.
If you know something more about it I will be really grateful for your help.
 
Hi again!
I found another way to solve my issue so I´m going to tell you how I solve this, in case of someone else may have the same problem.
Even Though already I have one solution, I would be very happy of receive others tips, information, recommendations and so on.

In my case I wanted to play several macros in a specific order, so I decided to concatenate each macro in another unique macro which contains the sorted macros

Dim macro As New List(Of String)()
macro.Add(My.Computer.FileSystem.ReadAllText("D:\Users\212464629\Desktop\run\macro.macro"))
macro.Add(My.Computer.FileSystem.ReadAllText("D:\Users\212464629\Desktop\run\macro2.macro"))
Dim text As String = Nothing
Dim i As Integer = 0
Try
For Each path As String In macro
If i = 0 Then 'the first macro has to be with all his header
text = path
MsgBox(path) ' this comment is just to check the content of the string
Else 'the consecutive ones has to be without their headers and in my case I decided to start concatenating since the first command which all the macros have in common, in my case "RESET"
Dim index As Integer = path.IndexOf("RESET")
text = text + path.Substring(index)
MsgBox(path.Substring(index)) ' this comment is just to check the content of the string
End If
i += 1
Next
Catch ex As Exception
MsgBox(ex.Message)
End Try
Dim _path As String = "D:\Users\212464629\Desktop\macro.macro"
Dim _file As FileStream = File.Create(_path)
Dim info As Byte() = New UTF8Encoding(True).GetBytes(text)
_file.Write(info, 0, info.Length)
_file.Close()
MACRO_playback_from_usertool(_path)
If you have a doubt about my code,just let me know it [peace]

[lightsaber] [trooper]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top