Book a Demo

Author Topic: Adding a package with VB Script  (Read 6097 times)

Jayson

  • EA User
  • **
  • Posts: 363
  • Karma: +1/-0
    • View Profile
Adding a package with VB Script
« on: March 09, 2015, 07:58:34 am »
Believe it or not, even after having done a LOT of script I have NEVER used scripting to add a new package.

However, I now have the need to and am failing miserably for some reason.

My script looks like this:

Set m_rootPackage = Repository.GetElementByGUID(rootPackageGUID)
...
...
Set m_targetPackage = m_targetPackage
...
...
Set package = m_targetPackage.Packages.AddNew(m_packageName,"")
package.Update()
package.Packages.Refresh()

Unfortunately when I call Set package = m_targ.... I get the following error:

Object doesn't support thisproperty or method:'Packages'

Any help gratefully received :-)


qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Adding a package with VB Script
« Reply #1 on: March 09, 2015, 09:04:36 am »
Set m_targetPackage = m_targetPackage

does nothing. You likely want

Set m_targetPackage = m_rootPackage

to add the new package to the root. Else if you want to add to another exiting package use

Set m_targetPackage = Repository.GetElementByGUID(myotherGUID)


Then you can add via

Set package = m_targetPackage.Packages.AddNew(m_packageName,"")


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: Adding a package with VB Script
« Reply #2 on: March 09, 2015, 06:18:42 pm »
Quote
Set m_targetPackage = m_targetPackage

does nothing. You likely want

Set m_targetPackage = m_rootPackage

to add the new package to the root. Else if you want to add to another exiting package use

Set m_targetPackage = Repository.GetElementByGUID(myotherGUID)


Then you can add via

Set package = m_targetPackage.Packages.AddNew(m_packageName,"")


q.

Almost there. But you should get the package using

Code: [Select]
Set m_targetPackage = Repository.GetPackageByGuid(myotherGUID)  
This will result in an EA.Package element, which has the .Packages attribute.

If you use GetElementByGUID you get an EA.Element object, which doesn't have .Packages.

Geert

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Adding a package with VB Script
« Reply #3 on: March 09, 2015, 08:25:58 pm »
That happens if you copy/paste without thinking :-[

q.