Creating a Symbol


 

Symbols can be directly created in code as well as in the user interface.  Creating symbols is similar to adding entities to the drawing with one minor change.  A symbol definition must first be created with VCCreateSymbolDef.  After the symbol definition has been created, any other operation normally used to add entities to a drawing can be used to add them to the symbol instead by simply substituting the proper symbol index.  The following code samples demonstrate creating a symbol in detail.

 

C++ VB.NET VBScript
// C++ to Create a Symbol
//   lines starting with a // are comments
void WINAPI CreateSym(charszDllCommandLine)
{
    //  used for error returns from the API
    short iError;
 
    // construct two point objects
    Point2D pt0;
    Point2D pt1;
 
    //  Create a symbol name:
    //      Create a reference to the symbol definition. The 
    //      definition allows the code to add a symbol to 
    //      currently active drawing session based on an internal 
    //      name.  The following code creates a new definition 
    //      with the name "MySymbolDefintion":
 
    short iSymbolIndex;
    iSymbolIndex = VCCreateSymbolDef(&iError"MySymbolDefintion");
 
    //  Add the entities directly to the symbol definition:
    //      The following code adds entities directly to the new 
    //      symbol definition.
 
    pt0.x = 0;
    pt0.y = 0;
    pt1.x = 0;
    pt1.y = 10;
 
    VCAddCircleEntity(&iErroriSymbolIndexpt0pt1);
    VCAddLineEntity(&iErroriSymbolIndexpt0pt1);
 
    //  Optional: Save the symbol definition to disk:
    //      When a symbol definition is created it is simply 
    //      loaded into the current drawing session.  In order to 
    //      utilize the definition in future drawing sessions, it 
    //      must be saved to disk.  The following code saves the 
    //      symbol to a VCS file.
 
    VCSaveVCS("MySymbolDefinition""C:\MyPath\Symbols\MySymbol.vcs");
}
' VB.NET to Create a Symbol
'   lines starting with an apostrophe are comments
Public Class CreateSym
 
    ' create Visual CADD object
    Shared WithEvents vcadd As New VCadd32.Automation
 
    Public Shared Function Run(ByVal str As StringAs Integer
 
        '   construct two point objects
        Dim pt0 As New VCadd32.VCPoint2D
        Dim pt1 As New VCadd32.VCPoint2D
 
        '   Create a symbol name:
        '       Create a reference to the symbol definition. The 
        '       definition allows the code to add a symbol to 
        '       currently active drawing session based on an internal 
        '       name.  The following code creates a new definition 
        '       with the name "MySymbolDefintion":
 
        Dim iSymbolIndex As Integer
        iSymbolIndex = vcadd.CreateSymbolDef("MySymbolDefintion")
 
        '   Add the entities directly to the symbol definition:
        '       The following code adds entities directly to the new 
        '       symbol definition.
 
        pt0.X = 0
        pt0.Y = 0
        pt1.X = 0
        pt1.Y = 10
 
        vcadd.AddCircleEntity(iSymbolIndex, pt0, pt1)
        vcadd.AddLineEntity(iSymbolIndex, pt0, pt1)
 
        '   Optional: Save the symbol definition to disk:
        '       When a symbol definition is created it is simply 
        '       loaded into the current drawing session.  In order to 
        '       utilize the definition in future drawing sessions, it 
        '       must be saved to disk.  The following code saves the 
        '       symbol to a VCS file.
 
        vcadd.SaveVCS("MySymbolDefinition""C:\MyPath\Symbols\MySymbol.vcs")
 
        ' return
        Return (True)
 
    End Function
 
End Class
' VBScript to Create a Symbol
'   lines starting with an apostrophe are comments
 
' create Visual CADD object
set vcadd = CreateObject("VisualCADD.Application.9")
set pt0 = CreateObject("VisualCADD.Point2D.9")
set pt1 = CreateObject("VisualCADD.Point2D.9")
 
'   Create a symbol name:
'       Create a reference to the symbol definition. The 
'       definition allows the code to add a symbol to 
'       currently active drawing session based on an internal 
'       name.  The following code creates a new definition 
'       with the name "MySymbolDefintion":
 
iSymbolIndex = vcadd.CreateSymbolDef("MySymbolDefintion")
 
'   Add the entities directly to the symbol definition:
'       The following code adds entities directly to the new 
'       symbol definition.
 
pt0.X = 0
pt0.Y = 0
pt1.X = 0
pt1.Y = 10
 
vcadd.AddCircleEntity iSymbolIndex, pt0, pt1 
vcadd.AddLineEntity iSymbolIndex, pt0, pt1 
 
'   Optional: Save the symbol definition to disk:
'       When a symbol definition is created it is simply 
'       loaded into the current drawing session.  In order to 
'       utilize the definition in future drawing sessions, it 
'       must be saved to disk.  The following code saves the 
'       symbol to a VCS file.
 
vcadd.SaveVCS "MySymbolDefinition""C:\MyPath\Symbols\MySymbol.vcs"
 
' release Visual CADD object
set vcadd = Nothing
set pt0 = Nothing
set pt1 = Nothing

 

See Also:

VCCreateSymbolDef, VCAddCircleEntity, VCAddLineEntity, VCSaveVCS