Book a Demo

Author Topic: use data from excel table  (Read 19154 times)

blabla

  • EA User
  • **
  • Posts: 21
  • Karma: +0/-0
    • View Profile
use data from excel table
« on: April 23, 2015, 10:01:18 pm »
hello

I'm using EA11. I want to use data from a excel file in a state diagramm.
for example:

time  data
  0      0
  1      2
  2      4
  ..      ..

Can I use this data. For example for a Transistion. [data>=3].

Maybe you can sen a short example. It would be very helpful.
thanks for every help ;)

blabla

  • EA User
  • **
  • Posts: 21
  • Karma: +0/-0
    • View Profile
Re: use data from excel table
« Reply #1 on: April 23, 2015, 10:30:49 pm »
Quote
hello

I'm using EA11. I want to use data from a excel file in a state diagramm.
for example:

time  data
  0      0
  1      2
  2      4
  ..      ..

Can I use this data. For example for a Transistion. [data>=3].

Maybe you can sen a short example. It would be very helpful.
thanks for every help ;)


maybe I can use the excelimporterv3??

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: use data from excel table
« Reply #2 on: April 23, 2015, 11:07:48 pm »
I'm not sure, I don't really see what the result of the import should be.
If you are importing elements, attributes or glossary items the excel importer can certainly be used.
For any other thing you'll have to write some vba code yourself.

Geert

blabla

  • EA User
  • **
  • Posts: 21
  • Karma: +0/-0
    • View Profile
Re: use data from excel table
« Reply #3 on: April 24, 2015, 05:22:06 pm »
time and data should be variable.
array would be the best.
I want to import data from a other simulation programm and use the imported data in a state diagramm


blabla

  • EA User
  • **
  • Posts: 21
  • Karma: +0/-0
    • View Profile
Re: use data from excel table
« Reply #4 on: April 24, 2015, 06:23:44 pm »
I'm trying to use the vba programm to read the inital value, but I don't know  how I can  insert the value.

To read the value of the excel shit is not  a problem.

only the syntax at the creation and update of the attributs

Code: [Select]
'-------------------------------------------------------------
' Author:   Geert Bellekens
' Date:     01/09/2009
' Description: Gets the data from the active excel sheet and
'   creates the classes and attributes defined on there
'-------------------------------------------------------------
Public Sub importFromExcel()
Dim excelConn As New ExcelConnector
Dim eaConn As New EAConnector
Dim excelData As Collection
Dim parentPackage As EA.package
'get the selected package
Set parentPackage = eaConn.getSelectedPackage()
'read the data in the active excel sheet starting from the second row (first row is for the headings
Set excelData = excelConn.getValues(2, 1)
'loop the data
Dim row As Collection
'loop rows
Dim currentClass As EA.element
For Each row In excelData
    Dim elementType As String 'Class or Attribute
    Dim name As String
    Dim stereotype As String
    Dim description As String
    Dim attrType As String
    Dim inital_value As String
    Dim attributeLength As String
    'get the type of element
    elementType = row.Item(1)
    'get the name
    name = row.Item(2)
    'get the stereotype
    If row.Count > 2 Then
        stereotype = row.Item(3)
        If stereotype = "null" Then
            stereotype = ""
        End If
    Else
        stereotype = ""
    End If
    
    
    'get the description
    If row.Count > 3 Then
        description = row.Item(4)
    Else
        description = ""
    End If
    'get the Initial Value
    If row.Count > 6 Then
        inital_value = row.Item(7)
    Else
        inital_value = ""
    End If
    
    
    If eaConn.isValidElementType(elementType) Then
            'create the element
            Set currentClass = eaConn.addOrUpdateElement(parentPackage, elementType, name, stereotype, description)
    ElseIf elementType = "Attribute" Then
        If row.Count > 4 Then
            'get the attribute type
            attrType = row.Item(5)
            If attrType = "null" Then
                attrType = ""
            End If
        Else
            attrType = ""
        End If
        
        Dim currentAttribute As EA.Attribute
        Set currentAttribute = eaConn.addOrUpdateAttribute(currentClass, name, stereotype, inital_value, attrType)
        
        'get the attribute lenght
        If row.Count > 5 Then
            attributeLength = row.Item(6)
            'create or update the length tag
           eaConn.addOrUpdateAttributeTag currentAttribute, "length", attributeLength
        End If
    End If
Next
'refresh the contents of the package so that the changes are seen in EA
eaConn.refreshModelView parentPackage
End Sub

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: use data from excel table
« Reply #5 on: April 24, 2015, 07:19:53 pm »
I'm sorry, I still have no clue as to what you are trying to achieve :-[

As such I can't really give you any helpful advice.

Geert

blabla

  • EA User
  • **
  • Posts: 21
  • Karma: +0/-0
    • View Profile
Re: use data from excel table
« Reply #6 on: April 29, 2015, 11:35:51 pm »


I would like to type in the value of the attribute in excel and bring it to Enterprise Architect. You can see this in the picture.
Example:
It is like variable in c of type char with the value 5 and the name variable.
I don'know what I have to write in vba to insert the inital value from excel to EA.

Next challange is to use the attribut in a state diagramm as a transition.

I have to change something here

Code: [Select]
Public Function addOrUpdateAttribute(parentClass As EA.element, name As String, stereotype As String, description As String, attrType As String) As EA.Attribute
    Dim myAttribute As EA.Attribute
    'try to find existing attribute with the given name
    Set myAttribute = getAttributeByName(parentClass, name)
    If myAttribute Is Nothing Then
        'no existing attribute, create new
        Set myAttribute = parentClass.Attributes.AddNew(name, "Attribute")
    End If
    'set properties
    myAttribute.stereotype = stereotype
    myAttribute.Notes = description
    myAttribute.Type = attrType
    'myAttribute.Initial Value = attrType
    'save attribute
    myAttribute.Update
    'refresh attributes collection
    parentClass.Attributes.Refresh
    'return attribute
    Set addOrUpdateAttribute = myAttribute
End Function
« Last Edit: May 01, 2015, 12:18:30 am by blablabla »

Prateek

  • EA User
  • **
  • Posts: 33
  • Karma: +0/-0
    • View Profile
Re: use data from excel table
« Reply #7 on: May 29, 2015, 06:47:19 pm »
Hi All,

I am also facing the same issue. I have about hundreds of attributes in Excel and those attributes have to be added to existing classes in EA.
By CSV import/export I can add tagged values. Is there any way by which I can add/update attributes for existing class.

I do not have an exposure in scripting. Is it possible without scripting? Or if anyone has ever faced the same issue would request to help.

Thanks in advance!!

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: use data from excel table
« Reply #8 on: May 29, 2015, 11:57:05 pm »
Hi,

You can use my excel to EA importer to import attributes to existing classes.

Geert

Prateek

  • EA User
  • **
  • Posts: 33
  • Karma: +0/-0
    • View Profile
Re: use data from excel table
« Reply #9 on: June 03, 2015, 02:09:19 pm »
You area saviour Geert!!

Thanks a lot :) :)

Prateek

  • EA User
  • **
  • Posts: 33
  • Karma: +0/-0
    • View Profile
Re: use data from excel table
« Reply #10 on: July 03, 2015, 08:24:18 pm »
Hi All,

I am using the excel to EA importer. I tried learning VBA for the same and have been able to modify the script to my needs. But I am stuck at one place. I do not know how to modify the Scope for the attribute.
By default the new attributes created by the code are of 'public' scope.
In the function mentioned below I tried to update the scope as highlighted but does not work.

Private Function addOrUpdateAttribute(parentClass As EA.element, name As String, alias As String, description As String, attrType As String) As EA.Attribute
    Dim myAttribute As EA.Attribute
    'try to find existing attribute with the given name
    Set myAttribute = getAttributeByName(parentClass, name)
    If myAttribute Is Nothing Then
        'no existing attribute, create new
        Set myAttribute = parentClass.Attributes.AddNew(name, "Attribute")
    End If
    'set properties
    myAttribute.name = name
    'myAttribute.alias = alias
    myAttribute.Notes = description
    myAttribute.Type = attrType
    [highlight]myAttribute.Scope= "Private"[/highlight]    'save attribute
    myAttribute.Update
    'refresh attributes collection
    parentClass.Attributes.Refresh
    'return attribute
    Set addOrUpdateAttribute = myAttribute
End Function


Please suggest what code do I write to change the scope of the attribute.

Thank you in advance!!
« Last Edit: July 03, 2015, 08:28:37 pm by bhadulaprateek »

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: use data from excel table
« Reply #11 on: July 04, 2015, 12:51:46 am »
Yeah. EA strikes again. Use Visibility instead of Scope.

Quote
[highlight]Visibility[/highlight]

Identifies the [highlight]scope[/highlight] of the attribute - Private, Protected, Public or Package.
 

Analogously black is white and white is black. And the responsible person got killed on a zebra crossing.

q.
« Last Edit: July 04, 2015, 12:54:00 am by qwerty »

Prateek

  • EA User
  • **
  • Posts: 33
  • Karma: +0/-0
    • View Profile
Re: use data from excel table
« Reply #12 on: July 06, 2015, 11:50:15 am »
Thanks a lot!! Its Monday morning and the code is working. Great start for the week. ;D

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: use data from excel table
« Reply #13 on: July 06, 2015, 03:53:07 pm »
Quote
Yeah. EA strikes again. Use Visibility instead of Scope.
Or you could look beyond EA, to UML itself.

Quote
visibility : VisibilityKind [0..1] Determines whether and how the NamedElement is visible outside its owning Namespace.

EA's UI does say scope. But from the perspective of most people I know that would be defining attributes/operations of a class, that is a more familiar term.

Prateek

  • EA User
  • **
  • Posts: 33
  • Karma: +0/-0
    • View Profile
Re: use data from excel table
« Reply #14 on: August 28, 2015, 09:19:04 pm »
Hi All,

I am working on importing attributes and classes from Excel to EA. Geert's EA to Excel importer was pretty helpful. I had modified it a bit to my needs but there is one problem I am facing. The code lets you select only single package. What if I have classes grouped under different packages? I have to run it  multiple times by selecting each package. Is there any function whcih lets you select multiple packages or searches for the class in the entire hierarchy of packages?

Thanks
Prateek