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.
python api + parametric study
joel_guerrero
Member, Developers Posts: 14 EDU
Hi,
So far the python api works fine for me. I managed to modify the geometry, evaluate featureScripts, and export the geometry in STL format. I also ran a small parametric study with no problems.
At this point, I want to run the same parametric study but concurrently, that is, I want to launch many python scripts at the same time. So far I am launching 4 scripts at the same time and it works (eventually I would like to scale to more than 100 processes), but the problem I am facing is that the exported STL is the same for the 4 scripts. Checking the scripts I can see that the parametrization is done right (all the scripts have different values), but it seems that when deploying the 4 scripts at the same time, onshape will only evaluate one script (which maybe is the first one in or the last one out). Is there any way to overcome this issue?
By the way, I am working in the same document and I don't want to create duplicates documents.
Any suggestion is appreciated,
Joel
So far the python api works fine for me. I managed to modify the geometry, evaluate featureScripts, and export the geometry in STL format. I also ran a small parametric study with no problems.
At this point, I want to run the same parametric study but concurrently, that is, I want to launch many python scripts at the same time. So far I am launching 4 scripts at the same time and it works (eventually I would like to scale to more than 100 processes), but the problem I am facing is that the exported STL is the same for the 4 scripts. Checking the scripts I can see that the parametrization is done right (all the scripts have different values), but it seems that when deploying the 4 scripts at the same time, onshape will only evaluate one script (which maybe is the first one in or the last one out). Is there any way to overcome this issue?
By the way, I am working in the same document and I don't want to create duplicates documents.
Any suggestion is appreciated,
Joel
Tagged:
0
Best Answer
-
Ethan_K Member, Onshape Employees Posts: 57If changing variables is your use case, then definitely use configurations. Configurations are built with this workflow in mind. To give you an example of REST calls that show two different configs, compare these two calls:
configurable cube stl download - specifying a size configuration parameter to be set as "0.0762 meter"
https://cad.onshape.com/api/partstudios/d/f97b224eed8484e4e4df703d/v/12fc10a0056fe9c25fe0d372/e/f8ea33aea606bb46c0db5862/stl?configuration=size=0.0762+meter
Now specifying a size of "2 meter"
https://cad.onshape.com/api/partstudios/d/f97b224eed8484e4e4df703d/v/12fc10a0056fe9c25fe0d372/e/f8ea33aea606bb46c0db5862/stl?configuration=size=2+meter
Feel free to click on them, and download the resulting model using your browser and compare the size of the two models. The right way to get that configuration string is to encode the params you want to use using the elements->getConfigurationEncoding endpoint.
Does that help?5
Answers
What sort of changes are you making? If the changes are anything but specifying different configurations, then the returned output will always be dependent on the state of the document - and other operations may be done in between making different requests. Configuration changes are exempt because they are applied to a microversion, and as such, need to be specified for every resource request that they are expected to affect.
For a REST API, there are no sessions that persist across multiple requests - it is "stateless". So if you are running multiple python processes, the "change feature list" code of process 1 may run just before the "get stl" code of process 5, making your script think that the stl is a result of process 5, when that indeed is not true.
To get around this, you have to create a 'session' (in a sense) by either copying the document for each running process (not recommended) OR creating a new branch for each process (recommended). The branching method is much less "weight" than the full document copy method. Some pseudo-code would look like:
Through branching, you are effectively isolating the actions of each python client process so that they don't confuse one another.
Alternatively, for parametric work, you could probably just use configurations to do the actual parametrizations. If you do that, then you'd be able to easily just specify the configuration within the download stl call against the document without branching/copying. That is because all of the actions to generate the resulting stl happen in a single request and therefore cannot interfere with one another.
Does that help?
Cheers,
-Ethan
configurable cube stl download - specifying a size configuration parameter to be set as "0.0762 meter"
https://cad.onshape.com/api/partstudios/d/f97b224eed8484e4e4df703d/v/12fc10a0056fe9c25fe0d372/e/f8ea33aea606bb46c0db5862/stl?configuration=size=0.0762+meter
Now specifying a size of "2 meter"
https://cad.onshape.com/api/partstudios/d/f97b224eed8484e4e4df703d/v/12fc10a0056fe9c25fe0d372/e/f8ea33aea606bb46c0db5862/stl?configuration=size=2+meter
Feel free to click on them, and download the resulting model using your browser and compare the size of the two models. The right way to get that configuration string is to encode the params you want to use using the elements->getConfigurationEncoding endpoint.
Does that help?
encodedId