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.

Having issue when using onshape api for download stl file

jihwan_lee888jihwan_lee888 Member Posts: 2

Hi i am very first time to use onshape tools and api. i am currently studying this for my project.

This is my .py file for loading stl file.



from onshape_client.client import Client

with open("config.txt") as cfg:
theta = float(cfg.readline().split("=")[1])

config = {
"base_url": "https://cad.onshape.com",
"access_key": "——",
"secret_key": "——"
}
client = Client(configuration=config)

document_id = "8439fb43c437263e5ddf1d36"
workspace_id = "35d8bc1ad49b2648a97c9da9"
element_id = "9aa403259ef60bf62302022b"
full_url = (
f"{config['base_url']}"
f"/api/partstudios/d/{document_id}"
f"/w/{workspace_id}"
f"/e/{element_id}/stl"
)

config_str = f"theta={theta}degree"

response = client.api_client.request("GET", full_url, query_params={"configuration": config_str})
if response.status == 200:
with open("output.stl", "wb") as f:
f.write(response.data.encode("utf-8"))
print(f"STL for θ={theta} written to output.stl")
else:
print("Error:", response.status, response.data)

This code works very well but it cannot change the parameter. i set my modeling's parameter as 'theta' and the .py file cannot change it.
I tried browser version of stl file, https://cad.onshape.com/api/partstudios/d/8439fb43c437263e5ddf1d36/w/35d8bc1ad49b2648a97c9da9/e/9aa403259ef60bf62302022b/stl?configuration=theta=2+degree ,

but it also make same result. please feel free to give some tips for me. thank you for reading.

Comments

Sign In or Register to comment.