New symbols can be created using the MWOffice.Project.Symbols collection methods. Like most collections in theAPI you'll use a method on the collection to add a new element into the collection. In the case of symbols this requires a three step procedure:
Create a SymbolRecord object using the Symbols.CreateSymbolRecord method.
Add your shapes and nodes to the SymbolRecord object.
Create the symbol using the Symbols.CreateSymbol method specifying a name and providing the SymbolRecord object.
So the basic procedure is get a SymbolRecord, specify the symbols details and then use the symbol record to create the symbol. Let's take a look at what this looks like in code,
First, we create the SymbolRecord object:
' Create a symbol Record Set symbRec = Project.Symbols.CreateSymbolRecord
Here again we are using the global Project property of the MWOffice application object. We could have written:
Next we'll add some nodes to the symbol record:
Here we are using the standard spacing of 1000 units between nodes to make the size consistent with other element symbols in the system. Next we add some shapes to the record:
Finally having specified the nodes and the shapes we create the symbol:
Now we have a new symbol in the project named "MySymbol" which can be added to an element. So let's create a schematic and add an element with our new symbol:
So now we've created a new symbol in the Project.Symbols collection, added a schematic to the Project.Schematicscollection and added and element to the Elements collection of our new schematic that uses the symbol.
The complete code sample is as follows:
And the result looks like this: