Book a Demo

Author Topic: VBscript  (Read 6501 times)

HenriqueBastos

  • EA Novice
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
VBscript
« on: February 25, 2022, 11:59:29 pm »
Dear all,

I am currently struggling with a simple issue, as some of you may know I am pretty new to EA. I am trying to write a script which allows me to select all Blocks within a Diagram and change the color of the Block. I am extremely grateful for any kind of feedback!

With kind regards yours Henrique Bastos.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13495
  • Karma: +572/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: VBscript
« Reply #1 on: February 26, 2022, 12:34:20 am »
You'll want a script that loops of the selected diagramobject and then change the BackgroundColor of the diagramObject, see
https://sparxsystems.com/enterprise_architect_user_guide/15.2/automation/diagramobjects.html

Here's an example that works on a diagram and loops the selected elements, so that should get you started.
https://github.com/GeertBellekens/Enterprise-Architect-VBScript-Library/blob/master/Projects/Bellekens/Bellekens%20Change%20Management/Link%20Selected%20Element(s)%20to%20CR.vbs

Geert

HenriqueBastos

  • EA Novice
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
Re: VBscript
« Reply #2 on: February 26, 2022, 01:04:19 am »
Thank you!

SystemsTinkerer

  • EA User
  • **
  • Posts: 48
  • Karma: +0/-0
    • View Profile
Re: VBscript
« Reply #3 on: February 28, 2022, 11:44:49 pm »
You'll want a script that loops of the selected diagramobject and then change the BackgroundColor of the diagramObject, see
https://sparxsystems.com/enterprise_architect_user_guide/15.2/automation/diagramobjects.html

Here's an example that works on a diagram and loops the selected elements, so that should get you started.
https://github.com/GeertBellekens/Enterprise-Architect-VBScript-Library/blob/master/Projects/Bellekens/Bellekens%20Change%20Management/Link%20Selected%20Element(s)%20to%20CR.vbs

Geert

Hi Geert,

I tried running your code "Link Selected Element(s) to CR.vbs" but it causes an error in file "LinkToCRMain.vbs" @line 43 : userLogin = getUserLogin
It does not recognise getUserLogin

I have imported the code using your XML file so I was expecting issues such as this.

Thanks,
Oz

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13495
  • Karma: +572/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: VBscript
« Reply #4 on: February 28, 2022, 11:51:54 pm »
That's because you are probably missing some of the included scripts.

If you search github for the function you'll find a couple of Util.vbs where that function is defined.
https://github.com/GeertBellekens/Enterprise-Architect-VBScript-Library/search?q=getUserLogin

Geert

SystemsTinkerer

  • EA User
  • **
  • Posts: 48
  • Karma: +0/-0
    • View Profile
Re: VBscript
« Reply #5 on: March 01, 2022, 12:00:03 am »
Got it! Many thanks Geert  :)

Best,
Oz

HenriqueBastos

  • EA Novice
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
Re: VBscript
« Reply #6 on: March 02, 2022, 09:22:42 pm »
I am running into similar problems while executing your script ‘LinktoCr’ is undefined.
What exactly is this variable ? I looked into the GitHub but I didn’t understand what exactly I need to add to the script so that it can run.
Sorry I really suck at EA and I don’t have the biggest Programming background.
I am trying to understand the example you’ve linked column for column so I’ll be able to handle similar tasks on my own in future.

Thanks a lot for your help and patient

Yours Henrique

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13495
  • Karma: +572/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: VBscript
« Reply #7 on: March 02, 2022, 09:32:53 pm »
EA has a method of including other scripts.

Look for the lines that start with !INC

LinkToCR is a function that is defined in an included script.

If you look here: https://github.com/GeertBellekens/Enterprise-Architect-VBScript-Library/blob/c3354b3f49069d354aa862569cf0a70410524e5c/Projects/Project%20A/A%20Scripts/LinkToCRMain.vbs

You'll find the function

Code: [Select]
function linkToCR(selectedItem, selectedItemType, CRToUse, userLogin, comments)
Session.Output "CRToUse: " & CRToUse.Name & " userLogin: " & userLogin & " comments: " & comments
dim crTag
set crTag = nothing
set crTag = selectedItem.TaggedValues.AddNew("CR","")
if not crTag is nothing then
crTag.Value = CRToUse.ElementGUID
crTag.Notes = "user=" & userLogin & ";" & _
"date=" & Year(Date) & "-" & Right("0" & Month(Date),2) & "-" & Right("0" & Day(Date),2) & ";" & _
"comments=" & comments
crTag.Update
end if
end function

But I'm not sure if that is really helpful for your problem.
I mentioned this script because it deals with diagramObjects, not because of the actual functionality of linking the items to a change request.

Geert


HenriqueBastos

  • EA Novice
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
Re: VBscript
« Reply #8 on: March 02, 2022, 09:43:37 pm »
Okay  :),
For now I don’t really think that I’ll need to link this script to anything else yet. For my problem I just need the For Each part with the selected objects ? Can I change the background color in the same for each loop adding the columns?

Your Henrique

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13495
  • Karma: +572/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: VBscript
« Reply #9 on: March 02, 2022, 09:57:47 pm »
Okay  :),
For now I don’t really think that I’ll need to link this script to anything else yet. For my problem I just need the For Each part with the selected objects ? Can I change the background color in the same for each loop adding the columns?

Your Henrique
Yes, simply loop the diagramobjects and update their properties.
Don't forget to call .Update to actually save your changes to the database

Geert

PS. I'm not sure what you mean by "adding the columns"

HenriqueBastos

  • EA Novice
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
Re: VBscript
« Reply #10 on: March 03, 2022, 01:21:24 am »
I meant that I added to the loop 3 columns 2 changing the colors and 1 updating the object but it isn’t doing any thing I don’t know how to uploads code in the forum because I always get a message saying it’s spam

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13495
  • Karma: +572/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: VBscript
« Reply #11 on: March 03, 2022, 02:08:42 am »
Then you'll probably need to debug it.
Step through the code and see what happens (or not)

Geert

HenriqueBastos

  • EA Novice
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
Re: VBscript
« Reply #12 on: March 04, 2022, 06:54:35 pm »
Hallo Geert,
Do I have to change something in columns 39 to 53 in the “ Link selected Element(s) to CR.vbs” script?

I tried to restart writing and copied columns 39-53 to a diagram vbscript. But once I run the program nothing is selected. Sorry if I am bothering you!

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13495
  • Karma: +572/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: VBscript
« Reply #13 on: March 04, 2022, 08:54:32 pm »
Hi Enrique,

I guess you mean rows instead of columns?

I'm sorry, I can't hold your had writing scripts like that. The best thing to do is start from the beginning, and try to understand what is happening.
Debugging the code and stepping through it might help as well.

In order to debug VBScripts, you'll need the Microsoft script debugger tool.

Geert

HenriqueBastos

  • EA Novice
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
Re: VBscript
« Reply #14 on: March 04, 2022, 09:32:41 pm »
Yes I somehow confused the rows with columns hahaha, by the way I just found out what went wrong I didn’t call the Function…. :D Now it’s running. Thanks for
Your help!