Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.

First time visiting? Here are some places to start:
  1. Looking for a certain topic? Check out the categories filter or use Search (upper right).
  2. Need support? Ask a question to our Community Support category.
  3. Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
  4. 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.

Options

How to update Feature Studio contents using python client?

oleksandr_slovakoleksandr_slovak Member Posts: 6
edited February 2021 in FeatureScript
Hi!

I can successfully access feature studio content using python client API by:
element = OnshapeElement("https://cad.onshape.com/documents/ca8f441b906a5949eb4e8196/w/3ffa603f8af8def1150f37d7/e/f85267336902055c5cbf495d")

result = osh.client.feature_studios_api.get_feature_studio_contents(
**element._get_DWMVE(),
_preload_content=True
)
This gives me valid result with something like:

{'btType': 'BTFeatureStudioContents-2239', 'contents': 'FeatureScript 1447;\n'             'import(path : "onshape/std/geometry.fs", version : "1447.0");\n'             '\n', 'library_version': 0, 'microversion_skew': False, 'reject_microversion_skew': False, 'serialization_version': '1.1.20', 'source_microversion': '422f02088f68947019b7c291'}

But any tries to call update_feature_studio_contents end up with:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/IPython/core/interactiveshell.py", line 3331, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-46-d4661d04e8f2>", line 1, in <module>
    result = osh.client.feature_studios_api.update_feature_studio_contents(
  File "/home/slovak/.local/lib/python3.8/site-packages/onshape_client/oas/api/feature_studios_api.py", line 613, in __call__
    return self.callable(self, *args, **kwargs)
  File "/home/slovak/.local/lib/python3.8/site-packages/onshape_client/oas/api/feature_studios_api.py", line 410, in __update_feature_studio_contents
    return self.call_with_http_info(**kwargs)
  File "/home/slovak/.local/lib/python3.8/site-packages/onshape_client/oas/api/feature_studios_api.py", line 670, in call_with_http_info
    return self.api_client.call_api(
  File "/home/slovak/.local/lib/python3.8/site-packages/onshape_client/oas/api_client.py", line 367, in call_api
    return self.__call_api(
  File "/home/slovak/.local/lib/python3.8/site-packages/onshape_client/oas/api_client.py", line 184, in __call_api
    response_data = self.request(
  File "/home/slovak/.local/lib/python3.8/site-packages/onshape_client/oas/api_client.py", line 447, in request
    return self.rest_client.POST(
  File "/home/slovak/.local/lib/python3.8/site-packages/onshape_client/oas/rest.py", line 400, in POST
    return self.request(
  File "/home/slovak/.local/lib/python3.8/site-packages/onshape_client/oas/rest.py", line 312, in request
    raise ApiException(http_resp=r)
onshape_client.oas.exceptions.ApiException: (400)
Reason: Bad Request
HTTP response headers: HTTPHeaderDict({'Date': 'Mon, 08 Feb 2021 21:28:36 GMT', 'Content-Type': 'application/json;charset=utf-8', 'Content-Length': '91', 'Connection': 'keep-alive', 'On-Version': '1.125.26734.a33400e3c8f4', 'On-Request-Id': '742b3dce8e437fe70dc6de1c', 'Strict-Transport-Security': 'max-age=31536000; includeSubDomains', 'X-Content-Type-Options': 'nosniff', 'X-XSS-Protection': '1; mode=block'})
HTTP response body: {
  "moreInfoUrl" : "",
  "message" : "Error in input",
  "code" : 9999,
  "status" : 400
}
Is there any working example of how to change the content of the feature studio using API?
So far I've tried:
1. Use API explorer to create working json like: '{"contents": "AAAAAAAAAAAAAAAAA", "serializationVersion": "1.1.20", "sourceMicroversion": "483f72f012aa6e1a6c6853ba", "rejectMicroversionSkew": false}' It works in browser/API explorer.
2. Use it as a body in the call to update_feature_studio_contents -> does not work.

Here is my code:
element = OnshapeElement("https://cad.onshape.com/documents/ca8f441b906a5949eb4e8196/w/3ffa603f8af8def1150f37d7/e/f85267336902055c5cbf495d")

result = osh.client.feature_studios_api.get_feature_studio_contents(
**element._get_DWMVE(),
_preload_content=True
)

resp = json.dumps({
"contents": "AAAAAAAAAAAAAAAAA",
"serializationVersion": "1.1.20",
"sourceMicroversion": result["source_microversion"],
"rejectMicroversionSkew": False
})

result = osh.client.feature_studios_api.update_feature_studio_contents(
**element._get_DWMVE(),
body=resp
)
Many thanks for any suggestion!

Best regards,
Oleksandr

Tagged:

Comments

Sign In or Register to comment.