How to locate model file based on the ModelElement?

Topics: Service Factory Modeling Edition Forum
Mar 16, 2009 at 10:07 AM
Edited Mar 16, 2009 at 10:51 AM
Hi guys,

Well the headline says it all.
If we are in a .tt file for example, and we have the CurrentElement item how do we find the physical file(filesystem file) where it is defined?

Cant seem to find a path anywhere, so it would be great if somebody could point me in the right direction.


Mar 17, 2009 at 1:16 AM
It's not easy to get access to the model file from an element becasue you need to get an instance of the DocData class that holds that information.
However, if your model is open in VS IDE, you can get access to it and get the file path.
To do this, you can open the WSSF source sln and look for the "DesignerHelper" class. With this code you can get the model file path assuming that your model window is opened and selected.


ModelingDocView docView = DesignerHelper.GetModelingDocView(modelElement.Store);
string modelFile = docView.DocData.FileName;


Mar 17, 2009 at 7:02 AM
Ahh ofcourse, Thanks!

The model is open but i wasnt aware that I could pass the Store as a parameter to that method, Thanks alot!