Date: Fri, 29 Mar 2024 04:43:48 +0000 (GMT) Message-ID: <1685955952.99.1711687428034@[172.30.0.157]> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_98_930644988.1711687428034" ------=_Part_98_930644988.1711687428034 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html
New symbols can be created using the MWOffice.Project.Symbols collection= methods. Like most collections in theAPI you'll use a method on the collec= tion 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 me= thod.
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 detail= s 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 =3D Project.Symbols.CreateSymbolRecord
' Create a symbol Record Set symbRec =3D Project.Symbols.CreateSymbolRecord
Here again we are using the global Project property of the MWOffice appl= ication object. We could have written:
' = Create a symbol Record Set symbRec =3D MWOffice.Project.Symbols.CreateSymbolRecord
Next we'll add so=
me 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 ma= ke the size consistent with other element symbols in the system. Next we ad= d some shapes to the record:
= =09 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:<= /p>
= ' 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 ad= ded 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 =3D 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 th=
e Elements collection of our new schematic that uses the symbol.
The complete code sample is as follows:
' C= ode Module Sub Main Dim symbRec As SymbolRecord ' Create a symbol Record Set symbRec =3D 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 =3D Project.Schematics.Add("MySchematic") schem.Elements.Add("MLIN", 0, 0, 0, False, "MySymbol") End Sub
And the result looks like this: