File size: 1,282 Bytes
49c8e40
385569a
7d6d9db
385569a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import requests
from loguru import logger
from onshape.onshape_base import OnshapeBase


class OnshapeDownload(OnshapeBase):
    def __init__(self, did, wid, eid, output_file):
        super().__init__()
        self.did = did
        self.wid = wid
        self.eid = eid
        self.output_file = output_file

    def download(self):
        url = f"{self.base_url}/blobelements/d/{self.did}/w/{self.wid}/e/{self.eid}"
        headers = {
            "Accept": "application/json;charset=UTF-8; qs=0.09",
            **self.get_auth_header(),
        }

        logger.info(
            f"Downloading file with element ID '{self.eid}' to '{self.output_file}'."
        )
        response = requests.get(url, headers=headers)

        with open(self.output_file, "wb") as f:
            f.write(response.content)
            logger.success(f"File downloaded successfully as '{self.output_file}'.")


# Example usage
if __name__ == "__main__":
    did = "ef42d7639096f3e61a4d4f07"
    wid = "5fcd0f25ce3dee08bbb823bf"
    eid = "fd0dbebc1ac05de1f1d1ed07"  # you can find it in `resultElementIds` when `requestState` of `TranslationStatusResponse` is `DONE`
    output_file = "output_file.step"

    downloader = OnshapeDownload(did, wid, eid, output_file)
    downloader.download()