Thought I would post a couple of nuggets I have discovered since I seem to be asking a lot of questions at the moment.
If you try this
Application.ActiveDisplay.Symbols.Add(pbSymbolComposite)
you will get a message saying that you cannot create a composite object programatically (along with a few other tasks). However what you can do is copy an existing composite object. so I have the following function:
' We can't create a composite object programmatically but we can copy one from the
' macros display to the current display
Function NewComposite() As Composite
Dim dMacros As Display
Dim dCurrent As Display
Dim sComp As Composite
Set dMacros = builderDisplay() '<-- this function finds a display that has a specific composite symbol
Set dCurrent = Application.ActiveDisplay
' just make sure there is nothing selected
Do While dMacros.SelectedSymbols.count > 0
dMacros.SelectedSymbols.Remove (1)
Loop
dMacros.Symbols("TemplateComposite").selected = True
dMacros.Copy
Dim tries As Integer
Do While sComp Is Nothing And tries < 5 ' <-- can't remember why I had to retry this bit!
tries = tries + 1
dCurrent.Paste
On Error Resume Next
Set sComp = dCurrent.Symbols("TemplateComposite")
On Error GoTo 0
Loop
' Extract the dummy objects in the composite and delete them
Do While sComp.GroupedSymbols.count > 0
sComp.GroupedSymbols.Remove (1)
Loop
dCurrent.Symbols.Remove ("TempCompRect1")
dCurrent.Symbols.Remove ("TempCompRect2")
Set NewComposite = sComp
End Function
Another thing you cannot do in VBA is change the Z-order of the symbols on the display. However, what you can do is add them to a composite object and then remove them again. This will put them back in the display's symbols collection at the top of the Z-order.
Hope these tips are useful to people.
--- Alistair.
Alistair,
It is quite true that you cannot create a new composite via Symbols.Add as you can't supply the symbols to form the composite symbol. You need to select the symbols and then group them, the returned object is a composite symbol.
Example (assumes 2 rectangles on the display):