Home Forums General XMetaL Discussion XFT forms with conditions Reply To: XFT forms with conditions

Derek Read

Reply to: XFT forms with conditions

Linking two forms to the same element in the CTM file is not recommended as there really is no way for the product to know which one to display. You will really need something unique in order to decide which one to show the user.

The following is one option:

1. Create two macros each containing script similar to the following:
[code]// XMetaL Script Language JSCRIPT:
if (Selection.ContainerName == “XYZ”) {
var dlg=Application.CreateFormDlg(Application.Path + “\Forms\form1.xft”);
dlg.DoModal();
dlg=null;
}
else {
  //optional message:
  Application.Alert(“You must be inside an XYZ element to run this macro.”);
}[/code]

[code]// XMetaL Script Language JSCRIPT:
if (Selection.ContainerName == “XYZ”) {
  var dlg=Application.CreateFormDlg(Application.Path + “\Forms\form2.xft”);
  dlg.DoModal();
  dlg=null;
}
else {
  //optional message:
  Application.Alert(“You must be inside an XYZ element to run this macro.”);
}[/code]

2. Place your forms (form1.xft and form2.xft) inside the Forms folder and have your user run each of the macros depending on what they wish to do. You can give the macros appropriate names or associate them with nice buttons and put them on a toolbar or maybe add them to a menu, create a new menu, or add new items to the context menu. If you want to store these forms elsewhere adjust the code so the CreateFormDlg API can find them.

If there is something unique about the element, you could have one script that decides which form to launch based on some basic logic as in this example:
[code]// XMetaL Script Language JSCRIPT:
if (Selection.ContainerName == “XYZ”) {
  if (Selection.ContainerAttribute(“A”) == “1”) {
    var dlg=Application.CreateFormDlg(Application.Path + “\Forms\form1.xft”);
  }
  else {
    //attribute A is anything other than “1” or not set at all
    var dlg=Application.CreateFormDlg(Application.Path + “\Forms\form2.xft”);
  }
  dlg.DoModal();
  dlg=null;
}
else {
  //optional message:
  Application.Alert(“You must be inside an XYZ element to run this macro.”);
}[/code]

I think this is more of a question of deciding how you wish the application to decide which form to launch (and less of a programming issue). I think once you figure that out we can probably help (rather than taking guesses). Maybe step back and ask yourself how you (as a human) would decide which one to launch.

It may also help to see some real XML in this case as well rather than dummy element, attribute names and values.

Reply

Products
Downloads
Support