General XMetaL Discussion
pooh2583 September 26, 2013 at 7:04 am
Common MacroSeptember 26, 2013 at 7:04 amParticipants 8Replies 9Last Activity 9 years, 4 months ago
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?
RegardsDerek Read September 26, 2013 at 8:26 pm
Reply to: Common MacroSeptember 26, 2013 at 8:26 pm
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?pooh2583 October 8, 2013 at 11:17 am
Reply to: Common MacroOctober 8, 2013 at 11:17 am
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
RegardsDerek Read October 8, 2013 at 11:08 pm
Reply to: Common MacroOctober 8, 2013 at 11:08 pm
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?pooh2583 October 9, 2013 at 10:30 am
Reply to: Common MacroOctober 9, 2013 at 10:30 am
Thnk you for your suggestion an help.
This exactly what I need.
RegardsDerek Read October 9, 2013 at 5:39 pm
Reply to: Common MacroOctober 9, 2013 at 5:39 pm
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);Derek Read October 9, 2013 at 5:47 pm
Reply to: Common MacroOctober 9, 2013 at 5:47 pm
Other scripting languages have something similar, including VBScript, which calls its method Eval().pooh2583 October 10, 2013 at 6:45 am
Reply to: Common MacroOctober 10, 2013 at 6:45 am
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”);
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
please suggest the solution.
Regards,Derek Read October 11, 2013 at 8:03 pm
Reply to: Common MacroOctober 11, 2013 at 8:03 pm
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.Derek Read October 11, 2013 at 8:29 pm
Reply to: Common MacroOctober 11, 2013 at 8:29 pm
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.
- You must be logged in to reply to this topic.