Adding a Hatch/Fill Entity


 

Hatch and fill entities behave very similar to the continuous entities in that a definition must be placed in the database and then entities and points used to define the definition. The difference is that a hatch entity boundary can be defined by any of the other geometry entities. For example, a circle and a rectangle can be used to define the boundaries of the pattern. Therefore, when adding a hatch entity, the application must add a reference to the hatch and then add single or continuous entities to define the boundary. The defined boundary must be a closed element in order to complete the process. The following steps illustrate this concept in detail.

 

C++ VB.NET VBScript
// C++ to Add a Hatch Entity
//   lines starting with a // are comments
void WINAPI AddHatchEnt(char* szDllCommandLine)
{
    //  used for error returns from the API
    short iError;
 
    //  an entity handle, an index into the drawing database
    long hEnt;
    
    // construct two point objects
    Point2D pt0;
    Point2D pt1;
 
    //  Optional: Set the properties for the new entity:
    //      Hatch settings have their own specific settings separate 
    //      from the drawing properties of layer, color, line type, 
    //      and line width settings.  Specific settings calls 
    //      are required to alter the color, pattern rotation, and 
    //      scale.  If no settings are specified, Visual CADD will 
    //      use the current settings.  The following code sets the 
    //      hatch pattern to ZigZag with a scale of 5.0, rotation 
    //      angle of 0.0, and color to blue (index 9):
 
    VCSetHatchColor(&iError, 9);
    VCSetHatchRot(&iError, 0.0);
    VCSetHatchScale(&iError, 5.0);
    VCSetHatchName(&iError, "ZigZag");
 
    //  Add a reference to the entity to the database:
    //      Hatch entities allow different combinations of entities 
    //      to form the boundary.  These entities need to be added 
    //      to an existing hatch entity.  After the hatch entity is 
    //      added drawing database, entities are added to the hatch 
    //      and sorted to verify the new boundary.  The following 
    //      code adds a Hatch entity which initially has no boundary:
 
    VCAddHatchEntity(&iError, -1);
 
    //      In order to add boundary entities to the hatch, the new 
    //      entity must be set current.  Each entity in the drawing 
    //      database is referenced based on a handle or index 
    //      allowing applications to quickly access entities with 
    //      VCSetCurrentEntity.  The following code gets the handle 
    //      (index) of the newly placed entity and sets it as the 
    //      current entity.
 
    VCLastEntity(&iError, &hEnt);
    VCSetCurrentEntity(&iError, hEnt);
 
    //  Add entities to create the boundary:
    //      The added entities must create a closed boundary for the 
    //      hatch.  These boundaries can be made of either single or 
    //      continuous entities.  Please see the topic Adding a 
    //      Continuous Entity for more information about continuous 
    //      entities.  The following code creates a hatch boundary 
    //      based on a circle entity.  Note the -2 means to add the 
    //      entity to the hatch definition.
 
    pt0.x = 0.0;
    pt0.y = 0.0;
    pt1.x = 0.0;
    pt1.y = 10.0;
    VCAddCircleEntity(&iError, -2, pt0, pt1);
 
    //  Sort the Hatch/Fill Entity:
    //      After the boundary has been created, the Visual CADD 
    //      engine must parse the boundary and determine if it is 
    //      closed. Only closed boundaries can be hatched or filled.  
    //      The following code hatches the boundaries if they are 
    //      closed:
 
    VCSortCurrentHatchFillEntity(&iError);
 
    //  Optional - Draw the new entity to the screen:
    //      New entities are not automatically displayed on the 
    //      screen after being added to the database.  The entity 
    //      will be drawn during the next redraw or paint event,
    //      such as a VCZoomAll() or a UI command Regen/RD.  In order
    //      to draw the entity immediately, use VCDrawCurrentEntity:
 
    VCDrawCurrentEntity(&iError);
}
' VB.NET to Add a Hatch Entity
'   lines starting with an apostrophe are comments
Public Class AddHatchEnt
 
    ' create Visual CADD object
    Shared WithEvents vcadd As New VCadd32.Automation
 
    Public Shared Function Run(ByVal str As StringAs Integer
 
        '   an entity handle, an index into the drawing database
        Dim hEnt As Integer
 
        '   construct two point objects
        Dim pt0 As New VCadd32.VCPoint2D
        Dim pt1 As New VCadd32.VCPoint2D
 
        '   Optional: Set the properties for the new entity:
        '       Hatch settings have their own specific settings separate 
        '       from the drawing properties of layer, color, line type, 
        '       and line width settings.  Specific settings calls 
        '       are required to alter the color, pattern rotation, and 
        '       scale.  If no settings are specified, Visual CADD will 
        '       use the current settings.  The following code sets the 
        '       hatch pattern to ZigZag with a scale of 5.0, rotation 
        '       angle of 0.0, and color to blue (index 9):
 
        vcadd.SetHatchColor(9)
        vcadd.SetHatchRot(0.0)
        vcadd.SetHatchScale(5.0)
        vcadd.SetHatchName("ZigZag")
 
        '   Add a reference to the entity to the database:
        '       Hatch entities allow different combinations of entities 
        '       to form the boundary.  These entities need to be added 
        '       to an existing hatch entity.  After the hatch entity is 
        '       added drawing database, entities are added to the hatch 
        '       and sorted to verify the new boundary.  The following 
        '       code adds a Hatch entity which initially has no boundary:
 
        vcadd.AddHatchEntity(-1)
 
        '       In order to add boundary entities to the hatch, the new 
        '       entity must be set current.  Each entity in the drawing 
        '       database is referenced based on a handle or index 
        '       allowing applications to quickly access entities with 
        '       VCSetCurrentEntity.  The following code gets the handle 
        '       (index) of the newly placed entity and sets it as the 
        '       current entity.
 
        hEnt = vcadd.LastEntity()
        vcadd.SetCurrentEntity(hEnt)
 
        '   Add entities to create the boundary:
        '       The added entities must create a closed boundary for the 
        '       hatch.  These boundaries can be made of either single or 
        '       continuous entities.  Please see the topic Adding a 
        '       Continuous Entity for more information about continuous 
        '       entities.  The following code creates a hatch boundary 
        '       based on a circle entity.  Note the -2 means to add the 
        '       entity to the hatch definition.
 
        pt0.X = 0.0
        pt0.Y = 0.0
        pt1.X = 0.0
        pt1.Y = 10.0
        vcadd.AddCircleEntity(-2, pt0, pt1)
 
        '   Sort the Hatch/Fill Entity:
        '       After the boundary has been created, the Visual CADD 
        '       engine must parse the boundary and determine if it is 
        '       closed. Only closed boundaries can be hatched or filled.  
        '       The following code hatches the boundaries if they are 
        '       closed:
 
        vcadd.SortCurrentHatchFillEntity()
 
        '   Optional - Draw the new entity to the screen:
        '       New entities are not automatically displayed on the 
        '       screen after being added to the database.  The entity 
        '       will be drawn during the next redraw or paint event,
        '       such as a VCZoomAll() or a UI command Regen/RD.  In order
        '       to draw the entity immediately, use VCDrawCurrentEntity:
 
        vcadd.DrawCurrentEntity()
 
        ' return
        Return (True)
 
    End Function
 
End Class
' VBScript to Add a Hatch Entity
'   lines starting with an apostrophe are comments
 
' create Visual CADD and point objects
set vcadd = CreateObject("VisualCADD.Application.9")
set pt0 = CreateObject("VisualCADD.Point2D.9")
set pt1 = CreateObject("VisualCADD.Point2D.9")
 
'   Optional: Set the properties for the new entity:
'       Hatch settings have their own specific settings separate 
'       from the drawing properties of layer, color, line type, 
'       and line width settings.  Specific settings calls 
'       are required to alter the color, pattern rotation, and 
'       scale.  If no settings are specified, Visual CADD will 
'       use the current settings.  The following code sets the 
'       hatch pattern to ZigZag with a scale of 5.0, rotation 
'       angle of 0.0, and color to blue (index 9):
 
vcadd.SetHatchColor(9)
vcadd.SetHatchRot(0.0)
vcadd.SetHatchScale(5.0)
vcadd.SetHatchName("ZigZag")
 
'   Add a reference to the entity to the database:
'       Hatch entities allow different combinations of entities 
'       to form the boundary.  These entities need to be added 
'       to an existing hatch entity.  After the hatch entity is 
'       added drawing database, entities are added to the hatch 
'       and sorted to verify the new boundary.  The following 
'       code adds a Hatch entity which initially has no boundary:
 
vcadd.AddHatchEntity(-1)
 
'       In order to add boundary entities to the hatch, the new 
'       entity must be set current.  Each entity in the drawing 
'       database is referenced based on a handle or index 
'       allowing applications to quickly access entities with 
'       VCSetCurrentEntity.  The following code gets the handle 
'       (index) of the newly placed entity and sets it as the 
'       current entity.
 
hEnt = vcadd.LastEntity()
vcadd.SetCurrentEntity(hEnt)
 
'   Add entities to create the boundary:
'       The added entities must create a closed boundary for the 
'       hatch.  These boundaries can be made of either single or 
'       continuous entities.  Please see the topic Adding a 
'       Continuous Entity for more information about continuous 
'       entities.  The following code creates a hatch boundary 
'       based on a circle entity.  Note the -2 means to add the 
'       entity to the hatch definition.
 
pt0.X = 0.0
pt0.Y = 0.0
pt1.X = 0.0
pt1.Y = 10.0
vcadd.AddCircleEntity -2, pt0, pt1 
 
'   Sort the Hatch/Fill Entity:
'       After the boundary has been created, the Visual CADD 
'       engine must parse the boundary and determine if it is 
'       closed. Only closed boundaries can be hatched or filled.  
'       The following code hatches the boundaries if they are 
'       closed:
 
vcadd.SortCurrentHatchFillEntity()
 
'   Optional - Draw the new entity to the screen:
'       New entities are not automatically displayed on the 
'       screen after being added to the database.  The entity 
'       will be drawn during the next redraw or paint event,
'       such as a VCZoomAll() or a UI command Regen/RD.  In order
'       to draw the entity immediately, use VCDrawCurrentEntity:
 
vcadd.DrawCurrentEntity
 
' release Visual CADD and point objects
set vcadd = Nothing
set pt0 = Nothing
set pt1 = Nothing

 

See Also:

VCSetHatchColor, VCSetHatchRot, VCSetHatchScale, VCSetHatchName, VCAddHatchEntity, VCLastEntity, VCSetCurrentEntity, VCAddCircleEntity, VCSortCurrentHatchFillEntity, VCDrawCurrentEntity