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.
Source code in onshape_robotics_toolkit\parse.py
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 |
|
fetch_rigid_subassemblies_async(subassembly, key, client, rigid_subassembly_map)
async
¶
Fetch rigid subassemblies asynchronously.
Source code in onshape_robotics_toolkit\parse.py
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
|
get_instances(assembly, max_depth=0)
¶
Optimized synchronous wrapper for get_instances
.
Source code in onshape_robotics_toolkit\parse.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
|
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 5 |
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
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 |
|
get_mates_and_relations(assembly, subassemblies, rigid_subassemblies, id_to_name_map, parts)
¶
Synchronous wrapper for get_mates_and_relations_async
.
Source code in onshape_robotics_toolkit\parse.py
560 561 562 563 564 565 566 567 568 569 570 571 572 |
|
get_mates_and_relations_async(assembly, subassemblies, rigid_subassemblies, id_to_name_map, parts)
async
¶
Asynchronously get mates and relations.
Source code in onshape_robotics_toolkit\parse.py
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 |
|
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
371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 |
|
get_occurrences(assembly, id_to_name_map, max_depth=0)
¶
Optimized occurrences fetching using comprehensions.
Source code in onshape_robotics_toolkit\parse.py
192 193 194 195 196 197 198 199 200 201 202 |
|
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
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 |
|
get_subassemblies(assembly, client, instances)
¶
Synchronous wrapper for get_subassemblies_async
.
Source code in onshape_robotics_toolkit\parse.py
269 270 271 272 273 274 275 276 277 |
|
get_subassemblies_async(assembly, client, instance_map)
async
¶
Asynchronously fetch subassemblies.
Source code in onshape_robotics_toolkit\parse.py
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 |
|
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
393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 |
|
process_features_async(features, parts, id_to_name_map, rigid_subassembly_occurrence_map, rigid_subassemblies, subassembly_prefix)
async
¶
Process assembly features asynchronously.
Source code in onshape_robotics_toolkit\parse.py
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 |
|
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.
Source code in onshape_robotics_toolkit\parse.py
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 |
|