Page tree
Skip to end of metadata
Go to start of metadata

Summary

Information about all the symbols in a project are contained in the MWOffice.Project.Symbols collection. This collection has an index member called Item defined as follows:

Symbol Symbols.Item(VARIANT Index)

Given an index, it will return the corresponding symbol. The Index for this method is a VARIANT indicating that it may be a integer value like a 1, 2, 3, 4…. or a string value such as "MySymbol@system.syf".

Now if we look at the Element object, it defines a property Element.Symbol which returns a string value. So the key to accessing the symbol efficiently is to use this Element.Symbol string property as an index into theMWOffice.Project.Symbols collection.

A couple of things to remember:

  1. All methods and properties of MWOffice are added to the global namespace so MWOffice.Project.Symbols

    is the same as Project.Symbols. In these cases, if we leave off the MWOffice. and just use Project.Symbols

    it is understood to be MWOffice.Project.Symbols

  2. Each collection has a default method. In the case of collections, the default method is Item. This means thatProject.Symbols.Item("SymName.syf")is the same as Project.Symbols("SymName.syf"). So if we leave off the .Item and just write Project.Symbols("SymName.syf") it is understood to mean Project.Symbols.Item("MySymbol@system.syf")

With these two things in mind consider the following Visual Basic script code:

Code Snippets

 ' Code Module
Sub Main
     Dim schem As Schematic
     Dim elem As Element
     Dim symb As Symbol

     Debug.Clear
     Set schem = Project.Schematics.Add("MySchematic")
     Set elem = schem.Elements.Add("MLIN", 0, 0)

     If (elem.Symbol = "") Then
          Set symb = Project.Symbols.GetDefaultSymbol(elem.Nodes.Count)
     Else
          Set symb = Project.Symbols(elem.Symbol)
     End If

     Debug.Print "Symbol Name   = " & symb.Name
     Debug.Print "Symbol Shapes = " & symb.Shapes.Count
     Debug.Print "Symbol Nodes  = " & symb.Nodes.Count
End Sub

 

 

In the first part we just define some variables to hold referenced to intermediate values:

     
     Dim schem As Schematic
     Dim elem As Element
     Dim symb As Symbol

 

 

Next, we clear the debugging output window, add a schematic named "MySchematic" and then add a MLIN element to this schematic.

     Debug.Clear
     Set schem = Project.Schematics.Add("MySchematic")
     Set elem = schem.Elements.Add("MLIN", 0, 0)

In the next section we have to do a check on the element's symbol name. If the symbol name is empty then the element will be using the default symbol. The default symbol is assigned to any elements without a named symbol and it's shape depends on the number of nodes the element has. If the element's symbol name is empty then we get the default symbol for an element with the number of nodes on this element. If the name is not empty we index directly into the symbols collection with the Symbol property from the Element.

     If (elem.Symbol = "") Then
          Set symb = Project.Symbols.GetDefaultSymbol(elem.Nodes.Count)
     Else
          Set symb = Project.Symbols(elem.Symbol)
     End If


Either way we get a reference to the symbol that is associated with this element. Once we have the reference we can print the properties and even get the shapes for the symbol.

    Debug.Print "Symbol Name   = " & symb.Name
     Debug.Print "Symbol Shapes = " & symb.Shapes.Count
     Debug.Print "Symbol Nodes  = " & symb.Nodes.Count
     
 

Running this script produces the following output:

Symbol Name   = TLINE@system.syf
Symbol Shapes = 7
Symbol Nodes  = 2