Author Topic: VBScript: Select element in the browser tree  (Read 4420 times)

m2i7c9k

  • EA User
  • **
  • Posts: 42
  • Karma: +0/-0
    • View Profile
VBScript: Select element in the browser tree
« on: January 21, 2021, 08:54:42 pm »
Hi Guys,

I can't figure out how c I select the element in the browser tree after adding new attributes to the element?
My code will select the newly added attribute in the Class, and I'd like to select the parent Class where I startred from.
Thanks for the advice.

sub main
   
   Repository.ClearOutput "Script"
   Repository.EnsureOutputVisible "Script"
   
   dim theElement as EA.Element
   set theElement = Repository.GetTreeSelectedObject()
   
   if not theElement is nothing and theElement.ObjectType = otElement then
      
      dim i, addedAttributeID
      
      Session.Output( "Working on element '" & theElement.Name & "' (Type=" & theElement.Type & _
         ", ID=" & theElement.ElementID & ")" )
      
      ' Create an attribute to work on
      dim attributes as EA.Collection
      set attributes = theElement.Attributes
      
      dim attName, attType, attScope
      dim newAtt, splitAtt
      
      dim iBox
      iBox=InputBox("Enter attribute", "Class Attribute", "attribute_name, string(150), public")
      
      if IsEmpty(iBox) Then
         exit sub
      else
         newAtt = iBox '"fullname, string(150), public"
         splitAtt = Array(Split(newAtt, ","))
         for each i in splitAtt
            attName = trim(i(0))
            Session.Output  attName
            attType = trim(i(1))
            Session.Output  attType
            attScope = trim(i(2))
            Session.Output  attScope
         next
         
         
         dim newAttribute as EA.Attribute
         set newAttribute = attributes.AddNew( attName, attType )
         newAttribute.Visibility(attScope)
         newAttribute.Update()
         attributes.Refresh()
         
         addedAttributeID = newAttribute.AttributeID
         
         Session.Output( "Added attribute: " & newAttribute.Name & _
            "(Type=" & newAttribute.Type & _
            ", ID=" & addedAttributeID & ")" )
      end if
   end if
   -->> SELECT the ELEMENT?
main

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 11299
  • Karma: +421/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: VBScript: Select element in the browser tree
« Reply #1 on: January 21, 2021, 09:35:09 pm »
What do you mean by "Select"?
If you mean select the element in the project browser you can use Repository.ShowInProjectView (object Item)

Geert

m2i7c9k

  • EA User
  • **
  • Posts: 42
  • Karma: +0/-0
    • View Profile
Re: VBScript: Select element in the browser tree
« Reply #2 on: January 21, 2021, 09:43:25 pm »
As always, thank you, Geert; it works perfectly.