[gme-users] Component: saving project, modifying, reopening
Peter Volgyesi
peter.volgyesi at vanderbilt.edu
Mon Jun 14 10:44:40 CDT 2004
It is (almost) possible what you are asking for.
One limitation: you cannot "replace" the current mga project with another
one in your interpreter. I suggest you to export and re-import the model
database. The benefits are:
- it is working
- your external program can work on a standard xml file
drawbacks:
- the import function is additive: you might have to delete the "old"
objects in your interpreter "manually".
Here are the steps (creating a plug-in is preferable):
1., create a new BON2 plug-in (CreateNewComponent.exe)
2., please, modify the ComponentLib.idl file, and include an additional
interface module:
...
#include PATH(/Interfaces/gme.idl)
#include PATH(/Interfaces/parser.idl) <- insert this line
3., unfortunately, you will have to modify the parser.idl file (in the
interfaces folder), because of a small bug in it (starting from the next GME
release, this modification will be there):
#ifndef MGAIDL_IMPORTED <------
import "Mga.idl";
#endif <------ Insert these two preproc. lines
4., here is the export/re-import code that you might copy into your
component (eg.: Component::invokeEx(...)):
CComPtr<IMgaProject> mgaProject = project->getProjectI();
ASSERT(mgaProject);
CComPtr<IMgaTerritory> terr;
COMTHROW( mgaProject->get_ActiveTerritory(&terr));
ASSERT(terr);
try {
COMTHROW( mgaProject->CommitTransaction() );
CComPtr<IMgaDumper> dumper;
COMTHROW(dumper.CoCreateInstance(OLESTR("Mga.MgaDumper")));
ASSERT(dumper);
CComBSTR tmpFileName("C:\\Temp\\project.xme");
COMTHROW(dumper->DumpProject(mgaProject, tmpFileName));
// Run your external tool on tmpFileName
// ...
CComPtr<IMgaParser> parser;
COMTHROW(parser.CoCreateInstance(OLESTR("Mga.MgaParser")));
ASSERT(parser);
COMTHROW(parser->ParseProject(mgaProject, tmpFileName));
COMTHROW( mgaProject->BeginTransaction(terr) );
}
catch (BON::Exception&) {
AfxMessageBox("Something went wrong...");
}
--
peter
> -----Original Message-----
> From: gme-users-bounces at list.isis.vanderbilt.edu
> [mailto:gme-users-bounces at list.isis.vanderbilt.edu] On Behalf
> Of Gabriele Trombetti
> Sent: Friday, June 11, 2004 9:57 PM
> To: gme-users
> Subject: [gme-users] Component: saving project, modifying, reopening
>
> Hi all,
> I need to create a plugin or an addon or interpreter, or whatever....
> preferably having an icon in the topright corner of GME.
>
> Such component would need to work with models of only one
> paradigm (simplyfying hypotesis... maybe).
>
> When the user runs it, I need to:
> somehow get the mga filename which is currently open in GME
> then save the current project (into that mga file) than
> perform some modification onto that mga project file
> (modifications made by launching an external exe onto it)
> then opening that file again into the same instance of GME
> (having the effect of a refresh from disk)
>
>
> Is it possible to do this, or something near to this?
>
> Would I need an add-on, a plugin or an interpreter?
> Which COM interfaces should I use?
>
> Thanks in advance
> Gabriele
> _______________________________________________
> gme-users mailing list
> gme-users at list.isis.vanderbilt.edu
> http://list.isis.vanderbilt.edu/mailman/listinfo/gme-users
More information about the gme-users
mailing list