Sparx Systems Forum
Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: rvaldes on January 07, 2011, 09:00:43 pm
-
Hi, this is the problem:
When line parent.Elements.AddNew("<Element Name>", type); executes, throw a COMException with "Internal Error" message.
Any ideas??
[size=8] public EA.IDualElement AddChildElement(EA.IDualElement parent, EA.IDualElement child, string type, string stereotype, out bool success)
{
if (parent == null)
{
throw new ArgumentNullException("parent", "METESPA_Addin.Model.Dao:AddChildElement(EA.IDualElement parent, EA.IDualElement child, string type, string stereotype, out bool success)");
}
object element = null;
success = true;
try
{
if (child == null)
{
[highlight] element = parent.Elements.AddNew("<Element Name>", type);[/highlight]
}
else
{
element = parent.Elements.AddNew(child.Name, type);
}
success &= ((EA.IDualElement)element).Update();
parent.Elements.Refresh();
((EA.IDualElement)element).Stereotype = stereotype;
success &= ((EA.IDualElement)element).Update();
((EA.IDualElement)element).TreePos = parent.Elements.Count;
success &= ((EA.IDualElement)element).Update();
if (success)
{
OnAddedElement(((EA.IDualElement)element).ElementID, ((EA.IDualElement)element).PackageID, ((EA.IDualElement)element).ParentID, ((EA.IDualElement)element).Type, ((EA.IDualElement)element).Stereotype);
}
}
catch
{
throw new DaoException("METESPA_Addin.Model.Dao:AddChildElement(EA.IDualElement parent, EA.IDualElement child, string type, string stereotype, out bool success)");
}
return (EA.IDualElement)element;
}[/size]
-
Some questions:
- Why do you use the IDualElement things? I've never used those interfaces, but always worked with EA.Element
- What is the value of the type parameter
- Do you use some kind of locking mechanism which could make the parent readonly
- Has the parent already been saved to the model (using Update())
- Do you have the same issue when you try with a name that doesn't contain "<" or ">"
- Does Repository.getLastError give you any info?
Geert