Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Journal or Macro to run .EXE files

Status
Not open for further replies.

Kenja824

Automotive
Nov 5, 2014
949
We have an .EXE file that we would like to create a button to automatically run. When I recorded a Macro to run it, it only partially worked. We would hit the button and the macro would run like it is supposed to. But at one point when the exe file goes into a second part where the user is supposed to select something, the exe file stops working correctly. It will allow you to select what you need to select in its options but its as if its buttons stop controlling anything. .... HOWEVER ..... If we hit CTRL-U and run the EXE file without the macro. it works perfect.

I have come to the conclusion at this point that what happens is the exe file starts running and the macro is still recording until you are finished. So the macro is running and the exe is running and cancelling each other out some how. I think what we need is a macro or a journal that will allow us to run the exe file, but will stop running as soon as the exe file has started.

I tried to record a Journal but cannot find in the journal where it opens or runs the exe file. Instead it looks as if it records everything the exe file does instead.

Is there a simple macro or Journal that just runs an exe file, that I could just go into it and replace the path and file with the one I want it to run here?
 
Replies continue below

Recommended for you

We tend to use MEN files for this, using the following syntax :

BUTTON My_Button
LABEL Executing external program for...
ACTIONS "Start MyPath\MyExecutable.exe"

NX 9.0.3.4
NX 10 (Testing)
Windows 7 64 (Windows 8.1 Tablet)
 
You can also use the "Shell" command in a journal
 
Hello Kenja824, try this code:

Code:
Option Strict Off
Imports System
Imports NXOpen

Module Module1

    Sub Main()

        'path to file
        Dim myfile As String = "c:\myfile.txt"

        Try
            System.Diagnostics.Process.Start(myfile)

        Catch ex As Exception
            Msgbox("Specified file: " & myfile & " Cannot be opened")

        End Try

    End Sub

End Module


With best regards
Michael
 
Thanks Niedzwviedz

I tried the code but it doesnt seem to be working. I tried it as it is below, and I tried replacing "myfile" with the file name in the other places as well. I tried it with the .exe and without it in the file name.

As it is below, I get a Framework error. An Unhandled Expression message. If I just go to File - Execute - NX Open, the .exe file works fine.
It may make a difference to know I am in NX9 and using Journal with Visual Basic, Unicode.

I know the company that issued this .exe file to us has a button that works for it at their place. My boss said he is going to see if they can just send us the info to make one that works here. But if you know where I am going wrong, I would still like to know for my own learning if nothing else. I need to find a book on Journal language. lol

------------------------------------------------
Option Strict Off
Imports System
Imports NXOpen

Module Module1

Sub Main()

'path to file
Dim myfile As String = "R:\NX9\Tooling\Hole Check GUI.exe"

Try
System.Diagnostics.Process.Start(myfile)

Catch ex As Exception
Msgbox("Specified file: " & myfile & " Cannot be opened")

End Try

End Sub

End Module




 
Can You upload this "Hole Check GUI.exe" file or it's isn't possible? I tried this journal with some ".exe" file and it's working in NX 8.5. Maybe there is a problem with connection to network disk? Please also upload picture with error.


With best regards
Michael
 
I'd guess the spaces in the .exe name are throwing things off. It is probably looking for the file: "R:\NX9\Tooling\Hole"
and it thinks "Check" and "GUI.exe" are arguments.

Try placing triple quotes around the path name.

Code:
Dim myfile As String = """R:\NX9\Tooling\Hole Check GUI.exe"""

www.nxjournaling.com
 
Well I was going to post about needing to update our Microsoft Framework from 4 to 4.5, but unfortunately that wasnt the answer. Right now we are thinking there is just something in the way they created this .exe file.

I asked my boss about posting the file but he said no to that as well as the actual error due to privacy issues. He said the company that made it has a button that works for them, so he is just going to get them to set us up with the button to run the file.

Another strange thing that I came across is that NX gives us the option in Customization to make our own command and pick an image for it and such. I did this and it seems to work fine. When we did it on my leaders NX the same way, it didnt work for him. So there is a chance something weird is just happening with our installation or with licensing bundles. Either way, I am ordered to let it go now, so I will likely never know what it was for sure.
 
May I suggest You some options:
1) Change name of file, for example remove spaces
2) Put this file on your local drive for example c:3) Try run journal with different .exe file for example some kind of installer or something.
4) Run this Journal on different NX (8.5?) or on different machine
If one of those methods will work, then We can find the answer. Please upload picture with error message.

With best regards
Michael
 
Sorry. I dont get too much time to look into things lately. I have yet to get this Journal to work.

I am sorry but I cannot post a lot of info due to privacy requirements with another company and my boss saying "no". lol

I have tried the triple quotes. It made no difference.

If I use a Journal, it always gives me a "Microsoft .NET Framework" error. Saying.... Unhandled exception has occurred in your application. If you click Continue, the application eill ignore this error and attempt to continue. If you click Quit, the application will close immediately. ..... however, if I click continue, it goes to the next step in the .exe file where I need to pick from several choices on what to look at, but the window that comes up is empty. But if I run the .exe file manually, I will receiver several choices.

