×
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

Journal or Macro to run .EXE files

Journal or Macro to run .EXE files

Journal or Macro to run .EXE files

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

RE: Journal or Macro to run .EXE files

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)

RE: Journal or Macro to run .EXE files

You can also use the "Shell" command in a journal

RE: Journal or Macro to run .EXE files

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

RE: Journal or Macro to run .EXE files

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




RE: Journal or Macro to run .EXE files

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

RE: Journal or Macro to run .EXE files

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

RE: Journal or Macro to run .EXE files

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

RE: Journal or Macro to run .EXE files

Did you try my trick with the triple quotes?

www.nxjournaling.com

RE: Journal or Macro to run .EXE files

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

RE: Journal or Macro to run .EXE files

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

RE: Journal or Macro to run .EXE files

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


RE: Journal or Macro to run .EXE files

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

RE: Journal or Macro to run .EXE files

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

RE: Journal or Macro to run .EXE files

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

RE: Journal or Macro to run .EXE files

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 -> http://www.howtogeek.com/howto/windows-vista/disab...
Do You have installed "Microsoft visual studio C++"

With best regards
Michael

RE: Journal or Macro to run .EXE files

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

RE: Journal or Macro to run .EXE files

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


RE: Journal or Macro to run .EXE files

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

RE: Journal or Macro to run .EXE files

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

RE: Journal or Macro to run .EXE files

With .net, you usually compile to .exe for "batch" type processing (no NX session running) and you compile to .dll for programs that will be run in interactive NX (this very general rule may not hold for non-.net languages). I suspect the exe file is launching its own, separate NX process to work with and doesn't know about the interactive session you have running. The "execute NXOpen program" command somehow tells the exe to use the existing NX session; the journal to launch the exe does not.

www.nxjournaling.com

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