The first step is to add the ALIpcClient.dll to project references.
using ALIpcClient;
Create an object for the communciation and another one to receive commands from ARCHline.XP
private readonly ALIpcClient.ALIpcClient _ipcClient = new ALIpcClient.ALIpcClient();
private readonly ALIpcClient.IndirectClientFunction _functionForCommands;
At the initializaton phase set up the receive command hook function.
//Register the command handler function
_functionForCommands = CommandHandler;
IntPtr intPtr = Marshal.GetFunctionPointerForDelegate(_functionForCommands);
_ipcClient.RegisterIndirectCommandQueue(intPtr);
You can decide to start a new embedded instance of ARCHline.XP or join into an existing one.
//Start a new ARCHLine.XP instance or join to an existing one?
bool startARCHline = true;
//Create the IPC channel with a unique name
string ipcChannelId = startARCHline ? Guid.NewGuid().ToString() : string.Empty ;
bool archLineStarted = startARCHline ?_ipcClient.StartArchline(
"c:\\Program Files\\ARCHline.XP 2021\\ARCHlineXP2021.bin", //The path to the ARCHLine.XP executable
$" -s -n -ipc {ipcChannelId}", //ARCHLine.XP command parameters: (-s: start new project), (-n: no splash) and (-ipc name: The name of the IPC channel)
25000, //Max waiting time for ARCHLine.XP to start in msec
alHostWnd.Handle, //Host control's handle
Width, Height, //Host window's size
out _archLineAppHwnd) : true; //ARCHline.XP's main window handle
The ipcChannelId is the identifier of the communication channel. Every instance can create its own channel Id. By default it is an empty string. At ARCHline.XP start you can define it with the -ipc command.
//If ARCHLine.XP has started successfully then connect to it
if (archLineStarted && _ipcClient.Connect(ipcChannelId))
{
//Handle successfull connection
;
}
else
{
//Handle errors
;
}
Incoming commands
Incoming commands come from ARCHline.XP, the client can receive at the registered hook function. The command parameter describes the command name, the parameter is it's parameters and the clientCommandResult is the handler object for the command. It can reply to ARCHline.XP about the current command, set the result and close it. Closing it is mandatory.
public void CommandHandler(string command, string param, ALIpcClient.IClientCommandResult clientCommandResut)
{
if (command == "on_selection_changed") //If the list of the selected items changed in ARCHLine.XP
{
//Process the incoming parameters
ALIpcClient.Variables selectedARCHLineItems = new ALIpcClient.Variables.ItemIDArray();
selectedARCHLineItems.FromStream(param);
}
//Always close commands even if the application cannot handle the specified command type
clientCommandResut.SetFinished(true, string.Empty);
}
The command can be synchron or asynchron. The synchron command means the sender is waiting until the command is not closed at the receiver side.
Command name |
Mode |
Function |
on_selection_changed |
asyncron |
The selection is changed in ARCHline.XP |
on_element_added |
asyncron |
New element created |
on_element_modified |
asyncron |
Elemetnt modified |
on_element_removed |
asyncron |
Element deleted |
on_new_project |
asyncron |
A new project started |
on_open_project |
asyncron |
A project loaded |
on_save_project |
asyncron |
A project saved |
on_quit |
asyncron |
The ARCHline.XP exited |
Outgoing commands
The client can send commands to ARCHline.XP. The first parameter is the function code, the second one is the function's parameter, the third one is the mode that can be synchron and asynchron, and the last one is the result object.
It describes:
- if the command is finished or not,
- if the result was successful or not,
- the result parameters.
string msStream = ModStruct.CreateModstructStream(itemIdentifiers);
if(_ipcClient.SendCommand(ALServerCommandType.cSetProperties, msStream, true, out
ServerCommandResult setPropertiesCommandResult)) {
Debug.Assert(setPropertiesCommandResult.IsFinished());
bool ok = setPropertiesCommandResult.GetResult(out string resultValue);
Debug.Assert(ok);
}
These are the avaliable commands:
- Kernel command
It can execute all ARCHline.XP internal commands. The parameter contains the ARCHline.XP command itself. - Get properties
The parameter defines the items and the result value contains the properties in XML format. - Set properties
The parameter is an XML stream or file what contins a list of new properties for all items what reqires to change.
Comments
0 comments
Article is closed for comments.