Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.
First time visiting? Here are some places to start:- Looking for a certain topic? Check out the categories filter or use Search (upper right).
- Need support? Ask a question to our Community Support category.
- Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
- Be respectful, on topic and if you see a problem, Flag it.
If you would like to contact our Community Manager personally, feel free to send a private message or an email.
Configuration is ignored when trying to export drawing via API?
I have this very simple example:
It is a cube
with three configuration variables that control its size. The link points to a
simple drawing from one of the sides. I want to export this drawing to DXG (via
the API) using the “configuration” option to modify the cube at the same time. See
the code below that reproduces the problem (replace acces_key and secret_key).
What I expect:
that the “configuration” parameter in get_drawing() is used when exporting the
drawing. This way the exported DXF has the dimensions of the configuration.
What actually happens: the result of get_drawing() (and then retrieving the dxf via the response > href > resultExternalDataIds) is a dxf with the drawing in whatever the dimensions are present at that time in the onshape drawing, ignoring the configuration parameter.
As an example I added a second request, massproperties().The configuration parameter in this request actually does take effect (volume in response is bigger if I input a bigger width in the configuration).
I’m wondering what i’m overlooking and what is needed to make this work.
Thanks in advance!
import base64
import requests
access_key = 'access_key'
secret_key = 'secret_key'
credentials = "{}:{}".format(access_key, secret_key)
encoded_credentials = base64.b64encode(credentials.encode()).decode()
headers = {
'Authorization': "Basic {}".format(encoded_credentials),
"Content-Type": "application/json;charset=UTF-8; qs=0.09"
}
def get_drawing(headers):
url = "https://cad.onshape.com/api/v6/drawings/d/1924bf2dae91de85359f60db/w/122fe50cf8f782da3f636032/e/9af2fef32d1f0656726a35bf/translations"
payload = {
'storeInDocument': False,
'formatName': 'DXF',
"configuration": "width=900"
}
response = requests.post(url, headers=headers, json=payload)
print(response.text)
def massproperties(headers):
url = "https://cad.onshape.com/api/v6/partstudios/d/1924bf2dae91de85359f60db/w/122fe50cf8f782da3f636032/e/5a1abb051284203d02770879/massproperties"
params = {
"configuration": "width=600mm",
"rollbackBarIndex": "-1",
"massAsGroup": "true",
"useMassPropertyOverrides": "false"
}
response = requests.get(url, headers=headers, params=params)
print(response.text)
get_drawing(headers=headers)
# massproperties(headers=headers)
Answers
Instead of configuration being set at the drawing level, its set per view, and it directly edits the drawing.
In order to export a configured drawing, you need to update each view in the drawing, and then export the result drawing.
You need to use the end point:
/api/appelements/d/../w/.../e/../references
And update the configuration of each reference.