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

Summary

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:

  1. Create a SymbolRecord object using the Symbols.CreateSymbolRecord method.

  2. Add your shapes and nodes to the SymbolRecord object.

  3. 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,

Code Snippets

First, we create the SymbolRecord object:

   ' Create a symbol Record
     Set symbRec = Project.Symbols.CreateSymbolRecord
     ' 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:

  ' Create a symbol Record
     Set symbRec = MWOffice.Project.Symbols.CreateSymbolRecord

    Next we'll add some nodes to the symbol record:
     symbRec.AddNode(0, 0, 50, 50, True)
     symbRec.AddNode(1000, 0, -50, 50, True)

 

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:

  	 symbRec.AddEllipse(300, -200, 700, 200)
     symbRec.AddLine(0, 0, 300, 0)
     symbRec.AddLine(700, 0, 1000, 0)
    

Finally having specified the nodes and the shapes we create the symbol:

      ' Create a symbol in the project, using the symbol record.
     Project.Symbols.CreateSymbol("MySymbol", symbRec)

 

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:

     ' Create and schematic and place an element using our new symbol.
     Dim schem As Schematic
     Dim elem As Element
     Set schem = Project.Schematics.Add("MySchematic")
     schem.Elements.Add("MLIN", 0, 0, 0, False, "MySymbol")


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:

 ' Code Module
Sub Main
     Dim symbRec As SymbolRecord

     ' Create a symbol Record
     Set symbRec = Project.Symbols.CreateSymbolRecord

     ' Add nodes and shapes to the symbol record.
     symbRec.AddNode(0, 0, 50, 50, True)
     symbRec.AddNode(1000, 0, -50, 50, True)
     symbRec.AddEllipse(300, -200, 700, 200)
     symbRec.AddLine(0, 0, 300, 0)
     symbRec.AddLine(700, 0, 1000, 0)

     ' Create a symbol in the project, using the symbol record.
     Project.Symbols.CreateSymbol("MySymbol", symbRec)

     ' Create and schematic and place an element using our new symbol.
     Dim schem As Schematic
     Dim elem As Element
     Set schem = Project.Schematics.Add("MySchematic")
     schem.Elements.Add("MLIN", 0, 0, 0, False, "MySymbol")

End Sub


And the result looks like this: