forked from evereux/pycatia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_012.py
86 lines (61 loc) · 2.9 KB
/
example_012.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#! /usr/bin/python3.7
"""
Example 12:
Access the CATIA COM object with a .CATPart open and and display
each parameter along with its name, value and its associated parameter set.
# todo: need to create a source part to support this example.
"""
from pycatia import catia
# from pycatia.knowledge_interfaces import BoolParam
caa = catia()
documents = caa.documents
documents.open(r'tests/cat_files/part_measurable.CATPart')
document = caa.active_document
part = document.part()
# gets part parameters
part_parameters = part.parameters
# create parameter to activate pocket
part_parameters.create_boolean("Activate_Pocket", True)
# find and assign parameters
pocket_activity = part_parameters.item("Activate_Pocket")
# gets RootParameterSet inside of parameters
root_parameter_set = part_parameters.root_parameter_set
# ParameterSet(name="Parameters")
# gets ParameterSets inside of RootParameterSet
parameter_sets = root_parameter_set.parameter_sets
# gets all parameter sets inside of parameter_sets
sub_parameter_set = parameter_sets.parameter_sets
# [ParameterSet(name="Parameters_Pad"), ParameterSet(name="Parameters_Pocket")]
for parm_set in sub_parameter_set:
print(parm_set.name)
sub_parms = parm_set.all_parameters
for sub_item in sub_parms:
print(sub_item)
print("Parameter name: {} - Value: {}".format(sub_item.name, sub_item.value))
print()
# ParameterSet name: Parameters_Pad
# Parameter name: CF_Part_3\Parameters_Pad\Width| value: 120.0
# Parameter name: CF_Part_3\Parameters_Pad\Length| value: 60.0
# Parameter name: CF_Part_3\Parameters_Pad\Height| value: 10.0
# ParameterSet name: Parameters_Pocket
# Parameter name: CF_Part_3\Parameters_Pocket\Width| value: 30.0
# Parameter name: CF_Part_3\Parameters_Pocket\Length| value: 15.0
# Parameter name: CF_Part_3\Parameters_Pocket\Height| value: 10.0
# -----------------------------------------------------------------
# gets part relations
part_relations = part.relations
# create the parameter to which you want to assign a formula
sketch_pocket_activity = part_parameters.item("Sketches\\Sketch_Pocket\\Activity")
object_pocket_activity = part_parameters.item("PartBody\\Pocket.1\\Activity")
# create the formula to combine the sketch and pocket activity with the parameter <pocket_activity>
part_relations.create_formula("Activity_Sketch_Pocket",
"Checks weather the Pocket should be activated or not", sketch_pocket_activity,
pocket_activity.name)
part_relations.create_formula("Activity_Object_Pocket",
"Checks weather the Pocket should be activated or not", object_pocket_activity,
pocket_activity.name)
part.update()
# remove created formula
# -----------------------------------------------------------------
# part_relations.remove("Activity_Sketch_Pocket")
# part_relations.remove("Activity_Object_Pocket")