import command improvement

traveler_hauptman
traveler_hauptman Member, OS Professional, Mentor, Developers Posts: 423 PRO
Imports are a bit inscrutable at the moment. It would be nice if the 'import' button commented the lines it inserts with descriptive info
import(
path : "3bf95367da7496dc5f19bf6c/d1068c2a6e0fdf68c9cba6a6/aa51840ef58770354c6dd517",
 version : "6cdb68bb3b66a2d24bc61ff9"); // User/Team: Bubba DocName: Super Features



Comments

  • kevin_o_toole_1
    kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 565 image
    Totally agree. We also want to make sure the actual import and the human-readable text don't go out of sync, so we have something a little fancier planned for this. Thanks for the feedback, and sit tight for the fix!

  • billy2
    billy2 Member, OS Professional, Mentor, Developers, User Group Leader Posts: 2,206 PRO
    edited May 2016
    Here's a csv parser Iyla wrote:

    function parseVertex(s is string) // Returns a unitless 3D Vector or undefined
    {
        const regexp = "v\\s+" ~ REGEX_NUMBER_CAPTURE ~
            "\\s+" ~ REGEX_NUMBER_CAPTURE ~
            "\\s+" ~ REGEX_NUMBER_CAPTURE ~ "\\s*";
        const matches = match(s, regexp);
        if (!matches.hasMatch)
            return undefined;
        var result = makeArray(3);
        for (var i in [0, 1, 2])
            result[i] = stringToNumber(matches.captures[i + 1]);
        return vector(result);
    }
    The input file looks like this:
    # Generated.
    v 0.0060 0.4554 0.0050
    vn 0.41 -0.49 -0.77
    v 0.0060 0.4535 0.0060
    vn 0.40 -0.51 -0.76
    v 0.0020 0.4554 0.0033

    and returns x,y,z; I guard this function and only pass in strings beginning with "v ".

    You can re-purpose it to parse your file.

    -Remember to add "csv" to the end of your uploaded file name.
    -Don't try and rename file in OS, that stopped working a couple of weeks ago (I think it's still broken).
    -watch for carriage returns at the end of file, that broke my parsing routine.