General XMetaL Discussion

  • pooh2583

    Common Macro

    Participants 8
    Replies 9
    Last Activity 9 years ago

    HI,

    I am developing some set of Macrocs which will be used for two different Xmetal projects(Functionality of the Macros would be similar), is there any way I can put those Macros in some Common Folder and use it in both the project to avoid redundency?

    Thanks'
    Regards

    Reply

    Derek Read

    Reply to: Common Macro

    It sounds like you possibly want an Application-Level macro (rather than multiple Document-Level macros).
    If that is the case then you can develop an Application-Level macro (XMetaL Developer has a project template for this). You would then then place it in the Startup subfolder of the XMetaL Author installation to have it load. Note that Application-Level macros are not applicable to XMAX.

    Is that what you are looking for?

    Reply

    pooh2583

    Reply to: Common Macro

    Hi Derek,

    I am not using application level, Macro I have two different Xmetal projects which have some common functionality Macros for some elements in the Xml, so to avoid redundency I need to use these Macro (from a common folder for both the projects) , later i will have to keep the same project into SVN .

    Please help me with this

    Regards

    Reply

    Derek Read

    Reply to: Common Macro

    You can add an existing script (JS or VB or whatever) to a project as a reference and then leave it where it is.
    When your MCR is built the script will be pulled in.

    Is that what you need?

    Reply

    pooh2583

    Reply to: Common Macro

    Hi Derek,

    Thnk you for your suggestion an help.
    This exactly what I need.

    Regards

    Reply

    Derek Read

    Reply to: Common Macro

    Just in case it helps, another thing you can do is to put your common code in a third file (the file extension doesn't matter in this case but you might use .js) and use JScript's eval statement together with Application.FileToString() to pull JScript code in at runtime in the two files that will be compiled into the MCR.

    The two JScript files that will compile into your separate MCR files would then contain code similar to this:

    var strMyJScript = Application.FileToString("path to file.js");
    eval(strMyJScript);

    Reply

    Derek Read

    Reply to: Common Macro

    Other scripting languages have something similar, including VBScript, which calls its method Eval().

    Reply

    pooh2583

    Reply to: Common Macro

    Hello Derek,

    As per the requirement i will be referring to the external .js file from common folder, and when i use it by Macro->add->Existing File-> and i select the file from the ommon folder but when i go by this method it copies that file itself in the project and this doesnt solve my problem of avoiding redundency.

    Also wnen I try to implemet  your above mentioned method by providing external path of the file, i will have to create a new files in the project itself which will be having following code.

    var strMyJScript = Application.FileToString(“path to file.js”);
    eval(strMyJScript);

    so this code would be there for the no. of file I have to call from external common folder for each project.

    Ex. to call file1  callfile1
    file2 callfile2

    please suggest the solution.

    Regards,

    Reply

    Derek Read

    Reply to: Common Macro

    Sorry, I thought the dialog for “Add Existing Item” allowed you to reference an existing file and leave it in place. That feature has either been removed or I remembered incorrectly. If you import files from an existing project I believe that option is actually available.

    Let's work on the second option though, since that is surefire. Yes, you will need to have code that imports the file. There is no way around that. If you set it up correctly with some planning then that code should never need to change. Each project needs its own MCR file in order to run scripts so you already have to have some script in each document-level project. There is no way around that. Just add your separate .JS file to one project or don't add it to any project. When you deploy your MCR files to an XMetaL Author installation copy the .JS file at the same time. You could also automate that if you want to using the “Post Build” functionality in the Visual Studio “Property Pages” for your project.

    Reply

    Derek Read

    Reply to: Common Macro

    OK, my memory is bad. We only had the option to leave a copy of the DTD/Schema in its present location when you create a new project. It doesn't apply to other file types. So, if you need to do what you are asking I think the easiest solution is to use eval() method.

    Remember that you can also create application-level MCR files. I don't know what you are building so can't tell if that is applicable, but it is an option.

    There might be other possibilities, but the only ones I can think of would probably involve creating your own custom build process, and I can't think of an easy way to do that, and I don't think it would be worth the trouble to try to figure that out.

    Reply

  • You must be logged in to reply to this topic.

Lost Your Password?

Products
Downloads
Support