Variable
This module defines data models for variables used in Onshape documents 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
- Variable: Represents a variable used in Onshape's Variable Studio.
Enum
- VARIABLE_TYPE: Enumerates the possible variable types in Onshape (LENGTH, ANGLE, NUMBER, ANY).
VARIABLE_TYPE
¶
Bases: str
, Enum
Enumerates the possible variable types in Onshape
Attributes:
Name | Type | Description |
---|---|---|
LENGTH |
str
|
Length variable type |
ANGLE |
str
|
Angle variable type |
NUMBER |
str
|
Number variable type |
ANY |
str
|
Any variable type |
Examples:
>>> VARIABLE_TYPE.LENGTH
'LENGTH'
>>> VARIABLE_TYPE.ANGLE
'ANGLE'
Source code in onshape_robotics_toolkit\models\variable.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
|
Variable
¶
Bases: BaseModel
Represents a variable used in Onshape's Variable Studio.
JSON
{
"type": "ANGLE",
"name": "forkAngle",
"value": null,
"description": "Fork angle for front wheel assembly in deg",
"expression": "15 deg"
}
Attributes:
Name | Type | Description |
---|---|---|
type |
str
|
The type of the variable (LENGTH, ANGLE, NUMBER, ANY). |
name |
str
|
The name of the variable. |
value |
str
|
The value of the variable. |
description |
str
|
The description of the variable. |
expression |
str
|
The expression of the variable. |
Examples:
>>> variable = Variable(
... type="ANGLE",
... name="forkAngle",
... value=None,
... description="Fork angle for front wheel assembly in deg",
... expression="15 deg"
... )
>>> variable
Variable(
type='ANGLE',
name='forkAngle',
value=None,
description='Fork angle for front wheel assembly in deg',
expression='15 deg'
)
Source code in onshape_robotics_toolkit\models\variable.py
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 |
|
validate_expression(value)
¶
Validate the variable expression to ensure it is not empty and in the correct format.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value
|
str
|
The variable expression to validate. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The validated variable expression. |
Raises:
Type | Description |
---|---|
ValueError
|
If the variable expression is empty or not in the correct format. |
Source code in onshape_robotics_toolkit\models\variable.py
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
|
validate_name(value)
¶
Validate the variable name to ensure it is not empty.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value
|
str
|
The variable name to validate. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The validated variable name. |
Raises:
Type | Description |
---|---|
ValueError
|
If the variable name is empty. |
Source code in onshape_robotics_toolkit\models\variable.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
|
validate_type(value)
¶
Validate the variable type to ensure it is one of the valid types.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value
|
str
|
The variable type to validate. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The validated variable type. |
Raises:
Type | Description |
---|---|
ValueError
|
If the variable type is not one of the valid types. |
Source code in onshape_robotics_toolkit\models\variable.py
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
|