3 of 3 people found this helpful
All static symbols (lines, rectangles, circles, polygons, etc) are not scriptable by default. Once you've added one to the display, you'll need to go into build mode, right click on the symbol, and select "Enable Scripting".
At that point, the rectangle should be scriptable, and its name in the VBA context will be the same as in the display when you hover over the symbol in build mode:
Lastly, is there a specific need for VBA for these symbols? Rectangles can become multistate symbols by clicking on them then on the multistate button, and the configuration menu there is usually everything you'd need. What specific actions were you looking to do within VBA?
Thank you Kelsey for your reply, Actually I have lots of rectangles in my displays and each rectangles have multi state. I understood your point.We can give multi state to all the rectangles by clicking on the multi state symbol as shown in above image.But It becomes the tedious process.So I was thinking that Is there any alternative way of it or not. Can we give multi state to all the rectangles by writing vb script?
1 of 1 people found this helpful
Here is example code that you could employ to create the multi-state, although you'll still need to follow the above steps to enable scripting on the rectangles. You should be able to do that quickly by going into build mode, ctrl+a, right click on something, "enable scripting".
Then you can use code such as this to define the states:
Dim mymultistate As MultiState Dim tagname As String tagname = "sinusoid" Set mymultistate = Rectangle1.CreateMultiState(tagname) With mymultistate .StateCount = 2 .DefineState 1, 0, 50 .DefineState 2, 50, 100 End With
It will follow the default color sequence controllable from ProcessBook > Tools > Preferences > Display Window > Color Palette.
To pull the existing multistate information from one rectangle and add it to another, you can do something like this:
Dim existingMSConfig As MultiState Set existingMSConfig = Rectangle1.GetMultiState Call Rectangle3.SetMultiState(existingMSConfig)
For any of these approaches, you can add this code to trigger on a button or similar, then disable it since you'll only want it to run once.
Couldn't you write a script that cycles through all symbols creating and setting multistate without "enabling scripting"?
I don't have time to fully write and test this, but I'm thinking of something like this starting with a group of symbols indiscriminately selected (cobbled together from existing bits of code, some tweaking will be needed like declaring/defining variables):
If Application.ActiveDisplay.SelectedSymbols.Count < 1 Then MsgBox "Select something. Anything." Exit Sub End If For i = 1 To Application.ActiveDisplay.SelectedSymbols.Count Set symb = Application.ActiveDisplay.SelectedSymbols.Item(i) If symb.Type = pbSymbolRectangle Then symb.CreateMultiState (tagName) Set oMultiState = symb.GetMultiState With oMultiState .StateCount = 2 .DefineState 1, 0, 0 .DefineState 2, 1, 1 .ColorBadData = gBadDataColor .BlinkBadData = False End With Set oState = oMultiState.GetState(1) With oState .Blink = False .Color = gSHNormalColor End With Set oState = oMultiState.GetState(2) With oState .Blink = False .Color = gSHAlarmColor End With End If Next