Skip to content

Commit 2731a84

Browse files
[API-482] Improved dimension controller and added a code snippet
1 parent b4bf87c commit 2731a84

File tree

2 files changed

+36
-10
lines changed

2 files changed

+36
-10
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "cwapi3d"
3-
version = "32.300.0"
3+
version = "32.301.0"
44
authors = [{ name = "Cadwork", email = "it@cadwork.ca" }]
55
requires-python = ">= 3.12"
66
description = 'Python bindings for CwAPI3D'

src/dimension_controller/__init__.pyi

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,37 @@ from cadwork.dimension_base_format import dimension_base_format
44
from cadwork.api_types import *
55

66
def create_dimension(xl: point_3d, plane_normal: point_3d, distance: point_3d, dimension_points: List[point_3d]) -> ElementId:
7-
"""Creates a dimension element.
8-
9-
Parameters:
10-
xl: The x direction of the dimension.
11-
plane_normal: The normal vector of the dimension plane.
12-
distance: The distance vector from the anchor point to the dimension reference point.
13-
dimension_points: A list of dimension points.
7+
"""Creates a dimension element to measure distances on 3D parts.
8+
The dimension is drawn on a plane
9+
defined by its normal and offset distance. Points added to the dimension are projected
10+
onto this plane, and dimension segments are automatically created between consecutive points.
11+
12+
Parameters:
13+
xl: The direction vector defining the dimension line axis (the direction of the measurement arrow). Can be aligned with X, Y, Z axes or any 3D direction.
14+
plane_normal: The normal vector defining the orientation of the dimension plane.
15+
distance: The offset vector from the dimensioned geometry to where the dimension line is drawn. Can offset in any direction.
16+
dimension_points: A list of dimension points to measure. At least 2 points are needed for a valid dimension measurement, but the points can be added later using addSegment(). Points are projected onto the dimension plane.
17+
18+
Examples:
19+
>>> import cadwork
20+
>>> import dimension_controller as dc
21+
22+
>>> # Create a list of dimension points
23+
>>> list_points = []
24+
>>> list_points.append(cadwork.point_3d(0., 0., 0.))
25+
>>> list_points.append(cadwork.point_3d(1000., 0., 0.))
26+
>>> list_points.append(cadwork.point_3d(2000., 500., 0.))
27+
>>> list_points.append(cadwork.point_3d(3000., 200., 0.))
28+
>>> list_points.append(cadwork.point_3d(4000., 360., 0.))
29+
>>> list_points.append(cadwork.point_3d(6000., 451., 0.))
30+
31+
>>> # Create the dimension element
32+
>>> id_dimension = dc.create_dimension(
33+
>>> cadwork.point_3d(1., 0., 0.), # xl - dimension arrow direction
34+
>>> cadwork.point_3d(0., 1., 0.), # plane_normal
35+
>>> cadwork.point_3d(0., 0., 500.), # distance - offset from geometry
36+
>>> list_points # dimension_points
37+
>>> )
1438
1539
Returns:
1640
The element id of the created dimension element.
@@ -26,11 +50,13 @@ def set_orientation(element_id_list: List[ElementId], view_dir: point_3d, view_d
2650
"""
2751

2852
def add_segment(element_id: ElementId, segment: point_3d) -> None:
29-
"""Adds a segment to a dimension element.
53+
"""Adds a new point to a dimension's point list. A dimension segment is automatically
54+
created between this point and the previous point. This method can be called multiple times
55+
to progressively add more measurement points to the dimension.
3056
3157
Parameters:
3258
element_id: The element id.
33-
segment: The segment to add.
59+
segment: The point to add to the dimension (despite the parameter name, this is a point, not a segment).
3460
"""
3561

3662
def set_precision(element_id_list: List[ElementId], precision: UnsignedInt) -> None:

0 commit comments

Comments
 (0)