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:
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
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:
In the first part we just define some variables to hold referenced to intermediate values:
Next, we clear the debugging output window, add a schematic named "MySchematic" and then add a MLIN element to this schematic.
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.
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.
Running this script produces the following output:
Symbol Name = TLINE@system.syf Symbol Shapes = 7 Symbol Nodes = 2