-
Notifications
You must be signed in to change notification settings - Fork 4
/
feature.py
executable file
·714 lines (633 loc) · 21.7 KB
/
feature.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
"""Feature module."""
STATUS_LIST = [
"ACTIVE",
"INACTIVE",
"FAMILY_TABLE_SUPPRESSED",
"SIMP_REP_SUPPRESSED",
"PROGRAM_SUPPRESSED",
"SUPPRESSED",
"UNREGENERATED",
]
def delete(client, name=None, file_=None, status=None, type_=None, clip=None):
"""Delete one or more features that match criteria.
Args:
client (obj):
creopyson Client.
name (str|list:str, optional):
Dimension name, (wildcards allowed: True);
if empty then all features are listed.
`file_` (str, optional):
Model name (wildcards allowed: True).
Defaults is current active model.
status (str, optional):
Feature status pattern (wildcards allowed: True).
Defaults: All feature statuses.
Valid values: ACTIVE, INACTIVE, FAMILY_TABLE_SUPPRESSED,
SIMP_REP_SUPPRESSED, PROGRAM_SUPPRESSED, SUPPRESSED, UNREGENERATED
`type_` (str, optional):
Feature type pattern (wildcards allowed: True).
Defaults: All feature types.
clip (boolean, optional):
Whether to clip-delete ANY features from this feature through
the end of the structure.
Defaults is False.
Raises:
ValueError: status value is incorrect.
Returns:
None
"""
data = {}
if file_ is not None:
data["file"] = file_
else:
active_file = client.file_get_active()
if active_file:
data["file"] = active_file["file"]
if name:
if isinstance(name, (str)):
data["name"] = name
elif isinstance(name, (list)):
data["names"] = name
if status in STATUS_LIST:
data["status"] = status
elif status is not None:
raise ValueError(f"`{status}` is not a correct status.")
if type_:
data["type"] = type_
if clip:
data["clip"] = clip
return client._creoson_post("feature", "delete", data)
def delete_param(client, name=None, file_=None, param=None):
"""Delete a feature parameter.
Args:
client (obj):
creopyson Client.
name (str, optional):
Parameter name (wildcards allowed: True).
Defaults: All parameter names.
`file_` (str, optional):
Model name. Defaults is current active model.
param (str, optional):
Parameter name (wildcards allowed: True).
Defaults: All parameter names.
Returns:
None
"""
data = {}
if file_ is not None:
data["file"] = file_
else:
active_file = client.file_get_active()
if active_file:
data["file"] = active_file["file"]
if name:
data["name"] = name
if param:
data["param"] = param
return client._creoson_post("feature", "delete_param", data)
def list_(
client,
file_=None,
name=None,
status=None,
type_=None,
paths=None,
no_datum=None,
inc_unnamed=None,
no_comp=None,
):
"""List feature parameters that match criteria.
Will only list parameters on visible features.
Args:
client (obj):
creopyson Client.
`file_` (str, optional):
File name. Defaults is the currently active model.
name (str, optional):
Feature name (wildcards allowed: True).
Defaults: All features are listed.
status (str, optionnal):
Feature status pattern.
Defaults: All feature statuses.
Valid values: ACTIVE, INACTIVE, FAMILY_TABLE_SUPPRESSED,
SIMP_REP_SUPPRESSED, PROGRAM_SUPPRESSED, SUPPRESSED, UNREGENERATED.
`type_` (str, optional):
Feature type patter (wildcards allowed: True).
Defaults: All feature types.
paths (boolean, optionnal):
Whether feature ID and feature number are returned with the data
Default: False.
no_datum (boolean, optional):
Whether to exclude datum-type features from the list;
these are COORD_SYS, CURVE, DATUM_AXIS, DATUM_PLANE, DATUM_POINT,
DATUM_QUILT, and DATUM_SURFACE features.
Defaults is False.
inc_unnamed (boolean, optional):
Whether to include unnamed features in the list.
Defaults is False.
no_comp (boolean, optional):
Whether to include component-type features in the list.
Defaults is False.
Raises:
ValueError: status value is incorrect.
Returns:
(list:dict): List of parameter information.
name (str):
Parameter nam.
value (depends on data type):
Parameter value.
type (string):
Data type. Valid values: STRING, DOUBLE, INTEGER, BOOL, NOTE.
designate (boolean):
Value is designated.
encoded (boolean):
Value is Base64-encoded.
owner_name (str):
Owner Name.
owner_id (int):
Owner ID.
owner_type (str):
Owner type.
"""
data = {}
if file_ is not None:
data["file"] = file_
else:
active_file = client.file_get_active()
if active_file:
data["file"] = active_file["file"]
if name:
data["name"] = name
if status in STATUS_LIST:
data["status"] = status
elif status is not None:
raise ValueError(f"`{status}` is not a correct status.")
if type_:
data["type"] = type_
if paths:
data["paths"] = paths
if no_datum:
data["no_datum"] = no_datum
if inc_unnamed:
data["inc_unnamed"] = inc_unnamed
if no_comp:
data["no_comp"] = no_comp
return client._creoson_post("feature", "list", data, "featlist")
def list_params(
client,
file_=None,
name=None,
type_=None,
no_datum=None,
inc_unnamed=None,
no_comp=None,
param=None,
value=None,
encoded=None,
):
"""List feature parameters that match criteria.
Args:
client (obj):
creopyson Client.
`file_` (str, optional):
File name. Defaults is the currently active model.
name (str|int, optional):
str: Feature name (wildcards allowed: True).
int: Feature ID.
Defaults: All features are listed.
`type_` (str, optional):
Feature type patter (wildcards allowed: True).
Defaults: All feature types.
no_datum (boolean, optional):
Whether to exclude datum-type features from the list;
these are COORD_SYS, CURVE, DATUM_AXIS, DATUM_PLANE, DATUM_POINT,
DATUM_QUILT, and DATUM_SURFACE features.
Defaults is False.
inc_unnamed (boolean, optional):
Whether to include unnamed features in the list.
Defaults is False.
no_comp (boolean, optional):
Whether to include component-type features in the list.
Defaults is False.
param (str|list:str, optional):
Parameter name; (wildcards allowed: True)
if empty all parameters are listed.
value (str, optional):
Parameter value filter (wildcards allowed: True).
Defaults is no filter.
encoded (boolean, optional):
Whether to return the values Base64-encoded.
Defaults is False.
Returns:
(list:dict): List of parameter information.
name (str):
Parameter nam.
value (depends on data type):
Parameter value.
type (string):
Data type. Valid values: STRING, DOUBLE, INTEGER, BOOL, NOTE.
designate (boolean):
Value is designated.
encoded (boolean):
Value is Base64-encoded.
owner_name (str):
Owner Name.
owner_id (int):
Owner ID.
owner_type (str):
Owner type.
description (str):
List of parameter information.
"""
data = {}
if file_ is not None:
data["file"] = file_
else:
active_file = client.file_get_active()
if active_file:
data["file"] = active_file["file"]
if name:
if isinstance(param, (str)):
data["name"] = name
elif isinstance(param, (list)):
data["feat_id"] = name
if type_:
data["type"] = type_
if no_datum:
data["no_datum"] = no_datum
if inc_unnamed:
data["inc_unnamed"] = inc_unnamed
if no_comp:
data["no_comp"] = no_comp
if param:
if isinstance(param, (str)):
data["param"] = param
elif isinstance(param, (list)):
data["params"] = param
if value:
data["value"] = value
if encoded:
data["encoded"] = encoded
return client._creoson_post("feature", "list_params", data, "paramlist")
def list_group_features(client, group_name, type_=None, file_=None):
"""List features in a Creo Group.
Args:
client (obj):
creopyson Client.
group_name (str):
Group name.
`type_` (str, optional):
Feature type patter (wildcards allowed: True).
Defaults: All feature types.
`file_` (str, optional):
File name. Defaults is the currently active model.
Returns:
(list:dict): List of feature information
"""
data = {
"group_name": group_name,
}
if file_ is not None:
data["file"] = file_
else:
active_file = client.file_get_active()
if active_file:
data["file"] = active_file["file"]
if type_:
data["type"] = type_
return client._creoson_post("feature", "list_group_features", data, "featlist")
def list_pattern_features(client, patter_name, type_=None, file_=None):
"""List features in a Creo Pattern.
Args:
client (obj):
creopyson Client.
patter_name (str):
Pattern name.
`type_` (str, optional):
Feature type patter (wildcards allowed: True).
Defaults: All feature types.
`file_` (str, optional):
File name. Defaults is the currently active model.
Returns:
(list:dict): List of feature information
"""
data = {
"patter_name": patter_name,
}
if file_ is not None:
data["file"] = file_
else:
active_file = client.file_get_active()
if active_file:
data["file"] = active_file["file"]
if type_:
data["type"] = type_
return client._creoson_post("feature", "list_group_features", data, "featlist")
def list_selected(client):
"""List the currently selected features in Creo
Returns:
(list): List of feature informations.
[
{
'file' : model name (str)
'name' : feature name (str)
'status' : feature status (str)
'type' : feature type (str)
'feat_id' : feature ID (int)
'feat_number' : feature number (int)
'path' : feature's component path (list of ints)
},
]
"""
data = None
return client._creoson_post("feature", "list_selected", data, "featlist")
def param_exists(client, file_=None, name=None, param=None):
"""Check whether parameter(s) exists on a feature.
Args:
client (obj):
creopyson Client.
`file_` (str, optional):
File name. Defaults is the currently active model.
name (str, optional):
Parameter name (wildcards allowed: True).
Defaults: All parameter names.
param (str|list:str, optional):
Parameter name; (wildcards allowed: True)
if empty all parameters are listed.
Returns:
(boolean): Whether the parameter exists on the model
"""
data = {}
if file_ is not None:
data["file"] = file_
else:
active_file = client.file_get_active()
if active_file:
data["file"] = active_file["file"]
if name:
data["name"] = name
if param:
if isinstance(param, (str)):
data["param"] = param
elif isinstance(param, (list)):
data["params"] = param
return client._creoson_post("feature", "param_exists", data, "exists")
def rename(client, name, new_name, file_=None):
"""Rename a feature.
Args:
client (obj):
creopyson Client.
name (str|int, optional):
Feature name (str) or Feature ID (int).
new_name (str):
New name for the feature.
`file_` (str, optional):
File name.
Defaults is the currently active model.
Returns:
None
"""
data = {"new_name": new_name}
if file_ is not None:
data["file"] = file_
else:
active_file = client.file_get_active()
if active_file:
data["file"] = active_file["file"]
if isinstance(name, (str)):
data["name"] = name
elif isinstance(name, (int)):
data["feat_id"] = name
else:
raise TypeError("name must be str or int")
return client._creoson_post("feature", "rename", data)
def resume(client, file_=None, name=None, status=None, type_=None, with_children=None):
"""Resume one or more features that match criteria.
Will only resume visible features.
Args:
client (obj):
creopyson Client.
`file_` (str, optional):
File name (wildcards allowed: True).
Defaults is the currently active model.
name (int|str|list:str, optional):
Feature name or Feature ID, (wildcards allowed: True);
if empty then all features are resumed.
int => Feat_ID
str => name
list:str => names
status (str, optional):
Feature status pattern. Defaults: All feature statuses.
Valid values: ACTIVE, INACTIVE, FAMILY_TABLE_SUPPRESSED,
SIMP_REP_SUPPRESSED, PROGRAM_SUPPRESSED, SUPPRESSED, UNREGENERATED
`type_` (str, optional):
Feature type pattern (wildcards allowed: True).
Defaults: All feature types.
with_children (boolean, optional):
Whether to resume any child features of the resumed feature.
Defaults is False.
Raises:
ValueError: status value is incorrect.
Returns:
None
"""
data = {
"with_children": False,
}
if file_ is not None:
data["file"] = file_
else:
active_file = client.file_get_active()
if active_file:
data["file"] = active_file["file"]
if name:
if isinstance(name, (int)):
data["feat_id"] = name
elif isinstance(name, (str)):
data["name"] = name
elif isinstance(name, (list)):
data["names"] = name
if status in STATUS_LIST:
data["status"] = status
elif status is not None:
raise ValueError(f"`{status}` is not a correct status.")
if type_:
data["type"] = type_
if with_children:
data["with_children"] = with_children
return client._creoson_post("feature", "resume", data)
def set_param(
client,
param,
file_=None,
name=None,
type_=None,
value=None,
encoded=None,
designate=None,
description=None,
no_create=None,
):
"""Set the value of a feature parameter.
Will only set parameters on visible features.
Args:
client (obj):
creopyson Client.
param (str):
Parameter name.
`file_` (str, optional):
File name (wildcards allowed: True).
Defaults is the currently active model.
name (str, optional):
Feature name. Defaults: All features are updated.
`type_` (str, optional):
Parameter data type. Defaults is True.
Valid values: STRING, DOUBLE, INTEGER, BOOL, NOTE.
value (depends on data type, optional):
Parameter value. Defaults: Clears the parameter value if missing.
encoded (boolean, optional):
Value is Base64-encoded. Defaults is False.
designate (boolean, optional):
Set parameter to be designated/not designated, blank=do not set.
Defaults is `blank`.
description (str, optionnal):
Parameter description. If missing, leaves the currect description in place.
no_create (boolean, optional):
If parameter does not already exist, do not create it.
Defaults is False.
Returns:
None
"""
data = {}
if file_ is not None:
data["file"] = file_
else:
active_file = client.file_get_active()
if active_file:
data["file"] = active_file["file"]
if name:
data["name"] = name
if param:
data["param"] = param
if type_:
data["type"] = type_
if value:
data["value"] = value
if encoded:
data["encoded"] = encoded
if designate:
data["designate"] = designate
if description:
data["description"] = description
if no_create:
data["no_create"] = no_create
return client._creoson_post("feature", "set_param", data)
def suppress(
client,
file_=None,
name=None,
status=None,
type_=None,
clip=None,
with_children=None,
):
"""Suppress one or more features that match criteria.
Will only suppress visible features.
Args:
client (obj):
creopyson Client.
`file_` (str, optional):
File name (wildcards allowed: True).
Defaults is the currently active model.
name (int|str|list:str, optional):
Feature name or Feature ID, (wildcards allowed: True);
if empty then all features are suppressed.
int => Feat_ID
str => name
list:str => names
status (str, optional):
Feature status pattern. Defaults: All feature statuses.
Valid values: ACTIVE, INACTIVE, FAMILY_TABLE_SUPPRESSED,
SIMP_REP_SUPPRESSED, PROGRAM_SUPPRESSED, SUPPRESSED, UNREGENERATED
`type_` (str, optional):
Feature type pattern (wildcards allowed: True).
Defaults: All feature types.
clip (boolean, optional):
Whether to clip-suppress ANY features from this feature through
the end of the structure. Defaults is True.
with_children (boolean, optional):
Whether to suppress any child features of the suppressed feature.
Defaults is True.
Raises:
ValueError: status value is incorrect.
Returns:
None
"""
data = {"clip": True, "with_children": True}
if file_ is not None:
data["file"] = file_
else:
active_file = client.file_get_active()
if active_file:
data["file"] = active_file["file"]
if name:
if isinstance(name, (int)):
data["feat_id"] = name
elif isinstance(name, (str)):
data["name"] = name
elif isinstance(name, (list)):
data["names"] = name
if status in STATUS_LIST:
data["status"] = status
elif status is not None:
raise ValueError(f"`{status}` is not a correct status.")
if type_:
data["type"] = type_
if clip is False:
data["clip"] = False
if with_children is False:
data["with_children"] = False
return client._creoson_post("feature", "suppress", data)
def user_select_csys(client, file_=None, max_=None):
"""Prompt the user to select one or more coordinate systems.
and return their selections.
Args:
client (obj):
creopyson Client.
`file_` (str, optional):
File name.
Defaults is the currently active model.
`max_` (int, optional):
The maximum number of dimensions that the user can select.
Defaults is `1`.
Returns:
(list:dict):
List of feature information.
name (str):
Feature name.
type (string):
Feature type.
status (str):
Feature status.
Valid values: ACTIVE, INACTIVE, FAMILY_TABLE_SUPPRESSED,
SIMP_REP_SUPPRESSED, PROGRAM_SUPPRESSED, SUPPRESSED,
UNREGENERATED.
feat_id (int):
Feature ID.
file (str):
File name containing the feature.
path (list:int):
Component Path to feature (optionnal)
"""
data = {
"max": 1,
}
if file_ is not None:
data["file"] = file_
else:
active_file = client.file_get_active()
if active_file:
data["file"] = active_file["file"]
if max_:
data["max"] = max_
return client._creoson_post("feature", "user_select_csys", data)