Skip to content

Commit 3418deb

Browse files
committed
updated examples that use range on a collection object
1 parent 7342301 commit 3418deb

File tree

4 files changed

+24
-19
lines changed

4 files changed

+24
-19
lines changed

examples/example__hybrid_shape_factory__001.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,14 @@
4949

5050
# create a list of only points.
5151
points = []
52-
for i in range(1, hs_shapes.count + 1):
53-
hybrid_shape = hs_shapes.item(i)
52+
for i in range(len(hs_shapes)):
53+
index = i + 1
54+
hybrid_shape = hs_shapes.item(index)
5455
hybrid_shape_reference = part.create_reference_from_object(hybrid_shape)
5556

5657
# make sure the element is indeed a point.
5758
if hsf.get_geometrical_feature_type(hybrid_shape_reference) == 1:
58-
points.append(hs_shapes.item(i))
59+
points.append(hs_shapes.item(index))
5960

6061
# sequentially rename the points starting from 1.
6162
point_post_fix = 1

examples/example__hybrid_shape_factory__004.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Example - Hybrid Shape Factory - 004
66
77
Description:
8-
Loops through the items in hybrid body "Lines" and determine the object type using selection.
8+
Loops through the items in hybrid body "ConstructionGeometry" and determine the object type using selection.
99
Once determined create an object from it and find it's parent(s).
1010
1111
Requirements:
@@ -41,10 +41,13 @@
4141

4242
hbs = part.hybrid_bodies
4343
hb_construction_lines = hbs.item("ConstructionGeometry")
44-
hss = hb_construction_lines.hybrid_shapes
44+
gs_construction_geometry = hb_construction_lines.hybrid_shapes
4545

46-
for shape_index in range(1, hss.count + 1):
47-
hs = hss.item(shape_index)
46+
for i in range(len(gs_construction_geometry)):
47+
48+
shape_index = i + 1
49+
50+
hs = gs_construction_geometry.item(shape_index)
4851

4952
# clear the selection on each loop.
5053
part_document.selection.clear()
@@ -61,9 +64,9 @@
6164
ref_start_point = hs_line_pt_pt.pt_origin
6265
ref_end_point = hs_line_pt_pt.pt_extremity
6366

64-
start_point = HybridShapePointCoord(hss.item(ref_start_point.display_name).com_object)
65-
end_point = HybridShapePointCoord(hss.item(ref_end_point.display_name).com_object)
67+
start_point = HybridShapePointCoord(gs_construction_geometry.item(ref_start_point.display_name).com_object)
68+
end_point = HybridShapePointCoord(gs_construction_geometry.item(ref_end_point.display_name).com_object)
6669

67-
print(hs_line_pt_pt.name)
68-
print(start_point.name, start_point.get_coordinates())
69-
print(end_point.name, end_point.get_coordinates())
70+
print(f'Line: {hs_line_pt_pt.name}')
71+
print(f'\tStart point: {start_point.name, start_point.get_coordinates()}')
72+
print(f'\tEnd point: end_point.name, end_point.get_coordinates()')

examples/example__material__001.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,19 @@
4444
material_families_list = []
4545
material_list = []
4646

47-
for i in range(1, material_families.count):
48-
family = material_families.item(i)
47+
for i in range(len(material_families)):
48+
index = i + 1
49+
family = material_families.item(index)
4950
material_families_list.append(family)
5051

51-
for i in range(1, materials.count):
52-
material = materials.item(i)
52+
for i in range(len(materials)):
53+
index = i + 1
54+
material = materials.item(index)
5355
material_list.append(material)
5456

5557
print(f"Found {material_families.count} material families: " f"{', '.join([n.name for n in material_families_list])}.")
5658
print(f"Found {materials.count} materials in the first family: " f"{', '.join([n.name for n in material_list])}.")
5759

58-
5960
##########################################################
6061
# MATERIAL MANAGER ON PARTS
6162
##########################################################
@@ -97,7 +98,6 @@
9798
"None" if material_3 is None else material_3.name,
9899
)
99100

100-
101101
##########################################################
102102
# MATERIAL MANAGER ON PRODUCTS
103103
##########################################################

examples/example__visual_properties__001.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333

3434
# to loop through the items
3535
for i in range(selection.count2):
36-
item = selection.item2(i + 1)
36+
index = i + 1
37+
item = selection.item2(i + index)
3738
type = item.type
3839
value = item.value
3940
reference = item.reference

0 commit comments

Comments
 (0)