A couple of Processbook VBA tips...

Discussion created by AlistairFrith on Mar 17, 2009
Latest reply on Oct 3, 2016 by jaroberts

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


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)

   dMacros.Symbols("TemplateComposite").selected = True
   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
     On Error Resume Next
     Set sComp = dCurrent.Symbols("TemplateComposite")
     On Error GoTo 0

   ' Extract the dummy objects in the composite and delete them
   Do While sComp.GroupedSymbols.count > 0
     sComp.GroupedSymbols.Remove (1)
   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.