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.
Can I import .dat files using a feature script?
darren_13
Member, Developers Posts: 119 PRO
so I have finished my NACA 4 digit aerofoil script and I now want to have the ability to use the vast amount of more comely aerofoils available for .dat download. Am I able to read a .dat file and store the co-ords in an array for aerofoil creation?
Kind regards,
Darren Lynch
Kind regards,
Darren Lynch
Tagged:
0
Best Answers
-
ilya_baran Onshape Employees, Developers, HDM Posts: 1,215You cannot do this with a .dat file (not sure what the format is) but if you were to convert it to a csv file, you could upload it and access it from FeatureScript as an array. See: https://cad.onshape.com/FsDoc/imports.html#importing-external-dataIlya Baran \ VP, Architecture and FeatureScript \ Onshape Inc5
-
kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 565FeatureScript doesn't access data directly through file names, but you can upload your profiles to a document (where they'll be saved and version controlled on our servers), and import data from those files into a custom FeatureScript feature within that document.
Here's a quick example of a feature that uses multiple CSV files, and allows the user to select among them:
https://cad.onshape.com/documents/d5df23667e8b892627d4b28d/w/cc3ec5cbfc63fa019e1a0874/e/70af96bc26b9d3730960e10dFeatureScript 422; import(path : "onshape/std/geometry.fs", version : "422.0"); // Imports data as top-level constants, which can be accessed through e.g. PROFILE_1::BLOB_DATA.csvData PROFILE_1::import(path : "d6c489e34a7389ebc8c3364a", version : "d89c86b0c14dfd85bee00095"); PROFILE_2::import(path : "5622f19b69d1c079d95e51a0", version : "040bd0eb4f97a1a4fdca14fe"); export enum ProfileType { annotation { "Name" : "Profile One" } ONE, annotation { "Name" : "Profile Two" } TWO } annotation { "Feature Type Name" : "Profile" } export const profile = defineFeature(function(context is Context, id is Id, definition is map) precondition { annotation { "Name" : "Profile type" } definition.profileType is ProfileType; annotation { "Name" : "Length" } isLength(definition.length, LENGTH_BOUNDS); } { var csv_array; if (definition.profileType == ProfileType.ONE) csv_array = PROFILE_1::BLOB_DATA.csvData; if (definition.profileType == ProfileType.TWO) csv_array = PROFILE_2::BLOB_DATA.csvData; // Convert raw numbers to real lengths var points is array = mapArray(csv_array, function(values) { const point is Vector = vector(values) * definition.length; println(point); return point; }); var sketch1 = newSketch(context, id + "sketch1", { "sketchPlane" : qCreatedBy(makeId("Front"), EntityType.FACE) }); skFitSpline(sketch1, "spline1", { "points" : points }); skSolve(sketch1); });
The imports at the top were selected from the "files" section of the import dialog:
As Ilya mentioned, some more documentation is at https://cad.onshape.com/FsDoc/imports.html#importing-external-data, and the forums are always a good place to ask more questions!
5 -
kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 565Actually, now that I think about it... Seems to me like a better ad hoc solution (which doesn't involve the API at all) is to just put all your data into a single CSV file (with 3 rows dedicated to each profile), and then use FeatureScript select the correct rows and map them into vectors. This means you need to generate the combined CSV file in python and have some logic which maps the selected profile to the correct row indices. However, you won't have to generate all of the import statements, nor will you have to upload 1600 different tabs.
6 -
mbattistello Member, Developers Posts: 51 ✭✭Were you planning to import 1600 individual files to your Onshape doc? Seems like a lot.
You might be able to take the individual files and put them in a single file and append a profileId to each one. Then in the featurescript use that profileid to group the outlines and draw the individual profiles. This makes it so you only have a single import you in featurescript.
If you do this then there is only a single import in your featurescript. On some of the uploads you can do an update, right click on the tab and see if update is available, and if this works then a user could just update that individual file an the import should still work.
I tried this and it seems like there is a bug in the .csv file type update. If I update a csv file and then try to use the update I get the error "Cannot update an element with file type "text/csv" with a different file type "application/vnd.ms-excel"." If the file is a text file it seems to work ok.5
Answers
This script is to be used in a parametric analysis of a wind turbine in SimScale.
Kind regards,
Darren Lynch
Here's a quick example of a feature that uses multiple CSV files, and allows the user to select among them:
https://cad.onshape.com/documents/d5df23667e8b892627d4b28d/w/cc3ec5cbfc63fa019e1a0874/e/70af96bc26b9d3730960e10d
As Ilya mentioned, some more documentation is at https://cad.onshape.com/FsDoc/imports.html#importing-external-data, and the forums are always a good place to ask more questions!
PROFILE_1::import(path : "d6c489e34a7389ebc8c3364a", version : "d89c86b0c14dfd85bee00095");
without manually going through importing all 1600 files? Ideally, I would like to determine the path based upon its location within my document?The reason I want to do this is because I believe people would rather copy the file, add their own profiles without getting me to update the script. This isn't a problem, however, others then don't benefit from the addition of those profiles. I have contemplated linking this to an app created using your API, however, wouldnt know where to start and for now, feature script is comfortable to use, although I feel I'm gonna have to bit the bullet at some point.
Kind regards,
Darren
The version for intraworkspace imports will automatically be updated to the latest version in the workspace of whatever you're pointing to. So, for your purposes, you can leave this blank (i.e.
import(path: "elementid123123123", version: "")
). When you paste the code and commit it, the latest version will automatically be populated as the version string.It likely won't surprise you to hear that we would one day like to have the ability for users to specify an new import right in the feature dialog (similar to what happens in derived part), instead of needing to modify the FeatureScript every time. In the meantime, it sounds like your python script could be a good solution.
You might be able to take the individual files and put them in a single file and append a profileId to each one. Then in the featurescript use that profileid to group the outlines and draw the individual profiles. This makes it so you only have a single import you in featurescript.
If you do this then there is only a single import in your featurescript. On some of the uploads you can do an update, right click on the tab and see if update is available, and if this works then a user could just update that individual file an the import should still work.
I tried this and it seems like there is a bug in the .csv file type update. If I update a csv file and then try to use the update I get the error "Cannot update an element with file type "text/csv" with a different file type "application/vnd.ms-excel"." If the file is a text file it seems to work ok.
Kind regards,
Darren
Thanks in advance,
Darren
Once again many thanks,
Darren