Book a Demo

Author Topic: GetRelationSet  (Read 5017 times)

ngong

  • EA User
  • **
  • Posts: 275
  • Karma: +2/-2
    • View Profile
GetRelationSet
« on: March 15, 2018, 11:50:59 pm »
I am trying to write a script (VBScript) that deletes all dependencies of an element. I tried to use GetRelationSet, but can not understand what I am doing wrong: if I put the constant rsDependStart as a parameter I get the failure Object required: '[string:""]'. Shall I pass a string?

BTW: As a "sporadic scripter" in a number of scripting languages, I would like to have a big set of examples that I can search quickly - just to remember the syntax and basic sequences of statements. Currently I am only able to search one script at a time. Any recommendation?
Rolf

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: GetRelationSet
« Reply #1 on: March 16, 2018, 12:51:36 am »
It's probably best to post the snippet of the code that fails.

q.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: GetRelationSet
« Reply #2 on: March 16, 2018, 12:54:21 am »
You have to use the enumeration value id.
In the script you are probably including: EAConstants-VBScript you'll find the following variables defined:

Code: [Select]
' =================================================================================================
' EnumRelationSetType
' See http://www.sparxsystems.com/enterprise_architect_user_guide/12.1/automation_and_scripting/enumrelationsettypeenum.html
' =================================================================================================
dim rsGeneralizeStart, rsGeneralizeEnd, rsRealizeStart, rsRealizeEnd, rsDependStart, rsDependEnd, _
rsParents

rsGeneralizeStart = 0
rsGeneralizeEnd = 1
rsRealizeStart = 2
rsRealizeEnd = 3
rsDependStart = 4
rsDependEnd = 5
rsParents = 6

I'm not sure why you are getting the error. Maybe because you are trying to set a string value?
The correct use would be

Code: [Select]
!INC Local Scripts.EAConstants-VBScript

'..other code
test = myElement.GetRelationSet(rsDependStart)
'..other code

You can search github for examples:

https://github.com/GeertBellekens/Enterprise-Architect-VBScript-Library

Geert


ngong

  • EA User
  • **
  • Posts: 275
  • Karma: +2/-2
    • View Profile
Re: GetRelationSet
« Reply #3 on: March 16, 2018, 01:37:38 am »
Thank you for your help, qwerty, Geert.

I am not at the point identifying the links of an element, just trying to find what elements are linked.
Thank you for the link to Git. However it seems that GetRelationSet is never used there? Perhaps it is the wrong idea using that one to find and later delete relations to other elements?

That is the code leading to 'Object required: '[string:""]' on line 18.

Code: [Select]
option explicit

!INC Local Scripts.EAConstants-VBScript
sub OnDiagramScript()
dim i
dim source as EA.Element
dim currentDiagram as EA.Diagram
set currentDiagram = Repository.GetCurrentDiagram()
if not currentDiagram is nothing then
dim selectedObjects as EA.Collection
set selectedObjects = currentDiagram.SelectedObjects
if selectedObjects.Count > 0 then
dim currentElement as EA.DiagramObject
set currentElement = selectedObjects.GetAt( 0 )
set source = Repository.GetElementByID(currentElement.ElementID)
If(source.Type = "InteractionOccurrence") then
dim all as EA.Collection
set all = source.GetRelationSet(rsDependStart)
Session.Output all.count
end if
end if
else
Session.Prompt "This script requires a diagram to be visible", promptOK
end if

end sub

OnDiagramScript
Rolf

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: GetRelationSet
« Reply #4 on: March 16, 2018, 01:53:01 am »
No, I don't think I've ever used this operation before.

I'm pretty sure if you replace
Code: [Select]
set all = source.GetRelationSet(rsDependStart)by
Code: [Select]
all = source.GetRelationSet(rsDependStart)the error will go away.

You may only use the keyword set when dealing with objects. And this operation returns a string.

Geert