Hello,
Is there some information or samples available on how you can access the domain model programmatically using code
For example I got a simple domain model with classes and these classes have an embedding relation to operations. Then I want to do some things on the double click on a shape like:
public
partial class ClassShape{
public override void OnFieldDoubleClick(ShapeField field, DiagramPointEventArgs e){
//Read some properties of the clicked Class Element //Collect the embedding Operation elements of the clicked class element //Add some new classes to the diagram //Add some new Operations to the clicked class}
}
I tried some things out using the this.Store property, but it isn't really clear to me how this works. Hope someone can help me out.
Thanks,
Gerben [Avanade]
Please note: the OnFieldDoubleClick method no longer exists - use "OnDoubleClick(...)" instead. See the following post for details: http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=2277778&SiteID=1&mode=1

Accessing the domain model using code
Roman Belousov
Thanks for your reply Gareth, this certainly gets me underway.
One remaining question:
When I add an element using code it appears in my domain explorer, but not on my diagram. So how do I visualize an element in my designer after it is added it using code
Thanks,
Gerben [Avanade]
Arnaud Prost
And is it possible to access from custom code to an in memory model or it's necessary xml deserialization I mean like ModelRoot modelRoot=[modelName].ModelRoot;
Paulson
Once the file has been loaded into a store, you can use Store.ElementDirectory.GetElements / FindElements to find any elements of any type in the store. If your custom code is running inside your target designer, then the model will have already been loaded in to the store. If your custom code is not running inside your target designer, you can use the generated [MyLanguage]SerializationHelper to load the model file into a Store.
Duncan
Dooker
Yes you're totally right Grayson. I didn't linked the element the right way to my model. It's working now after I fixed that.
Thanks for your help!
Gerben. [Avanade]
DianaED
If there's a shape defined in your .dsldd file corresponding to the element you created, and you've linked your new element into the existing model, you should get a shape created automatically. If you can post the code you're using to create the element, perhaps I can tell you why it's not working.
Thanks,
Grayson
madhan
Hi Gerben,
If you access the ModelElement property on your Shape you'll get the underlying element representing your Class (the thing the shape was mapped to in your .dd file)
From there you should be able to navigate around your class model by saying things like
theClass.Operations.Count or whatever it is that you want to do.
If you want to make changes to the model you'll need to start a transaction.
The code for that goes something like:
using (Transaction t = themodelelement.Store.TransactionManager.BeginTransaction("Make Changes"))
{
// Do your thing
t.Commit();
}
Hope this gets you underway.