Parse
This module contains functions that provide a way to traverse the assembly structure, extract information about parts, subassemblies, instances, and mates, and generate a hierarchical representation of the assembly.
build_rigid_subassembly_occurrence_map(rigid_subassemblies, id_to_name_map, parts)
async
¶
Asynchronously build a map of rigid subassembly occurrences.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rigid_subassemblies
|
dict[str, RootAssembly]
|
Mapping of instance IDs to rigid subassemblies. |
required |
id_to_name_map
|
dict[str, str]
|
A dictionary mapping instance IDs to their sanitized names. |
required |
parts
|
dict[str, Part]
|
A dictionary mapping instance IDs to their corresponding parts. |
required |
Returns:
Type | Description |
---|---|
dict[str, dict[str, Occurrence]]
|
A dictionary mapping occurrence paths to their corresponding occurrences. |
Source code in onshape_robotics_toolkit\parse.py
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 |
|
fetch_rigid_subassemblies_async(subassembly, key, client, rigid_subassembly_map)
async
¶
Fetch rigid subassemblies asynchronously.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
subassembly
|
SubAssembly
|
The subassembly to fetch. |
required |
key
|
str
|
The instance key to fetch. |
required |
client
|
Client
|
The client object to use for fetching the subassembly. |
required |
rigid_subassembly_map
|
dict[str, RootAssembly]
|
A dictionary to store the fetched subassemblies. |
required |
Source code in onshape_robotics_toolkit\parse.py
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 |
|
get_instances(assembly, max_depth=0)
¶
Optimized synchronous wrapper for get_instances
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
assembly
|
Assembly
|
The assembly object to traverse. |
required |
max_depth
|
int
|
The maximum depth to traverse. |
0
|
Returns:
Type | Description |
---|---|
dict[str, Union[PartInstance, AssemblyInstance]]
|
A tuple containing: |
dict[str, Occurrence]
|
|
dict[str, str]
|
|
Source code in onshape_robotics_toolkit\parse.py
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 |
|
get_instances_sync(assembly, max_depth=0)
¶
Get instances and their sanitized names from an Onshape assembly.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
assembly
|
Assembly
|
The Onshape assembly object to use for extracting instances. |
required |
max_depth
|
int
|
Maximum depth to traverse in the assembly hierarchy. Default is 0 |
0
|
Returns:
Type | Description |
---|---|
dict[str, Union[PartInstance, AssemblyInstance]]
|
A tuple containing: |
dict[str, Occurrence]
|
|
dict[str, str]
|
|
Examples:
>>> assembly = Assembly(...)
>>> get_instances(assembly, max_depth=2)
(
{
"part1": PartInstance(...),
"subassembly1": AssemblyInstance(...),
},
{
"part1": "part1",
"subassembly1": "subassembly1",
}
)
Source code in onshape_robotics_toolkit\parse.py
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 |
|
get_mates_and_relations(assembly, subassemblies, rigid_subassemblies, id_to_name_map, parts)
¶
Synchronous wrapper for get_mates_and_relations_async
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
assembly
|
Assembly
|
The assembly object to traverse. |
required |
subassemblies
|
dict[str, SubAssembly]
|
A dictionary mapping instance IDs to their corresponding subassemblies. |
required |
rigid_subassemblies
|
dict[str, RootAssembly]
|
Mapping of instance IDs to rigid subassemblies. |
required |
id_to_name_map
|
dict[str, str]
|
A dictionary mapping instance IDs to their sanitized names. |
required |
parts
|
dict[str, Part]
|
A dictionary mapping instance IDs to their corresponding parts. |
required |
Returns:
Type | Description |
---|---|
dict[str, MateFeatureData]
|
A tuple containing: |
dict[str, MateRelationFeatureData]
|
|
tuple[dict[str, MateFeatureData], dict[str, MateRelationFeatureData]]
|
|
Source code in onshape_robotics_toolkit\parse.py
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 |
|
get_mates_and_relations_async(assembly, subassemblies, rigid_subassemblies, id_to_name_map, parts)
async
¶
Asynchronously get mates and relations.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
assembly
|
Assembly
|
The assembly object to traverse. |
required |
subassemblies
|
dict[str, SubAssembly]
|
A dictionary mapping instance IDs to their corresponding subassemblies. |
required |
rigid_subassemblies
|
dict[str, RootAssembly]
|
Mapping of instance IDs to rigid subassemblies. |
required |
id_to_name_map
|
dict[str, str]
|
A dictionary mapping instance IDs to their sanitized names. |
required |
parts
|
dict[str, Part]
|
A dictionary mapping instance IDs to their corresponding parts. |
required |
Returns:
Type | Description |
---|---|
dict[str, MateFeatureData]
|
A tuple containing: |
dict[str, MateRelationFeatureData]
|
|
tuple[dict[str, MateFeatureData], dict[str, MateRelationFeatureData]]
|
|
Source code in onshape_robotics_toolkit\parse.py
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 |
|
get_occurrence_name(occurrences, subassembly_prefix=None)
¶
Get the mapping name for an occurrence path.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
occurrences
|
list[str]
|
Occurrence path. |
required |
subassembly_prefix
|
Optional[str]
|
Prefix for the subassembly. |
None
|
Returns:
Type | Description |
---|---|
str
|
The mapping name. |
Examples:
>>> get_occurrence_name(["subassembly1", "part1"], "subassembly1")
"subassembly1-SUB-part1"
>>> get_occurrence_name(["part1"], "subassembly1")
"subassembly1-SUB-part1"
Source code in onshape_robotics_toolkit\parse.py
420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 |
|
get_occurrences(assembly, id_to_name_map, max_depth=0)
¶
Optimized occurrences fetching using comprehensions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
assembly
|
Assembly
|
The assembly object to traverse. |
required |
id_to_name_map
|
dict[str, str]
|
A dictionary mapping instance IDs to their sanitized names. |
required |
max_depth
|
int
|
The maximum depth to traverse. Default is 0 |
0
|
Returns:
Type | Description |
---|---|
dict[str, Occurrence]
|
A dictionary mapping occurrence paths to their corresponding occurrences. |
Source code in onshape_robotics_toolkit\parse.py
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
|
get_parts(assembly, rigid_subassemblies, client, instances)
¶
Get parts of an Onshape assembly.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
assembly
|
Assembly
|
The Onshape assembly object to use for extracting parts. |
required |
rigid_subassemblies
|
dict[str, RootAssembly]
|
Mapping of instance IDs to rigid subassemblies. |
required |
client
|
Client
|
The Onshape client object to use for sending API requests. |
required |
instances
|
dict[str, Union[PartInstance, AssemblyInstance]]
|
Mapping of instance IDs to their corresponding instances. |
required |
Returns:
Type | Description |
---|---|
dict[str, Part]
|
A dictionary mapping part IDs to their corresponding part objects. |
Source code in onshape_robotics_toolkit\parse.py
399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 |
|
get_subassemblies(assembly, client, instances)
¶
Synchronous wrapper for get_subassemblies_async
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
assembly
|
Assembly
|
The assembly object to traverse. |
required |
client
|
Client
|
The client object to use for fetching the subassemblies. |
required |
instances
|
dict[str, Union[PartInstance, AssemblyInstance]]
|
A dictionary mapping instance IDs to their corresponding instances. |
required |
Returns:
Type | Description |
---|---|
dict[str, SubAssembly]
|
A tuple containing: |
dict[str, RootAssembly]
|
|
tuple[dict[str, SubAssembly], dict[str, RootAssembly]]
|
|
Source code in onshape_robotics_toolkit\parse.py
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 |
|
get_subassemblies_async(assembly, client, instance_map)
async
¶
Asynchronously fetch subassemblies.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
assembly
|
Assembly
|
The assembly object to traverse. |
required |
client
|
Client
|
The client object to use for fetching the subassemblies. |
required |
instance_map
|
dict[str, Union[PartInstance, AssemblyInstance]]
|
A dictionary mapping instance IDs to their corresponding instances. |
required |
Returns:
Type | Description |
---|---|
dict[str, SubAssembly]
|
A tuple containing: |
dict[str, RootAssembly]
|
|
tuple[dict[str, SubAssembly], dict[str, RootAssembly]]
|
|
Source code in onshape_robotics_toolkit\parse.py
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 |
|
join_mate_occurrences(parent, child, prefix=None)
¶
Join two occurrence paths with a mate joiner.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
parent
|
list[str]
|
Occurrence path of the parent entity. |
required |
child
|
list[str]
|
Occurrence path of the child entity. |
required |
prefix
|
Optional[str]
|
Prefix to add to the occurrence path. |
None
|
Returns:
Type | Description |
---|---|
str
|
The joined occurrence path. |
Examples:
>>> join_mate_occurrences(["subassembly1", "part1"], ["subassembly2"])
"subassembly1-SUB-part1-MATE-subassembly2"
>>> join_mate_occurrences(["part1"], ["part2"])
"part1-MATE-part2"
Source code in onshape_robotics_toolkit\parse.py
442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 |
|
process_features_async(features, parts, id_to_name_map, rigid_subassembly_occurrence_map, rigid_subassemblies, subassembly_prefix)
async
¶
Process assembly features asynchronously.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
features
|
list[AssemblyFeature]
|
The assembly features to process. |
required |
parts
|
dict[str, Part]
|
A dictionary mapping instance IDs to their corresponding parts. |
required |
id_to_name_map
|
dict[str, str]
|
A dictionary mapping instance IDs to their sanitized names. |
required |
rigid_subassembly_occurrence_map
|
dict[str, dict[str, Occurrence]]
|
A dictionary mapping occurrence paths to their corresponding occurrences. |
required |
rigid_subassemblies
|
dict[str, RootAssembly]
|
Mapping of instance IDs to rigid subassemblies. |
required |
subassembly_prefix
|
Optional[str]
|
The prefix for the subassembly. |
required |
Returns:
Type | Description |
---|---|
dict[str, MateFeatureData]
|
A tuple containing: |
dict[str, MateRelationFeatureData]
|
|
tuple[dict[str, MateFeatureData], dict[str, MateRelationFeatureData]]
|
|
Source code in onshape_robotics_toolkit\parse.py
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 |
|
traverse_instances_async(root, prefix, current_depth, max_depth, assembly, id_to_name_map, instance_map)
async
¶
Asynchronously traverse the assembly structure to get instances.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
root
|
Union[RootAssembly, SubAssembly]
|
The root assembly or subassembly to traverse. |
required |
prefix
|
str
|
The prefix for the instance ID. |
required |
current_depth
|
int
|
The current depth in the assembly hierarchy. |
required |
max_depth
|
int
|
The maximum depth to traverse. |
required |
assembly
|
Assembly
|
The assembly object to traverse. |
required |
id_to_name_map
|
dict[str, str]
|
A dictionary mapping instance IDs to their sanitized names. |
required |
instance_map
|
dict[str, Union[PartInstance, AssemblyInstance]]
|
A dictionary mapping instance IDs to their corresponding instances. |
required |
Source code in onshape_robotics_toolkit\parse.py
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 |
|