×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

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

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

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

(OP)
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. 

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 : http://www.eng-tips.com/viewthread.cfm?qid=327153

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.



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

(OP)
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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources