‘Hello there. I have specific problem on trying to open and modify Preactor specific file.I am new to this syntax and manipulation of Preactor UI with external scripting code. I have some knowledge in C#. I understood that Preactor.prmdf file can carry configuration of Preactor, so that functions/methods(from C#) could be called from dlls , scripts can be executed etc. I have the original file and tried to learn what and how has been executed inside. It seems to be tough for me at this point. I would greatly appreciate If someone familiar with this scripting language (Preactor with integration with C#) to help me understand what are the best possible options in modifying such files. In other words I simply want to be able to integrate Class Library generated from C# code into Preactor.prmdf file. The simplest result I want to achieve for now is the following: Getting some method executed from the produced dll(from C# project) to Preactor. E.g -> After clicking button in Preactor to execute C# code where writing into a file some text or just printing some text or something else, which is a sign that the code has been executed successfully inside the DLL and has been integrated to Preactor.
I have written small C# code into a Class Library , where I have loaded the needed Libraries from Preactor , needed to execute the following ->
using Preactor;
using Preactor.Interop.PreactorObject;
using System;
using System.IO;
using System.Runtime.InteropServices;
namespace FileWriterLibrary
{
[ComVisible(true)]
[Guid("9C30CF27-C793-4469-BBB3-B02765CD06E8")]
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface IFileWriterActions
{
int WriteToFile(ref PreactorObj preactorComObject);
}
[ComVisible(true)]
[Guid("F213BD5A-B81D-48DC-8170-A773E9D0A245")]
[ClassInterface(ClassInterfaceType.None)]
public class FileWriterActions : IFileWriterActions
{
public int WriteToFile(ref PreactorObj preactorComObject)
{
// Create an instance of the Preactor object
IPreactor preactor = PreactorFactory.CreatePreactorObject(preactorComObject);
string logFilePath = @"C:Cfg_12_Test_10.06.24log.txt";
string directory = @"C:Cfg_12_Test_10.06.24";
string fileName = "file_to_write.txt";
string filePath = Path.Combine(directory, fileName);
try
{
File.AppendAllText(logFilePath, "WriteToFile method called.n");
if (!Directory.Exists(directory))
{
Directory.CreateDirectory(directory);
}
using (StreamWriter writer = File.AppendText(filePath))
{
writer.WriteLine("Written!");
}
File.AppendAllText(logFilePath, "WriteToFile method completed successfully.n");
return 0; // Success
}
catch (Exception ex)
{
// Log any exceptions that occur
File.AppendAllText(logFilePath, $"Error: {ex.Message}n");
throw new Exception("Error writing to file", ex);
}
}
}
}
After successfully adding the dependencies , and also compiling with F6 in VS , the dll was created. Now I read that the dll has to be registered on my PC, and on the target Pc where Preactor is contained. So i did in command prompt as Admin -> C:WindowsMicrosoft.NETFramework64v4.0.30319regasm.exe /codebase /tlb FileWriterLibrary.dll ( this is the dll coming from my project after building).
The same I did on the target PC. It worked, gave me :
Types registered successfully Assembly exported to ‘C:xxxxxxxxxsourcereposFileWriterLibraryFileWriterLibrarybinDebugFileWriterLibrary.tlb’, and the type library was registered successfully.
I have put the dll inside the Preactor folder where are the rest of the files needed to be executed.
Here is part of Preactor.prmdf :
[SHELL]
#define PARSE_STRICT
;
;************************************************************************
;
; Preactor AS Menu Definition
;
;************************************************************************
;
;
#include Language{COUNTRY}{COUNTRY}_popup_prmdf.inc #OPTIONAL
;
PROGRAMS
;
; Include Preactor Features
;
#include {PREACTOR PATH}Includepr_prmdf.inc #VERSION 1
;
;
#include MaterialControl_prmdf.inc
;
{CONDITIONAL},
{#FIND RELATED DB VALUE("Menu Button Mapping" "Number" "1" "Enabled")} == 1,{NEXT},DATATRANSFER1=1:
ELSE,{NEXT},DATATRANSFER1=0;
;
{CONDITIONAL},
{#FIND RELATED DB VALUE("Menu Button Mapping" "Number" "2" "Enabled")} == 1,{NEXT},DATATRANSFER2=1:
ELSE,{NEXT},DATATRANSFER2=0;
;
{CONDITIONAL},
{#FIND RELATED DB VALUE("Menu Button Mapping" "Number" "3" "Enabled")} == 1,{NEXT},DATATRANSFER3=1:
ELSE,{NEXT},DATATRANSFER3=0;
;
{CONDITIONAL},
{#FIND RELATED DB VALUE("Menu Button Mapping" "Number" "4" "Enabled")} == 1,{NEXT},DATATRANSFER4=1:
ELSE,{NEXT},DATATRANSFER4=0;
;
{CONDITIONAL},
{#FIND RELATED DB VALUE("Menu Button Mapping" "Number" "5" "Enabled")} == 1,{NEXT},DATATRANSFER5=1:
ELSE,{NEXT},DATATRANSFER5=0;
;
{CONDITIONAL},
{#FIND RELATED DB VALUE("Menu Button Mapping" "Number" "6" "Enabled")} == 1,{NEXT},DATATRANSFER6=1:
ELSE,{NEXT},DATATRANSFER6=0;
;
{CONDITIONAL},
{#FIND RELATED DB VALUE("Menu Button Mapping" "Number" "7" "Enabled")} == 1,{NEXT},DATATRANSFER7=1:
ELSE,{NEXT},DATATRANSFER7=0;
;
{CONDITIONAL},
{#FIND RELATED DB VALUE("Menu Button Mapping" "Number" "8" "Enabled")} == 1,{NEXT},DATATRANSFER8=1:
ELSE,{NEXT},DATATRANSFER8=0;
;
{CONDITIONAL},
{#FIND RELATED DB VALUE("Menu Button Mapping" "Number" "9" "Enabled")} == 1,{NEXT},DATATRANSFER9=1:
ELSE,{NEXT},DATATRANSFER9=0;
;
;
; --------------------------------------------------------------------------
; Main Menu
; --------------------------------------------------------------------------
;
#label image Data_Transfer_Script_1:{EMBEDDED IMAGE PATH}/Import.Export.48.png
#label image Data_Transfer_Script_2:{EMBEDDED IMAGE PATH}/Import.Export.48.png
#label image Data_Transfer_Script_3:{EMBEDDED IMAGE PATH}/Import.Export.48.png
;
MENU_Main : {DIALOG},
Select Scheduling Option from Menu,
Main Menu:
#ifndef VIEWER
PUSHBUTTON | HELPPOPUPID (50100),Data Transfer,MENU_ImpExp:
#endif
PUSHBUTTON | HELPPOPUPID (50030),Generate Schedule,SEQ_Main:
PUSHBUTTON | HELPPOPUPID (60005),File_Writer,FileWriter_Script:
#ifndef VIEWER
PUSHBUTTON,{FIND RELATED DB VALUE("Menu Button Mapping" "Number" "1" "Button Text")},DATATRANSFER1 = 1,Data_Transfer_Script_1:
PUSHBUTTON,{FIND RELATED DB VALUE("Menu Button Mapping" "Number" "2" "Button Text")},DATATRANSFER2 = 1,Data_Transfer_Script_2:
PUSHBUTTON,{FIND RELATED DB VALUE("Menu Button Mapping" "Number" "3" "Button Text")},DATATRANSFER3 = 1,Data_Transfer_Script_3:
#endif
PUSHBUTTON | HELPPOPUPID (50070),Data Maintenance,MENU_Maintenance;
;
;
;
It can be seen that I have created a PUSHBUTTON, which is Visible when I open Preactor application
An it can be clicked.
(PUSHBUTTON | HELPPOPUPID (60005),File_Writer,FileWriter_Script:)
It is expected to run the script “FileWriter_Script”
Also inside the document I have add the following script, thinking that I could manage to get the things work as I expect ->
; --------------------------------------------------------------------------
; FileWriter Script
; --------------------------------------------------------------------------
;
FileWriter_Script : FileWriterLibrary.dll,
/RunEventScript WriteToFile,
Write to File Script,
Custom Write to File Script,
Foreground,
ALWAYS:{RETURN};
After all when I start Preactor and click on the button “File_Writer” , it actually finds the dll,
but does not execute the code inside. No log file is created nor file_to_write.txt is created or written inside.
Before that attempt I was trying to integrate similar code inside the dll , but the execution targeted to open On Screen Keyboard, after Button click , which did not also work. Now after the two attempts one and the same error occurs when I click on the button inside Preactor -> Detailed Exception Information:
No application is associated with the specified file for this operation
System.ComponentModel.Win32Exception
No application is associated with the specified file for this operation
Program Location:
at System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo startInfo)
at Preactor.Modules.Shell.Controllers.ExternalApplicationControllerBase`1.a(Process A_0)’
What is the simplest way to integrate specific behavior to a newly created button inside Preactor?
I have used PreactorObject according to this guide -> Guide but even every point has been executed from me, the result is the same. Not proper button behavior.