overview
pocketknife adds commands that start with pk. Each one works on the selected objects and shows its options on the command line, like any Rhino command. Click an option to change it, then press Enter.
The geometry runs in pure Python 3, on the CPython runtime inside Rhino 8. No other software is needed.
install and first run
- Open Rhino 8 and run
_PackageManager. - Search for pocketknife and install it.
- Restart Rhino.
- Run
pkInfo: it prints the installed version and the commands.
Updates come through the same package manager. To run a command straight from the source code instead, download the repository from GitHub and run _RunPythonScript on a file in its commands folder.
commands
Eleven commands; eight of them are also Grasshopper components (gh).
| command | gh | what it does |
|---|---|---|
pkCleanCurves |
yes | cleans messy curve networks such as Make2D output |
pkClipCurves |
yes | clips curves with closed masks or hatches |
pkRebuildCurves |
yes | rebuilds faceted curves into lines, arcs and light NURBS |
pkFootprint |
yes | outline of many objects on a plane, with real holes |
pkInnerPoint |
yes | a point always inside a shape |
pkMinBoundingBox |
yes | minimum-volume oriented box |
pkMinBoundingRect |
yes | minimum rectangle on XY |
pkOrientToMinRect |
yes | turns objects to follow X or Y |
pkCopyToLayerCopy |
– | copies objects into a copy of their layer tree |
pkLayerColorFromMaterial |
– | layer colour from its material |
pkInfo |
– | opens the docs, prints the version |
pkCleanCurves
Cleans a messy network of planar curves, such as Make2D output. Overlapping and duplicated stretches are drawn once, pieces are joined at their endpoints along the straightest continuation, collinear lines and co-circular arcs merge. A grid becomes long X and Y curves; an outline stays separate from the inner lines that touch it.
| option | effect |
|---|---|
Layers=PerLayer |
curves interact only with curves on the same layer and with the same object colour, linetype and print width (default) |
Layers=All |
all selected curves are cleaned together |
MaxAngle |
maximum deviation from straight, in degrees, for joining where three or more pieces meet (15 by default); two pieces are always joined |
DeleteInput=Yes, No |
replace the input curves (default), or keep them |
The geometry never moves beyond the document tolerance. Non-planar curves are skipped. An input is deleted only once its replacement is added. One undo step.
pkClipCurves
Clips curves with mask shapes, like a clipping mask: curves are cut where they cross the mask boundaries and only the pieces inside, or outside, are kept. Select the curves to clip first, then the masks.
| option | effect |
|---|---|
Keep=Inside |
keeps the pieces inside the masks (default) |
Keep=Outside |
keeps the pieces outside the masks |
DeleteMask=No, Yes |
keep the mask objects (default), or delete them |
Masks are closed planar curves and hatches, all on one plane; masks on different planes stop the command and nothing changes. Nested shapes are holes (even-odd rule). Stretches lying on a mask boundary are always dropped, so the laser never cuts twice; a curve that only touches the boundary is not split. Curves off the mask plane are clipped by their projection and stay where they are. One undo step.
pkRebuildCurves
Rebuilds curves exported badly by Revit, SketchUp or Blender: faceted polylines and over-dense curves. Uniformly faceted runs become true arcs and circles, straight runs become lines, the rest becomes a smooth NURBS with the fewest control points. True corners are kept.
| option | effect |
|---|---|
Tolerance |
maximum distance of every input vertex from the result (document tolerance by default) |
CornerAngle |
turning angle, in degrees, above which a vertex is a corner (45 by default); an octagonal column stays an octagon |
DeleteInput=Yes, No |
replace the input curves (default), or keep them |
Pieces that meet without a corner are tangent. The command line reports the lines, arcs and free curves made and the control points before and after. A curve that cannot be rebuilt is kept as it is. One undo step.
pkFootprint
Draws the outline of the union of many objects seen along a plane: one closed curve per island and per real hole, such as a courtyard, with no inner lines and exact lines, arcs and circles. Made for figure-ground bases of masterplans cut with a laser. Works on breps, extrusions, meshes, SubD and block instances, nested ones too.
| option | effect |
|---|---|
Plane=World |
projects on World XY (default) |
Plane=CPlane |
projects on the construction plane of the active view |
MinArea |
islands and holes with a smaller area are dropped, with everything inside them (0, off, by default) |
GapTolerance |
joins breaks in the outline and closes slits between buildings narrower than this (3 times the document tolerance by default) |
The curves go to the current layer; the input objects never change. Buildings that touch or share walls merge into one region; two buildings touching only at a corner give two curves. A curve that cannot be closed is still added, selected and reported: check the model there, or try another GapTolerance. Mesh outlines stay faceted. One undo step.
pkInnerPoint
Adds a point always inside each object: the pole of inaccessibility of its XY outline, the interior point farthest from the boundary. Accepts closed curves, hatches, surfaces, polysurfaces, extrusions, SubD and meshes. Holes are respected.
| option | effect |
|---|---|
Z=Mid |
Z in the middle of the object along the vertical through the point |
Z=Zero |
the point lies on the XY plane |
Regions=All |
one point for each separate region of the outline |
Regions=Biggest |
one point only, in the largest region |
pkMinBoundingBox
Adds the minimum-volume oriented bounding box of the objects. Slow computations show a warning and a progress bar; press Esc to stop. A flat result becomes a rectangle.
| option | effect |
|---|---|
Accuracy=Fast, Normal, Precise |
number of directions tested before the local refinement |
Group=Yes |
one box for all objects (default) |
Group=No |
one box per object |
pkMinBoundingRect
Draws the minimum bounding rectangle of the objects projected on the XY plane, at Z = 0. Exact for the sampled points; curves are sampled within the document tolerance.
| option | effect |
|---|---|
Metric=Area |
minimizes the area |
Metric=Perimeter |
minimizes the perimeter |
Group=No |
one rectangle per object |
Group=Yes |
one rectangle for all objects |
pkOrientToMinRect
Rotates objects around Z so the long side of their minimum XY rectangle is parallel to X or Y. The smallest rotation is used, never more than 90°.
| option | effect |
|---|---|
Axis=X, Y |
target axis for the long side |
Group=No |
each object rotates around its own rectangle centre |
Group=Yes |
all objects rotate together around the common centre |
pkCopyToLayerCopy
Copies or moves the selected objects into a copy of their layer structure. Only selected objects count: a parent layer holding unselected objects is still a valid container. Existing names get - Copy 2, - Copy 3.
| option | effect |
|---|---|
Parent=No |
each layer is copied next to the original as <name> - Copy |
Parent=Min |
the nearest parent without selected objects becomes the copy; the layers below keep their names |
Parent=Max |
the farthest parent without selected objects becomes the copy; the layers below keep their names |
Copy=Clone |
objects are duplicated; the copies end up selected |
Copy=Cut |
objects are moved |
pkLayerColorFromMaterial
Sets each layer colour to the diffuse colour of the layer material, or the base colour for PBR materials. Layers without a material are skipped and listed on the command line.
| option | effect |
|---|---|
Mode=Default |
only the layer colour changes, so only ByLayer objects change colour |
Mode=Override |
also resets every object on those layers to ByLayer, hidden and locked ones included |
AllLayers=No |
acts on the layers of the selected objects |
AllLayers=Yes |
press Enter to act on every layer |
pkInfo
Opens this page in the default browser and prints the installed version and the loaded pk commands on the command line. No options.
grasshopper
Eight commands are also components, in the Pocket Knife tab, Geometry panel.
| component | inputs | outputs |
|---|---|---|
pkCleanCrv |
curves, max angle | clean curves |
pkClip |
curves, masks, keep outside | kept pieces, index of the source curve |
pkRebuildCrv |
curves, tolerance, corner angle | rebuilt curves, one per input |
pkFootprint |
geometry, plane, min area, gap tolerance | closed curves, curves that could not be closed |
pkInnerPt |
geometry, mid height, biggest only, accuracy 1-6 | points, distance to the outline |
pkMinBox |
geometry, one for all, accuracy 0-2 | boxes, volumes |
pkMinRect |
geometry, one for all, perimeter | rectangles, areas |
pkOrient |
geometry, along Y, all together | rotated geometry, transformations |
The transformations of pkOrient can move other geometry the same way, for example the labels of a part. pkClip returns the index of the source curve of each piece, to carry its data along. pkFootprint shows a warning when some curves could not be closed.
faq
GapTolerance there. The open curve is selected and reported: fix the model at that spot, or run again with a larger tolerance.