Importing ShapesCognex VisionPro

VisionPro's CAD File Import Package lets you convert the shapes contained in a DXF-format CAD file into a collection of VisionPro shapes or shape models. As shown in the following figure, you can convert all of the shapes in a file or only the shapes within a DXF layer or group:

Search PMAlign Theory Importing Shapes simptx overview

If you are importing shapes from a CAD file to create a shape-trained PatMax pattern, you should import the shapes as a CogShapeModelCollection.

DXF Files

This section provides an overview of the DXF file format and describes how VisionPro imports the shape information from DXF files and converts it into VisionPro shapes or shape models.

DXF Version Support

The DXF format is an evolving standard, closely tracking released versions of AutoCAD software. VisionPro supports text-based DXF files in formats corresponding to the versions of AutoCAD shown below. VisionPro does not support the binary version of the DXF file format.

Table 1. DXF Versions Supported for Import
DXF Version IDAutoCAD VersionNotes
AC1009R11Same DXF version as R12
AC1009R12Supported by VisionPro
AC1012R13Supported by VisionPro
AC1014R14Supported by VisionPro
AC10152000Supported by VisionPro
AC10152000iSame DXF version as 2000
AC10152002Same DXF version as 2000
DXF File Sections

The DXF file format is divided into sections. The following table shows the DXF section names and how they are parsed by VisionPro during CAD file import.

Table 2. DXF Sections
DXF SectionImport Action
HEADERIgnored
TABLESParsed for information about the drawing’s layers
BLOCKSParsed for information about any custom objects and groups
ENTITIESParsed for information about basic drawing shapes and primitives
CLASSESIgnored
OBJECTSParsed for group information
DXF Entities

The DXF ENTITIES section contains one or more entities, each of which correspond to CAD drawing primitive shapes. The following table shows how the DXF entities are mapped to VisionPro shapes.

Table 3. DXF Entity Conversions
DXF EntityVisionPro Shape
ARCCogEllipticalArc
CIRCLECogEllipse

ELLIPSE

CogEllipticalArc

Depending on the angle span of the DXF file's ELLIPSE entity, the imported shape may be represented as a single CogEllipticalArc or as a CogGeneralContour object with two elliptical arc segments.

INSERTCogGeneralContour
LINECogLineSegment
LWPOLYLINECogGeneralContour
MLINECogGeneralContour

POINT

CogPointMarker

Keep in mind that there is no shape model object that corresponds to a CogPointMarker. Model Maker will ignore any POINT entities in a DXF file; if you want to import POINT entities, you must use the GetShapes method.

POLYLINECogGeneralContour
RAYCogLine
SOLIDBoundary converted to CogGeneralContour
SPLINEApproximated by a CogGeneralContour
XLINECogLine
Unsupported Entities

The following DXF entities are ignored by VisionPro during import.

3DFACE, HATCH, SEQEND, 3DSOLID, IMAGE, SHAPE, ACAD_PROXY_ENTITY,  
LEADER, TEXT, ATTDEF, MTEXT, TOLERANCE, ATTRIB, OLEFRAME, TRACE,  
BODY, OLE2FRAME, VERTEX, DIMENSION, REGION,VIEWPORT
Importing DXF Files

You import shapes from a DXF file using the properties and methods defined in the CogCADFile interface. The interface's methods offer you some control over how shapes are imported.

In all cases, however, the imported shapes are returned to you as either a CogShapeModelCollection (if you request shape models) or a CogGraphicCollection if you request shapes) that contains the individual shapes. The imported shapes will always include CogGeneralContour objects and primitive shape objects such as CogLineSegments.

Connectivity and Tolerance Settings

Most CAD files contain thousands of discrete, unconnected shape entities. In most cases, PatMax shape training will work better if related discrete shapes are connected into larger VisionPro shapes. For example, if the CAD file represents a rectangular shape using four contiguous LINE entities, PatMax will be more effective if those shapes are converted into a single CogPolygon.

You enable or disable the connection of shapes using the ConnectEnabled property. If shape connection is enabled, only the endpoints of adjacent shapes are connected. You specify the distance, in the DXF file's coordinate space units, within which two shapes' endpoints must lie of each other to be connected using the ConnectTolerance property.

As you increase the value of the ConnectTolerance, the imported CogShapeModelCollection will tend to have fewer, larger CogGeneralContour objects and fewer shape primitives. If you specify a value of 0 for the ConnectTolerance , the imported shape collection will still include some CogGeneralContour objects.

Often, DXF files may use many (tens of thousands) of very small graphic entities to represent complex shapes. Even when mapped through an appropriate calibrated coordinate space, the size of these shapes may be much less than a pixel, or even a tenth of a pixel. If you specify a connect tolerance of 0.25, and the DXF file contains a number of shapes each 0.05 pixels in size and lying within 0.25 pixels of each other, VisionPro may connect the shapes in inappropriate ways that produce degenerate shape errors (such as line segments which have the same start and end point).

If your DXF files contain large numbers of tiny shapes, you can prevent degenerate shape connection errors by specifying an appropriately small connect tolerance. If possible, however, you should attempt to modify the way in which the DXF file is created to reduce the number of shapes in the file.

Note: The Model Maker control does not let you specify the connect tolerance value explicitly. Instead, it lets you choose between not connecting shapes, connecting shapes that touch (using a fixed value for ConnectTolerance of 0.000000001), or connecting shapes that are nearby (using a fixed value for ConnectTolerance of 0.25 pixels, mapped through the selected selected space that you have selected in Model Maker's SSN popup menu). If you experience degenerate shape errors on import using Model Maker, specify Connect Coincident Points for the shape connection method.

Spline Mapping

VisionPro does not include a spline shape. When you import SPLINE entities from a DXF file, VisionPro converts these shapes into CogGeneralContour shapes. Because CogGeneralContour shapes comprise line segments and elliptical arc segments only, many spines can only be approximated rather than duplicated using a CogGeneralContour shape. The accuracy with which the spline is modeled depends on the number of segments in the CogGeneralContour. You control this value by specifying the maximum fit error (SplineApproximationTolerance) and the spacing at which to measure the fit error (SplineApproximationSpacing). You specify these values in the DXF file's coordinate space units.

Note: The Model Maker control does not let you specify these values. Instead, it uses a fixed value of 0.25 pixels for SplineApproximationTolerance and a fixed value of 1.0 pixels for SplineApproximationSpacing. Also, it maps these values to pixels using the selected space that you have selected in Model Maker's SSN popup menu.

Working with Layers and Groups

CAD drawings are usually constructed in layers. For example, one drawing layer might contain the lines and arcs of the drawing itself, while another layer contains text annotations. You can specify which drawing layer or layers to import using the VisionPro CAD file import package. You can determine the layers that are present in a DXF file in several ways.

  • Model Maker displays the layers when you import a DXF file.
  • You can use the GetLayers function.
  • You can view the DXF file in AutoCAD's free viewer Volo View Express, which is available for download from AutoCAD.

AutoCAD software also supports a feature called groups that allows the user to create a named group of objects that have a feature in common, independent of their hierarchy in the drawing. For example, all of the components of an assembly drawing that are sourced from the same vendor might be placed in the same group. Grouped objects can be on any drawing layer, and can thus cross layer boundaries.

You can use the same techniques you use to enumerate DXF layers to enumerate DXF groups.

  • Model Maker displays the groups when you import a DXF file.
  • You can use the GetGroups function.
  • You can view the DXF file in AutoCAD's free viewer Volo View Express, which is available for download from AutoCAD.