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.
How to hardcode files for opImportForeign?
joshtargo
Member Posts: 551 EDU
How can I hardcode the blob data so a user can select from a list of STEP files from a dropdown list?
I've tried many different things but nothing works. this is the starting point with a single imported file for a test.FeatureScript 2960;
import(path : "onshape/std/importForeign.fs", version : "2960.0");
import(path : "onshape/std/feature.fs", version : "2960.0");
import(path : "onshape/std/common.fs", version : "2960.0");
Part1::import(path : "4e82d1e61d46ecc058c3ab67", version : "797f1d3b6c8dd334df5c46ba");
annotation { "Feature Type Name" : "Import", "Feature Type Description" : "" }
export const myFeature = defineFeature(function(context is Context, id is Id, definition is map)
precondition
{
}
{
opImportForeign(context, id + "importForeign1",
{
"blobData" : Part1::BLOB_DATA as CADImportData});
});
Answers
Could you use a derive of the imported model?
Experts in Onshape Automation - Custom Features and Integrated Applications
It becomes significantly slower to use derive. But would the same syntax work for either? I just can't make it work.
Bump
I had a quick poke around out of curiosity, here.
In short, I can't get it to work either, only via the predicate import:
annotation { "Name" : "CAD model" } definition.cadModel is CADImportData;This seems to do some additional processing of the blob that also write
processedForeingDataInfoto the blob data. See the different debug printouts. I can't find a way to process this at the FeatureScript level, so my best guess it's some processing happening behind the scenes in the C-level at feature computation.I have a feeling this is the best one can do to select blob 3D geometry in FeatureScript as it stands. But you're definitely onto something, there is a significant difference in regen time between native derive and the CAD blob import.
But, the native derive do a lot extra processing, using the more plain
opMergeContextsdoes show some nice improvements. All variants are in the same document to have a look at.Hope any of this helps 😃
@wille_j I played with it too and ran into the same exact thing and same conclusion. I sort of thought it might be simple since the code for an import feature is so dang simple.
FeatureScript 1746;import(path : "onshape/std/geometry.fs", version : "1746.0");
icon::import(path : "dbbb95dc4b30445fafe0ff6d", version : "17a1cb30b1bd13b6dd31b29b");annotation { "Feature Type Name" : "Import 3D File","Icon" : icon::BLOB_DATA}
export const importFeature = defineFeature(function(context is Context, id is Id, definition is map)
precondition
{
annotation { "Name" : "3D File" }
definition.file is CADImportData;
}
{
opImportForeign(context, id + "importForeign1", {
"blobData" : definition.file
});
});
The Onsherpa | Reach peak Onshape productivity
www.theonsherpa.com
Thank you both. It's a bummer because I could have a huge prepoulated organized list of items to import, basically a mini app. But I can build it all into a single parts doc of STEP files and select via doc browsing.
@wille_j the other main difference is that derive can bring in native Onshape parts, and import can only do downloadable cad files. Can any of the other methods bring in Onshape parts from studios?
Not sure I follow your question, and maybe you're already familiar with the instantiator stuff, but on certain features I've set them up to access pretty complicated parts libraries via a lookup table path to dig into it. The terminal node of each path ends in the build function instantiator needs. That way you can set it up to narrow down to the final selection like Metric → Inserts → Heat Set → M5, and get back the model you want. Here's a 1-layer example, but your table can go deeep. Might not be quite as zippy as a straight import, but for many things is plenty good. This does, of course, bring us back to the other thread about how in many cases bringing the hardware directly into the Part Studio isn't a recommended general practice though for a number of reasons:
Performance issues - merging contexts (aka Derive) can bog it down.
Part search can become a nightmare - if you search a part from the document dashboard everywhere it's derived will come up because Onshape sees them as unique parts now. How do you know which one is "the real one"?
BoM issues - You want it to show 1 screw 10x not 10 screws 1x.
https://cad.onshape.com/documents/9840ec2b6d75757f8b4ad7c7/w/6da09b0068c9fad6999e2811/e/9417ae113a3138e3d30bfe5e
The Onsherpa | Reach peak Onshape productivity
www.theonsherpa.com