Element
This module defines data model for elements retrieved from Onshape REST API responses.
The data models are implemented as Pydantic BaseModel classes, which are used to
1. Parse JSON responses from the API into Python objects.
2. Validate the structure and types of the JSON responses.
3. Provide type hints for better code clarity and autocompletion.
These models ensure that the data received from the API adheres to the expected format and types, facilitating easier and safer manipulation of the data within the application.
Models
- Element: Represents an Onshape element, containing the element ID, name, type, and microversion ID.
Enum
- ElementType: Enumerates the possible element types in Onshape (PARTSTUDIO, ASSEMBLY, DRAWING, etc.).
Element
¶
Bases: BaseModel
Represents an Onshape element, containing the element ID, name, type, and microversion ID.
JSON
{
"name": "wheelAndFork",
"id": "0b0c209535554345432581fe",
"type": "Part Studio",
"elementType": "PARTSTUDIO",
"dataType": "onshape/partstudio",
"microversionId": "9b3be6165c7a2b1f6dd61305",
"lengthUnits": "millimeter",
"angleUnits": "degree",
"massUnits": "kilogram",
"timeUnits": "second",
"forceUnits": "newton",
"pressureUnits": "pascal",
"momentUnits": "newtonMeter",
"accelerationUnits": "meterPerSecondSquared",
"angularVelocityUnits": "degreePerSecond",
"energyUnits": "footPoundForce",
"areaUnits": "squareMillimeter",
"volumeUnits": "cubicMillimeter",
}
Attributes:
Name | Type | Description |
---|---|---|
id |
str
|
The unique identifier of the element. |
name |
str
|
The name of the element. |
elementType |
str
|
The type of the element (e.g., PARTSTUDIO, ASSEMBLY, DRAWING). |
microversionId |
str
|
The unique identifier of the microversion of the element. |
Examples:
>>> element = Element(id="0b0c209535554345432581fe", name="wheelAndFork", elementType="PARTSTUDIO",
... microversionId="9b3be6165c7a2b1f6dd61305")
>>> element
Element(id='0b0c209535554345432581fe', name='wheelAndFork', elementType='PARTSTUDIO',
microversionId='9b3be6165c7a2b1f6dd61305')
Source code in onshape_robotics_toolkit\models\element.py
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 |
|
validate_id(value)
¶
Validate the element ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value
|
str
|
The element ID to validate. |
required |
Returns:
Type | Description |
---|---|
str
|
The validated element ID. |
Raises:
Type | Description |
---|---|
ValueError
|
If the element ID is not 24 characters long. |
Source code in onshape_robotics_toolkit\models\element.py
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
|
validate_mid(value)
¶
Validate the microversion ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value
|
str
|
The microversion ID to validate. |
required |
Returns:
Type | Description |
---|---|
str
|
The validated microversion ID. |
Raises:
Type | Description |
---|---|
ValueError
|
If the microversion ID is not 24 characters long. |
Source code in onshape_robotics_toolkit\models\element.py
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
|
validate_type(value)
¶
Validate the element type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value
|
str
|
The element type to validate. |
required |
Returns:
Type | Description |
---|---|
str
|
The validated element type. |
Raises:
Type | Description |
---|---|
ValueError
|
If the element type is not one of the valid types. |
Source code in onshape_robotics_toolkit\models\element.py
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
|
ElementType
¶
Bases: str
, Enum
Enumerates the possible element types in Onshape
Attributes:
Name | Type | Description |
---|---|---|
PARTSTUDIO |
str
|
Part Studio |
ASSEMBLY |
str
|
Assembly |
VARIABLESTUDIO |
str
|
Variable Studio |
DRAWING |
str
|
Drawing |
BILLOFMATERIALS |
str
|
Bill of Materials |
APPLICATION |
str
|
Application |
BLOB |
str
|
Blob |
FEATURESTUDIO |
str
|
Feature Studio |
Examples:
>>> ElementType.PARTSTUDIO
'PARTSTUDIO'
>>> ElementType.ASSEMBLY
'ASSEMBLY'
Source code in onshape_robotics_toolkit\models\element.py
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 |
|