Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - SiliconRancher

Pages: [1]
1
Of course I'm stuck again :( Now I am able to copy attributes and methods, but while I'm copying parameters of methods:
Code: [Select]
for (short k = 0; k < originalMethod.Parameters.Count; k++)
                        {
                            EA.Parameter origParameter = (EA.Parameter)originalMethod.Parameters.GetAt(k);
                          
                          EA.Parameter copyParameter = (EA.Parameter)copyParameter.Parameters.AddNew(origParameter.Name+"copy", origParameter.Type);
                
                            cV.Update();
                            cM.Update();

                        }


 I receive an error:



Also I tried to find out - without succes - which attribute of the column attribute holds the info about input data type (what type - eg. integer or char - is put inside a column) and how much data can user put inside (eg. char[15]). Also where can I set which column is primary key? And set the column's values as "unique" - or switch it off.

Thank you in advance.


P.S. about adding objects (in my case - link to object) to diagram:
Code: [Select]
                   Repository.GetCurrentDiagram().DiagramLinks.AddNew(elementCopy.Name, elementCopy.Type);
                      Repository.GetCurrentDiagram().Update();
                     Repository.RefreshOpenDiagrams(true);
Of course it doesn't work. What am I missing?

2
Thanks, it did the trick :) Now I have to try with methods to make original table's PK aa FK in the copy and I will have fun with other attributes and such.

One last question - is there a way to make the copy appear in the diagram (the same diagram as the original element)?

3
I added update and refresh, but it's not the case :( And I think it's not about the type of the attribute. I tried e.g. this:

Code: [Select]
foreach (EA.Attribute attribute in selectedElement.Attributes)
                      {
elementCopy.Attributes.AddNew(attribute.Name + "_copy", attribute.Type);                          
                          elementCopy.Attributes.Refresh();
                          elementCopy.Update();  
                      }
I even tried doing it in ulgy way:
Code: [Select]
elementCopy = selectedElement;But it didn't get me anywhere. I also thought that I sholud get "inside" each attribute:

Code: [Select]
short i = 0;
                      foreach (EA.Attribute att in elementCopy.Attributes)
                      {
                          att.Type = selectedElement.Attributes.GetAt(i).Type;
                          att.Style = selectedElement.Attributes.GetAt(i).Style;
                          att.Stereotype = selectedElement.Attributes.GetAt(i).Stereotype;
                          att.Containment = selectedElement.Attributes.GetAt(i).Containment;
                          att.Container = selectedElement.Attributes.GetAt(i).Container;
                          
                          elementCopy.Attributes.Refresh();
                          elementCopy.Update();
                          i++;
                      }
But it also was pointless. I can't copy columns of my original element (table), maybe it's just not possible to do it this way? So maybe there's a different way - taking SQL code from the first element and "inserting" it into the copy? But then - how?

4
Thank you so much for your help, you make so much good work here; also your tutorials were the first (and yet only, except the documentation...) useful thing I found in the Internet aboud writing add-ins to EA.
I'm now able to copy my Element (particulary table, because this add-in is about tables), but still I can't copy attributes.

Now my copy method looks like this:
Code: [Select]
private void copyIt(EA.Repository Repository, EA.Diagram diagram)
        {
            Object o = new Object();
            Repository.GetContextItem(out o).ToString();
          
           if (o is EA.Element)
            {
                EA.Element selectedElement = (EA.Element)o;
                if (selectedElement.Stereotype == "table")
                {
                    
                    EA.Package parentPackage = Repository.GetPackageByID(selectedElement.PackageID);
                      EA.Element elementCopy = parentPackage.Elements.AddNew(selectedElement.Name.ToString() + "_copy",selectedElement.Type.ToString());
                  


                    MessageBox.Show(selectedElement.Properties.Count.ToString() + selectedElement.Methods.Count.ToString());
// element that I try to copy has 2 properties and 3 methods; also 3 attributes - table columns
                    elementCopy.Status = selectedElement.Status;
                    elementCopy.Phase = selectedElement.Phase;
                    elementCopy.Stereotype = selectedElement.Stereotype;
                    elementCopy.MetaType = selectedElement.MetaType;
                    elementCopy.Notes = selectedElement.Notes;
                  
                    

                      foreach (EA.Attribute attribute in selectedElement.Attributes)
                      {
                          
                          
                          elementCopy.Attributes.AddNew(attribute.Name + "_copy", "Attribute");
                          
                      }
                      MessageBox.Show(elementCopy.Attributes.Count.ToString() + " " + selectedElement.Attributes.Count.ToString());
// new element doesn't get any new attributes
                      foreach (EA.Method method in selectedElement.Methods)
                      {
                          elementCopy.Methods.AddNew(method.Name + "_copy", "Method");
                          MessageBox.Show(elementCopy.Methods.Count.ToString());
// the same is true for methods
                      }
                      
                      foreach (EA.CustomProperty customProperty in selectedElement.CustomProperties)
                      {
                          elementCopy.CustomProperties.AddNew(customProperty.Name + "_copy", "CustomProperty");
                          
                      }
                    
                      elementCopy.Update();
                      Repository.RefreshModelView(parentPackage.PackageID);
                      diagram.Update();
                    
                }
                else
                {
                   MessageBox.Show("That's not a table, that's "+selectedElement.Stereotype);
                }
            }
            else
            {
                MessageBox.Show("That's not Element, that's "+o.GetType().ToString());
            }    
            
          
        }


Quote
If you're completely new to EA's API I can recommend my book Scripting EA. If you are deeper in the matters you should check out Geerts EA Navigator addin: http://bit.ly/Y1pCwT
Someday I propably will, but not yet, I'm not even sure if I'll use EA anymore (that strongly depends of this particular add-in to be honest) :)

5
Automation Interface, Add-Ins and Tools / Simple click->copy Add-in
« on: April 04, 2013, 07:33:11 am »
Hello,

I'm trying to write a simple add-in (with C#) that allows user to copy selected element with some modifications  pre-set in my add-in (e.g. with name change).

I'm totally new to EA (although with some experience in C#) and I have no idea how to enter into element's attributes, then change them and copy to new element.

As far as it goes I have only this:

 public void EA_MenuClick(EA.Repository Repository, string Location, string
        MenuName, string ItemName)
        {
            Object o = new Object();
            o = Repository.GetContextItem(out o);

        }

Poor, isn't it?

I've searched almost all the internet and didn't find a clue.

Thanks in advance for any help.

Pages: [1]