Skip to content

Instantly share code, notes, and snippets.

@connorworley
Created April 11, 2020 01:21
Show Gist options
  • Save connorworley/1028cb2dd9c2d64506e75e0b4d26ea6c to your computer and use it in GitHub Desktop.
Save connorworley/1028cb2dd9c2d64506e75e0b4d26ea6c to your computer and use it in GitHub Desktop.
from pathlib import Path
import onshape_client
from onshape_client.oas.models.bt_translate_format_params import BTTranslateFormatParams
from onshape_client.onshape_url import OnshapeElement
def main():
def open_authorize_grant_callback(authorization_url, fetch_token):
print(f"Open the following URL in your browser: {authorization_url}")
authorization_code = input("Enter the token you received: ")
fetch_token(code=authorization_code)
drawing = OnshapeElement.create_from_ids(
did="c7d69482982a4c651d6d46f9",
wvm="w", wvmid="5ffe3a8df402271b05556d03",
eid="5ab568ba4a2cc4a3d8171f1a",
)
onshape_client.client.Client.get_client().configuration.debug = True
drawing.export_file(
Path("api.pdf"),
BTTranslateFormatParams(
cloud_object_id="",
cloud_storage_account_id="",
color_method="color",
current_sheet_only=False,
destination_name="Drawing 1",
element_id="5ab568ba4a2cc4a3d8171f1a",
email_link=False,
flatten=True,
format_name="PDF",
selectable_pdf_text=False,
show_overridden_dimensions=True,
splines_as_polylines=False,
store_in_document=False,
text_as_geometry=False,
trigger_auto_download=False,
version_string="",
),
)
client = onshape_client.client.Client(
keys_file="onshape_client_config.yaml",
open_authorize_grant_callback=open_authorize_grant_callback,
)
client.open_authorize_grant()
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment