-1

I am struggling to make sense of the VBScript API to Enterprise Architect.

I want to add an artefact if and only if it has not already been added, its a large import so I want to use the GetElementsByQuery interface to check if class or interface has already been created and then use the existing reference rather than a new one.

the following code throws an exception every time, even when I know strSourceName is already added to the repository.

on error resume next ' in case no object found the query will throw an exception 
objCollection = Ea.Repository.GetElementsByQuery( "Simple", "strSourceName" )
If Err.Number = 0 Then
    Session.Output( "info: found :" & strSourceName & ":" )
Else
    Session.Output( "warn: not found :" & strSourceName & ":" )
    Err.Clear
End If

I am not familiar with either EA or VBScript so please go easy on me.

Thanks in advance for any help.

  • If you get an exception make sure to add that info to your question (and google the exception first). The problem has nothing to do with the actual source, but is simply a syntax error. You have to use `set` when assigning to object variables. – Geert Bellekens Mar 28 '18 at 08:45

1 Answers1

0

There are a couple of quirks with your script. Try this one:

dim o as EA.Collection
set o = Repository.GetElementsByQuery ("Simple", "strSourceName" )
Session.Output( "info: found :" & o.Count & ":" )

You will see that o.Count is either 0 or something greater than 0.

qwerty_so
  • 35,448
  • 8
  • 62
  • 86