Submitted by ankum16 on Wed, 05/07/2014 - 21:17
Forums:
I need to run a macro inside my C# code. Any idea how to run a macro programmatically?
Regards,
Ankita
I need to run a macro inside my C# code. Any idea how to run a macro programmatically?
Regards,
Ankita
re: run macro
I don't think it is possible to run a macro from a journal. I remember reading about it in the programmer's guide, but can't seem to find the reference now...
Thanks for reply
Thanks. It is great and very helpful site.
~ Ankita
Life is beautiful. :)
It is possible but not very good
Hi,
ther is a possibility to run a Macro during a journal:
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
This is a sample in VB. It runs a Macro - but not synchron to the journal. And unfortunately it is NX version dependent. This e.g. runs in NX8.5 - others not tested. The alias could be different for every NX version...
regards,
NXJ
VB Run Macro Within Journal
Any ideas as how to accomplish this in VB?
DHuskic
Nx 9 VB
Nevermind....
Nevermind, missed the comment below the above post. Please disregard this.
DHuskic
Nx 9 VB
Getting error while trying the above code to execute Macro in c#
Hi, In one of my c# custom application, I'm trying to execute a macro. I have used below code to import libugui.dll and tried to call the macro in the below mentioned fashion. I'm getting the error saying "Unable to find an entry point named '?MACRO_playback_from_usertool@@YAXPEBD@Z'in DLL 'libugui.dll'. I also tried to give the full path of the dll which is in the UGII root directory. I checked the libugui.dll for the entry point in Dependency Walker, the entry point is correct. Please let me know if there is any way to solve the issue.
Code:
[DllImport("libugui.dll", EntryPoint = "?MACRO_playback_from_usertool@@YAXPEBD@Z")]
static extern void MACRO_playback_from_usertool64(string lpName);
public static void RunMacro(string lpname) {
MACRO_playback_from_usertool64(lpname);
}
re: run macro
The code used to run a macro is not supported by Siemens; in fact, they discourage its use. This usually means that the code has one or more bugs that they do not plan on fixing. If possible, I suggest writing NXOpen code to replace the macro functionality.
C# sample
[DllImport("libugui.dll", EntryPoint = "?MACRO_playback_from_usertool@@YAXPBD@Z")]
static extern void MACRO_playback_from_usertool32(string lpName);
[DllImport("libugui.dll", EntryPoint = "?MACRO_playback_from_usertool@@YAXPEBD@Z")]
static extern void MACRO_playback_from_usertool64(string lpName);
///
/// Run NX Macro files
///
/// Macro File Name
public static void RunMacro(string lpname) {
if (IntPtr.Size == 8) {
MACRO_playback_from_usertool64(lpname);
} else {
MACRO_playback_from_usertool32(lpname);
}
}
Note
It is possible to run only 1 macro.
It always runs at the end of the program, regardless of the position in the code.
this command seems not active
this command seems not active with python?
"MACRO_playback_from_usertool("C:\temp\test.macro")"
Can you help me, please?
End Module
NX OPEN
re: macro playback
It is not a fully supported tool in NXOpen. I'd suggest investigating other ways to accomplish what you need.
Thanks!
Thanks!
NX OPEN