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.

python api + parametric study

joel_guerrerojoel_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
Tagged:

Best Answer

Answers

  • Ethan_KEthan_K Member, Onshape Employees Posts: 57
    Hi Joel,

    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:

    function parametrizeAndDownloadStl():
        branch = createBranch()
        makeFeatureListChanges(branch)
        return downloadStl(branch)

    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
  • joel_guerrerojoel_guerrero Member, Developers Posts: 14 EDU
    Hi Ethan,

    Thanks for your reply.

    Well, I am updating features in the document using variables, and then exporting the STL.

    So far I have it working by duplicating the document, then updating the features in the duplicated document, exporting the STL and then erasing the duplicated document, but I am sure that there should be a better way. Also, I am not sure if there is a limit in the number of simultaneous restful calls (and duplicated cases) I am allow to do. Eventually I am planning in deploying about 100 configurations at the same time, so I don't know if this will give me problems.

    Definitely I will explore the branching option.  However, checking the API explorer I don't see any function for branching, is it implemented in the API explorer or somewhere else?

    I am also exploring the update configurations option, but I still don't understand how it works neither understand the header.  So far I haven't been able to update the configurations, I think the request body is fine (I am getting the 200 status code) but I don't see the geometry being updated.


    Thanks for your help,

    joel

  • joel_guerrerojoel_guerrero Member, Developers Posts: 14 EDU
    Hi,

    Thanks for the tip.  How would you do it if you have let's say 3 configurations?
  • joel_guerrerojoel_guerrero Member, Developers Posts: 14 EDU
    Hi,

    Ok, I figured out how to use configurationencodings. I wish the API was documented a little bit better, but you can get your way around using the web developer tools.

    In any case, I wonder what is the difference between "encodedId" and "queryParam", both of them work fine with the url. For example

    encodedId

    queryParam

    Is there a preference between encodedId and queryParam?


  • Ethan_KEthan_K Member, Onshape Employees Posts: 57
    The only difference is that the queryParam packages the url up in a way that is ready to use as a qp in the url - use that. For many cases, it is identical to the encodedId.
Sign In or Register to comment.