Sparx Systems Forum

Enterprise Architect => Suggestions and Requests => Topic started by: m2i7c9k on January 21, 2021, 08:54:42 pm

Title: VBScript: Select element in the browser tree
Post by: m2i7c9k 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
Title: Re: VBScript: Select element in the browser tree
Post by: Geert Bellekens 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
Title: Re: VBScript: Select element in the browser tree
Post by: m2i7c9k on January 21, 2021, 09:43:25 pm
As always, thank you, Geert; it works perfectly.