Applying Tools from Command Line

LinkCAD has extensive support for controlling the conversion process from the command line.

The following documentation explains how to apply various LinkCAD tools from the command line.

Automating Conversion

LinkCAD conversion tasks can be automated by means of command line arguments, as described in the LinkCAD help file, chapter “Customization Guide”. The following parameters are of particular interest in this context:

  • LcImportFormat selects the import format
  • LcExportFormat selects the export format
  • LcImportFile or -i specifies the file to import
  • LcExportFile or -o specifies the converted file
  • LcSkipSteps specifies which part of the LinkCAD user interface to hide (eg. -LcSkipSteps=all)

This document describes the command line argument ToolApply, which is used to apply a series of transformations to the imported file.

ToolApply Syntax

In order to apply a tool command to the loaded file, one of the following commands needs to be specified using the ToolApply command line argument. The general syntax is:

-ToolApply=cmd1;cmd2;cmd3;...

where cmdn is any of the command below. They will be applied in the order specified; you can even run the same command, with the same or different parameters, several times.

Important: Do not include any white space characters in the argument to the ToolApply parameter.

The following lists the various commands that may be specified using the ToolApply parameter.

Setting Processing Modes

This section lists all valid ToolApply commands that can be used to specify various processing modes for the tool commands described in the next section.

SetUnits(unit-name)

  • unit-name is one of nm|um|mil|point|mm|cm|in|m|ft|pm.

This sets the units to be used by any tool following this command. You can change units as many times as needed.

Example:
-ToolApply=SetUnits(mm);JoinOpenPolylines(120)

SetResolution(value)

  • value is either a number or a number and a unit (as in unit-name in SetUnits, but also dpi is possible).

Sets the resolution to be used for following tools (default is taken from ToolArcPrecValue and ToolArcPrecUnits if SetResolution is not specified). You can change resolution as many times as needed.

Example 1: Join polygons with a tolerance of 120 mm, and convert arcs, if needed, with 32 faces / 360°:
-ToolApply=SetResolution(32);SetUnits(mm);JoinOpenPolygons(120)
Example 2: Join polygons with a tolerance of 120 mm, and convert arcs, if needed, with a precision of 10 nm:
-ToolApply=SetResolution(10nm);SetUnits(mm);JoinOpenPolygons(120)

SetFillRule(rule)

  • rule is either NonZero or EvenOdd.

This selects the fill rule to be used by tools following this command, and that rely on this setting. If absent, the default is taken from the option parameter -ToolEvenOddFill.

SetHolesMode(mode)

  • mode is either Link or Split.

This selects the hole split mode used by tools following this command, and that rely on this setting. If absent, the default is taken from the option parameter -ToolDeembedCutLines.

SetEdgePolicy(policy)

  • policy is either Merge or Keep.

This specifies how to handle internal edges during a Boolean operation, such as MergeOverlappingPolygons. If absent, the default is taken from the option parameter -ToolKeepInternalEdges.

Performing Tool Commands

Explode(shape-type)

  • shape-type is one of All|Polylines|Text|Circles|Nurbs|Donuts|DonutsSplit|Arcs.

This explodes the specified shapes to polygons. If more than one type needs to be exploded, either use All, or repeat the command for the desired types.

CropBounds(x0,y0,x1,y1)

  • x0,y0,x1,y1 specifies the crop window. They are expressed in the units specifies using SetUnits.

Crops the drawing to the specified size.

Example:
-ToolApply=SetUnits(mm);CropBounds(-100,-150,900,100)

MergeZeroWidthPolylines(tolerance)

where tolerance specifies the maximum tolerance distance. The tolerance value is expressed in the units specifies using SetUnits.

Merges zero-width polylines by performing the following steps on zero-width polylines:

  1. Split polylines in individual segments at their vertices;
  2. Snap segment end-points to near segment if within tolerance distance;
  3. Split segments at common intersections;
  4. Remove any redundant (duplicate) segments;
  5. Reassembly (possibly open) polylines from remaining segments.
It makes sense to follow this operation by JoinOpenPolylines, in order to create closed polygons from the merged polylines
Example 1: Merge zero-width polylines with a tolerance of 120 mm, and convert arcs, if needed, with 32 faces / 360°:
-ToolApply=SetResolution(32);SetUnits(mm);MergeZeroWidthPolylines(120)

JoinOpenPolylines(tolerance)

where tolerance specifies the maximum distance between adjacent polyline end-points. The tolerance value is expressed in the units specifies using SetUnits.

Joins open polylines, and turns them into polygons.

It makes sense to preceed this operation by MergeZeroWidthPolylines, in order to simplify polylines prior to joining them.
Example 1: Join zero-wdith polylines with a tolerance of 120 mm, and convert arcs, if needed, with 32 faces / 360°:
-ToolApply=SetResolution(32);SetUnits(mm);JoinOpenPolylines(120)
Example: Join zero-wdith polylines with a tolerance of 120 mm, and convert arcs, if needed, with a precision of 10 nm:
-ToolApply=SetResolution(10nm);SetUnits(mm);JoinOpenPolylines(120)

AddWidthToPolylines(width)

Adds with to all zero-width polylines.

EraseZeroWidthPolylines()

Deletes all zero-width polylines.

CloseOpenPolylines()

Closes open polylines, and converts them into polygons, by adding a segement from the last to the first vertex.

RemoveDuplicateShapes()

Removes any duplicate shapes

MergeOverlappingPolygons()

Merges overlapping polygons.

DeEmbedPolygons()

De-embeds polygons. Note that you need to specify Explode(All) before de-embedding to include other shapes in this operation.

ExtractHoles(mode)

  • mode is one of Holes|FullNesting.

Extracts holes from polygons onto separate layers. The hole layer will be named after the original layer, with the suffix _neg appended. If such a layer name already exists, _neg1 will be used, where the number is increased as needed.

Modes:

  • Holes: Extracts only holes onto separate layers
  • FullNesting: Extracts polygons nested inside another polygon's hole onto yet another layer. That polygon's holes are then again extracted onto another layer, and so on.

Note that you need to specify Explode(All) before extracting holes to include other shapes in this operation.

FlattenHierarchy()

Flattens the main cell structure hierarchy. Tools such as DeEmbedPolygons() only perform on a per-cell basis, so prior flattening may be desired.

SanitizePolygons()

Forces clock-wise orientation for all polygons

DetectArcSegmentsRel(min_vertices,error_margin)

Where

  • min_vertices is the minimum number of consecutive vertices that may be converted to an arc segment;
  • error_margin defines the relative allowable error, as follows:

An error_margin of 1.0 means that all “n” vertices of the segment are within a distance “s” of the ideal arc, where “s” is maximum distance between an ideal arc and a polygonal arc with “n” vertices. If you set the margin to 2, then that distance “s” may be twice as large (the actual influence is more complex - the algorithm tests many criteria, such as continuous derivation, maximum cord length, standard deviation, …).

A value of 1.0 provides a tight arc fit (or no arc at all, if tight fitting is not possible), whereas large values of “s” (2 or 3) will include more vertices in any given arc with a looser fit. Values above 3 result in large deviations, so use with care. A good compromise is 1.5.

Note that the min_vertices may prevent some segments to be converted, as they don't have enough vertices. When using a close fit, you may want to set the minimum vertices to a lower value to enable conversion of even small polygonal arc segments. For a large error margin, a large number of minimum vertices is desirable to avoid smoothing the shape even further.

DetectArcSegmentsAbs(min_vertices,max_error)

Where

  • min_vertices is the minimum number of consecutive vertices that may be converted to an arc segment;
  • max_error defines the absolute allowable error, expressed in the units specifies using SetUnits.
Note that the min_vertices may prevent some segments to be converted, as they don't have enough vertices. When using a close fit, you may want to set the minimum vertices to a lower value to enable conversion of even small polygonal arc segments. For a large error margin, a large number of minimum vertices is desirable to avoid smoothing the shape even further.