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.

FS to import Excel list of XY data points

john_allen289john_allen289 Member Posts: 38 PRO
Hi,
I am very new working with FeatureScript.
I have a long list of X & Y points in an excel worksheet. I want to build an FS custom feature that will read this excel worksheet and put a point in a sketch on the XY plane for each row pair of X & Y co-ordinates in the excel sheet.
Before I start is this possible with FS?
Any existing examples of any similar FS custom features anyone can share that do anything similar?
Any pointers or obstacles to look out for?
Thanks in advance.
John

Comments

  • _anton_anton Member, Onshape Employees Posts: 410
    Sounds like you could export as CSV, upload that into your document, import into your Feature Studio, and then read it into a custom feature.

    We have a tutorial on how to make sketches: https://cad.onshape.com/FsDoc/tutorials/add-sketch-geometry.html
  • chadstoltzfuschadstoltzfus Member, Developers, csevp Posts: 142 PRO
    It is definitely possible to use the data from an Excel file in FeatureScript. The way I've done it before is to export the Excel file as a CSV, import that file into an Onshape document, and parse that CSV using FeatureScript. I whipped up a very basic example here. You might have to do some stuff with coordinate systems to get it aligned the way you'd like, but this should be a good start.

    See the "Importing external data" at https://cad.onshape.com/FsDoc/imports.html for more information.

    For plotting on a plane it should be relatively straightforward, just depends on if you want to add the points as floating points in a Part Studio or if you want them to be sketch points. I find working with opPoint() to be easier, you just plug in the vectors you parse from the CSV  file. 
    Applications Developer at Premier Custom Built
    chadstoltzfus@premiercb.com
  • chadstoltzfuschadstoltzfus Member, Developers, csevp Posts: 142 PRO
    Looks like @_anton beat me to it! If the sketch option is preferred definitely go with the documentation they provided in the sketch tutorials. 
    Applications Developer at Premier Custom Built
    chadstoltzfus@premiercb.com
  • john_allen289john_allen289 Member Posts: 38 PRO
    Great, thanks guys, I'll check these methods out and let you know how I get on....
  • EvanReeseEvanReese Member, Mentor Posts: 2,135 ✭✭✭✭✭
    @john_allen289
    here's an example of using a csv to drive variables (by @john_mcclary), but it should be a good reference for how to get the data from the csv. https://cad.onshape.com/documents/75dfbb9091b5bea038398789/v/2d6edbf047281ce828b3923f/e/97a921379d1437bdaef7fcdf?jumpToIndex=1095&showReturnToWorkspaceLink=true
    Evan Reese
  • john_allen289john_allen289 Member Posts: 38 PRO
    Ok, taking baby steps here.

    Set up a Document.

    Created Excel list, two columns with 10 rows of X & Y data, exported to .csv, imported to the Document.

    @chadstoltzfus I cut&paste your FS example, but I'm stuck on the CSV import line.

    How do I get the Version for the imported .csv? I've versioned the document, viewed the version then copy for the URL, back to Main, paste the version id into the FS line but it's not working? Any thoughts? I;ve got the path to look at my .csv import 'XY Values.csv' but error is saying can't find module?

    @chadstoltzfus FS


    My FS



    My URL in Main for the FS



    Help please, thank you!



  • chadstoltzfuschadstoltzfus Member, Developers, csevp Posts: 142 PRO
    edited September 2021
    @john_allen289 Instead of copying the import statement, it should be easier to use the import button at the top of the Feature Studio and reference the CSV you imported. 

    From there you should see an import statement appear in your code, and then place the "CSV::" chunk in front of you import statement. This will not only bring in the correct import statement but also reference the main of the document, so that way you will not have to create a version of the document every time you update the CSV.

    To actually answer your question the version you could copy would be the sequence between /v/ and /e/ in the URL, it's much easier to just redo the import statement using the button up top. 
    Applications Developer at Premier Custom Built
    chadstoltzfus@premiercb.com
Sign In or Register to comment.