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.
Select assembly configuration in API?
eric_pesty
Member Posts: 1,947 PRO
Started playing around a bit with the API.
I'm looking at what it would take to generate some images of different configurations of an assembly to use on our website.
Looking through the "Gif generator" example, I'm seeing a lot of the pieces I would need to make that happen, but one thing I'm not clear on is how to switch configurations. I tried pasting a link that includes a specific configuration but I couldn't seem to get it to propagate through...
Ideally I'd be able to retrieve the lists of configuration and iterate through them with a for loop to generate a bunch of pictures automatically...
Is there an example on how to do this somewhere?
I'm looking at what it would take to generate some images of different configurations of an assembly to use on our website.
Looking through the "Gif generator" example, I'm seeing a lot of the pieces I would need to make that happen, but one thing I'm not clear on is how to switch configurations. I tried pasting a link that includes a specific configuration but I couldn't seem to get it to propagate through...
Ideally I'd be able to retrieve the lists of configuration and iterate through them with a for loop to generate a bunch of pictures automatically...
Is there an example on how to do this somewhere?
Tagged:
0
Answers
https://cad.onshape.com/glassworks/explorer/#/Element/getConfiguration
This endpoint will give you the list of all configuration parameters and possible values.
The configuration is generally an encoded string of key value pairs, and most endpoints will take in a configuration as either a body parameter or a URL parameter.
If you want an example of how the configuration looks, you can create an extension with the configuration included in the action URL, or another easy way is to just add a bunch of different instances to a test assembly in different configurations, use an endpoint like /assemblies/.../bom, and check the configuration parameter for each instance. You'll get a value like:
"Width=Long;Height=Tall" etc, (or less human readable names likely)
That looks promising!
I understand the document/workspace/element parts of the URL but is the wvmid only applicable to microversions (and in which case does it imply the API explorer requires a microversion to be used rather than a workspace?
There are only 3 parts to the URL in the example colab notebook so that threw me off a bit!
Also, when I put in the 4 parts of a microversion of my document in the explorer I get a 404... There's probably something obvious I'm missing (and that might where my problem is coming from...)!
Sounds like a need to do some more background reading!
For anyone reading this... the 4th part I was confused by is just asking for either "w", "v" or "m", to indicate a workspace version or microversion. Some sections in the API explorer offer a dropdown instead which makes things a lot clearer...
I did get something working to iterate through every combination of configuration with up to two "lists" configuration inputs but the way I "solved" this is really not scalable to more inputs so I'm thinking there's got to be a fundamentally better way...
For context here is what I came up with:
As a first step I build a table based on the "/configuration" response using the following code:
I then go through my "configstrs" array to generate every possible permutation like this:
At first I had it working with exactly two input lists but then I went back and added some "if" so make it work with just one as well... The "assembliesShadedView" function also saves the image to my google drive in the process and that's working fine.
This covers my basic needs at this point but it might come in handy down the road to make it a bit more "flexible" by allowing more inputs. I might also need to collect some more info to generate some mor useful filenames down the road (right now I include the actual "config" string in the filename and put in a folder named after the assembly description)...
I'm guessing there's an opportunity to use recursion somewhere in there but in case you were wondering how far above my head most of this is, my current level requires googling "for loop in Python"...
Thanks for reading this far!
EDIT: what the heck is wrong with the "code" blocks now? I created the blocks before pasting and they look fine in the preview but are displaying in one line when posting!