I tried using a macro for this. But when I execute the .exe file the macro is still recording. When it is played back, the .exe file will run correctly, but when it gets to the user options again, there is still a wheel rolling like it is thinking (which there shouldnt be) and if I click on one of the options, the wheel goes away, but the options dont do anything.

If I use the "New Command" option in NX9 Customization, and choose the NX Open and connect to the .exe file, it runs perfect. The problem is, we would have to manually make that button for each computer that uses the program. I cant find a way to transfer that button to another computer unless possibly with Roles, but I didnt look at that as we dont want to mess up each person's role.

I do wish I could just load the error info, but my hands are tied. Sorry.
 
Since I still have not found the answer to this, and it turns out the buttons the company that made this program for us are nothing more than User Commands they created, I decided to start digging into the error again. I figured maybe if I paste a section of the error details that looks important, and "X" out the company name ( I hate privacy issues) that maybe someone can give me an idea what the problem is.

To my understanding, this is actually not an error from NX, but is a "Microsoft.NET Framework" error.

The main error states.....
Unhandled exception has occurred in your application. If you click "continue", the application will ignore this error and attempt to continue. (It sometimes kicks me out of NX). If you click "Quit" this application will close immediately.
The type initializer for "XXXXXXX.Main" threw an exception.

Clicking on details there was a bunch of info, but this section seemed the important part to me.....
************** Exception Text **************
System.TypeInitializationException: The type initializer for XXXXXXX.Main' threw an exception. ---> System.IO.FileNotFoundException: Could not load file or assembly 'NXOpen, Version=9.0.0.19, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
at XXXXXXXXX.Main..cctor()
--- End of inner exception stack trace ---


Does this help at all?


 
Upon further investigation, I learned that any error with.... System.IO.FileNotFoundException: Could not load file or assembly 'NXOpen, .... means that it could not find that file.

I do not know this language much but would I be right to assume that it is looking for the NX Open command and cant find it? Could the problem be that the code was written in NX8 or something, and since I am using NX9 and the NX Open command is in FILE / EXECUTE / NX Open, that the journal offered me is not looking for NX Open in the right place?

In the one in a million chance I am right, can someone tell me what to change in my journal code? (Which is what I posted around 8 posts above)
 
I'd guess the .exe file is not finding the NX dll files that it needs to operate correctly. Check the value of the UGII_SITE_DIR environment variable and navigate to the folder it points to with windows explorer. Inside of this folder, there should be two subfolders named "Application" and "Startup". Copy (or move) the .exe file into the Application folder. This should start your .exe in the NX environment and it should be able to find the NXOpen.dll and other .dll files it needs.

www.nxjournaling.com
 
My question is, why would it be that the .exe file works perfect, if I manually go to File/Execute/NX open .... or if I create a New User Command and select the NX Opn drop down and attach it to the same .exe file, but it only will not run right when using a macro or Journal to do the same thing?

The fact that if I manually run the .exe file and it works perfect, doesnt that say it does find all the needed files and the problem is somewhere in the Journal not working right?
 
Hello @kenja824,

Did You tried one of my suggestion, which I have posted on 5 January? If not, try it and write the results, especially my second proposition. It's look like You don't have access to file.
Do You have latest .net framework installed correctly? Try install .NET Framework 4.5.2.
Do You have admin rights? If yes, try "Disable UAC". see this link -> Do You have installed "Microsoft visual studio C++"

With best regards
Michael
 
If moving the .exe file to the Application folder doesn't work, try copying the {NX install dir}\UGII\managed\NXOpen*.dll files to the same folder as the .exe file.

www.nxjournaling.com
 
1) Change name of file, for example remove spaces ------ This did not make any difference. I also tried cowski's idea with triple quotes and it made no difference.
2) Put this file on your local drive for example c:\ --------- This made no difference either
3) Try run journal with different .exe file for example some kind of installer or something. --------- I sent my journal to some old .exe files we do not use anymore. These seemed to try to run, but errored out for what looks to be reasons outside of the journal. Mainly as if we just dont have them set up to work anymore. This makes me believe it is the .exe file at fault. I will have a boss look for an .exe file we still use to test it farther.
4) Run this Journal on different NX (8.5?) or on different machine ---------- I cannot test this as we have zipped away all old NX8 files I am aware of. I will have to wait until a boss can hook me up.
If one of those methods will work, then We can find the answer. Please upload picture with error message.


So I will look further but I have to wait until bosses are in again (and have time). lol But I am not thinking there is something in how the .exe file is written that keeps it from communicating with the journal code or something strange like that.
Thanks. I will keep looking into this when I can.


 
Try running the code that niedzviedz posted on 4 Jan 15 11:13, change the myfile reference to point to an existing text file on your computer. When you run this code, it should open the file in notepad (or whatever your default text editor is). If this journal runs without error, then we know that the journal code runs correctly and an external program can be started. This would point to a problem with the particular exe file you are attempting to run or the method in which it is started.

www.nxjournaling.com
 
Ok

Cowski, it does open the text file.
Also
I copied the .dll files from that folder over with interesting results. It seems to start the .exe file with those coppied over, but the file then gives me a message saying I must first open a tool before continuing. But I already have a tool open and the exe file works if I run it manually. Does that make sense that it would now act like it wants to work, but doesnt recognize my NX has a tool open already?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor