Draft PathArray: Difference between revisions

From FreeCAD Documentation
(Code signature more complete)
(Code more complete)
Line 57: Line 57:
</translate>
</translate>
{{Code|code=
{{Code|code=
makePathArray(shapeobject, pathobject, count, [translationvector], [alignment], [listofpathsubelements])

PathArray = makePathArray(baseobject, pathobject, count, xlate=None, align=False, pathobjsubs=[])
PathArray = makePathArray(baseobject, pathobject, count, xlate=None, align=False, pathobjsubs=[])
}}
}}
<translate>
<translate>
<!--T:12-->
<!--T:12-->
* Create a {{incode|PathArray}} object from the {{incode|baseobject}}, by placing as many as {{incode|count}} copies along {{incode|pathobject}}.
* Create
** If {{incode|pathobjsubs}} is given, it is a list of sub-objects of {{incode|pathobject}}, and the copies are created along this shorter path.

* If {{incode|xlate}} is given, it is a {{incode|FreeCAD.Vector}} that indicates an additional displacement to move the base point of the copies.
* Distribute count copies of a document shapeobject along a pathobject or subobjects of a pathobject. Optionally translates each copy by FreeCAD.Vector xlate direction and distance to adjust for difference in shape centre vs shape reference point. Optionally aligns baseobject to tangent/normal/binormal of path.
* If {{incode|align}} is {{incode|True}} the copies are aligned to the tangent, normal or binormal of the {{incode|pathobject}} at the point where the copy is placed.


<!--T:13-->
<!--T:13-->
Line 72: Line 71:
{{Code|code=
{{Code|code=
import FreeCAD,Draft
import FreeCAD,Draft

Draft.makePathArray(base,path,items,centretrans,orient,pathsubs)
p1 = FreeCAD.Vector(500, -1000, 0)
p2 = FreeCAD.Vector(1500, 1000, 0)
p3 = FreeCAD.Vector(3000, 500, 0)
p4 = FreeCAD.Vector(4500, 100, 0)
spline = Draft.makeBSpline([p1, p2, p3, p4])
object = Draft.makePolygon(3, 500)

PathArray = Draft.makePathArray(object, spline, 6)
}}
}}
<translate>
<translate>

Revision as of 19:01, 15 November 2018

Draft PathArray

Menu location
Draft → PathArray
Workbenches
Draft, Arch
Default shortcut
None
Introduced in version
0.14
See also
Draft Array, Draft PointArray

Description

The PathArray tool places copies of a selected shape along a selected path. The path can be a wire or one or more edges.

The shapes can optionally be aligned with the tangent of the path. If required, a translation Vector can be specified to shift the shapes so the centroid is on the path.

How to use

  1. Select an object which you wish to distribute.
  2. Select a path object or some edges along which the object will be distributed.
  3. Press the Draft PathArray button.

The base object should be centred around the origin, even if the path starts somewhere else.

The count, alignment, and position of the copies along the path can be changed after creation by changing its properties.

Options

There are no options for this tool. Either it works with the selected object or not.

Properties

  • DataBase: specifies the object to duplicate in the path.
  • DataPathObj: specifies the path object.
  • DataPathSubs: specifies the sub-elements (edges) of the path object. This property does not yet appear in the property editor.
  • DataCount: specifies the number of copies of the base object.
  • DataAlign: if it is true the copies are aligned to the path; otherwise they are left in their default orientation.
Note: in certain cases the shape will appear flat, in reality it may have moved in the 3D space, so instead of using a flat view, change the view to axonometric.
  • DataXlate: specifies a translation vector (x, y, z) to displace each copy along the path.
Note: when DataAlign is true, the vector is relative to the local tangent, normal or binormal coordinates; otherwise the vector is relative to the global coordinates.

Scripting

See also: Draft API and FreeCAD Scripting Basics.

The PathArray tool can be used in macros and from the Python console by using the following function:

PathArray = makePathArray(baseobject, pathobject, count, xlate=None, align=False, pathobjsubs=[])
  • Create a PathArray object from the baseobject, by placing as many as count copies along pathobject.
    • If pathobjsubs is given, it is a list of sub-objects of pathobject, and the copies are created along this shorter path.
  • If xlate is given, it is a FreeCAD.Vector that indicates an additional displacement to move the base point of the copies.
  • If align is True the copies are aligned to the tangent, normal or binormal of the pathobject at the point where the copy is placed.

Example:

import FreeCAD,Draft

p1 = FreeCAD.Vector(500, -1000, 0)
p2 = FreeCAD.Vector(1500, 1000, 0)
p3 = FreeCAD.Vector(3000, 500, 0)
p4 = FreeCAD.Vector(4500, 100, 0)
spline = Draft.makeBSpline([p1, p2, p3, p4])
object = Draft.makePolygon(3, 500)

PathArray = Draft.makePathArray(object, spline, 6)

Technical Explanation

When "Align = false", PathArray's logic is quite easy to understand.

Align false
Align false

When "Align = true" the logic is a bit harder to grasp:

  1. Construct Frenet coordinate systems on the path (X is tangent, Z is normal, Y is binormal).
  2. Copy the original object to every on-path coordinate system, so that the global origin is matched with the on-path coordinate system origin.

It is much easier to understand with pictures. The following images show how the array is produced, depending on which plane is the path.

XY Plane
XY Plane

Path on XY Plane

XZ Plane
XZ Plane

Path on XZ Plane

YZ Plane
YZ Plane

Path on YZ Plane

The clear advantage of this logic is that as you reorient the path but not the object, the result is consistent - object remains aligned to the path the way it was before reorienting the path.

(Thanks to @DeepSOIC for this explanation)