run a macro inside C# code

I need to run a macro inside my C# code. Any idea how to run a macro programmatically?

Regards,
Ankita

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. It is great and very helpful site.

~ Ankita

Life is beautiful. :)

Hi,

ther is a possibility to run a Macro during a journal:

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

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

Any ideas as how to accomplish this in VB?

DHuskic
Nx 9 VB

Nevermind, missed the comment below the above post. Please disregard this.

DHuskic
Nx 9 VB

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);
}

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.

[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);
}
}

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 with python?

"MACRO_playback_from_usertool("C:\temp\test.macro")"
Can you help me, please?

End Module

NX OPEN

It is not a fully supported tool in NXOpen. I'd suggest investigating other ways to accomplish what you need.

Thanks!

NX OPEN